1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package user
import (
"net/http"
"soko/pkg/app/layout"
"soko/pkg/app/utils"
"soko/pkg/config"
"soko/pkg/models"
"time"
)
var viewTabs = []layout.SubTab{
{
Name: "Maintainers",
Link: "/user/preferences/maintainers",
Icon: "fa fa-users mr-1",
},
}
templ show(currentSubTab string, preferences models.UserPreferences) {
<div class="container mb-5">
switch currentSubTab {
case "Maintainers":
@maintainers(preferences.Maintainers)
}
</div>
<script src="/assets/userpref.js"></script>
}
func Preferences(currentSubTab string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
layout.TabbedLayout("User", layout.About, "Preferences", "fa fa-fw fa-cog", "You can customize the page contents to your needs here", viewTabs,
currentSubTab, show(currentSubTab, utils.GetUserPreferences(r))).Render(r.Context(), w)
}
}
// addCookie will apply a new cookie to the response of a http request
// with the key/value specified.
func addCookie(w http.ResponseWriter, name, path, value string, ttl time.Duration) {
expire := time.Now().Add(ttl)
cookie := http.Cookie{
Name: name,
Path: path,
Value: value,
Expires: expire,
HttpOnly: true,
Secure: config.DevMode() == "false",
}
http.SetCookie(w, &cookie)
}
|