| @@ -31,6 +31,16 @@ type accountPGP struct { |
| 31 | Confirm string // the fingerprint's first 8 characters |
31 | Confirm string // the fingerprint's first 8 characters |
| 32 | } |
32 | } |
| 33 | |
33 | |
| |
34 | // accountDevice is one registered APNs device as the settings page shows |
| |
35 | // it. Token is truncated to its first 8 characters: the full token is |
| |
36 | // device-identifying and never reaches the page. |
| |
37 | type accountDevice struct { |
| |
38 | ID int64 |
| |
39 | Label string |
| |
40 | Token string |
| |
41 | LastSeenAt string |
| |
42 | } |
| |
43 | |
| 34 | // accountForm renders the account's own settings: keys, addresses, and the |
44 | // accountForm renders the account's own settings: keys, addresses, and the |
| 35 | // commands for everything that stays on SSH. |
45 | // commands for everything that stays on SSH. |
| 36 | func (s *Server) accountForm(w http.ResponseWriter, r *http.Request, u store.User) { |
46 | func (s *Server) accountForm(w http.ResponseWriter, r *http.Request, u store.User) { |
| @@ -64,8 +74,16 @@ func (s *Server) accountPage(w http.ResponseWriter, r *http.Request, u store.Use |
| 64 | s.runControlInto(u, []string{"profile", "show"}, &profile) |
74 | s.runControlInto(u, []string{"profile", "show"}, &profile) |
| 65 | mailOn, _ := s.st.MailEnabled(u.ID) |
75 | mailOn, _ := s.st.MailEnabled(u.ID) |
| 66 | watchOn, _ := s.st.WatchEnabled(u.ID) |
76 | watchOn, _ := s.st.WatchEnabled(u.ID) |
| |
77 | pushOn, _ := s.st.PushEnabled(u.ID) |
| 67 | theme, _ := s.st.Theme(u.ID) |
78 | theme, _ := s.st.Theme(u.ID) |
| 68 | |
79 | |
| |
80 | var devices []accountDevice |
| |
81 | if list, err := s.st.PushDevices(u.ID); err == nil { |
| |
82 | for _, d := range list { |
| |
83 | devices = append(devices, accountDevice{ID: d.ID, Label: d.Label, Token: prefix8(d.Token), LastSeenAt: d.LastSeenAt}) |
| |
84 | } |
| |
85 | } |
| |
86 | |
| 69 | // The about text is a file. The page points at it rather than editing |
87 | // The about text is a file. The page points at it rather than editing |
| 70 | // it: the repository's own editor already does that job. |
88 | // it: the repository's own editor already does that job. |
| 71 | aboutRepo := u.Username + "/" + control.ProfileRepoName |
89 | aboutRepo := u.Username + "/" + control.ProfileRepoName |
| @@ -89,10 +107,12 @@ func (s *Server) accountPage(w http.ResponseWriter, r *http.Request, u store.Use |
| 89 | Message string |
107 | Message string |
| 90 | MailOn bool |
108 | MailOn bool |
| 91 | WatchOn bool |
109 | WatchOn bool |
| |
110 | PushOn bool |
| |
111 | Devices []accountDevice |
| 92 | ThemeSetting string // system, light or dark: the form's selected option |
112 | ThemeSetting string // system, light or dark: the form's selected option |
| 93 | }{s.baseFor(u), "account", keys, pgp, emails, profile, profileLinksText(profile.Links), |
113 | }{s.baseFor(u), "account", keys, pgp, emails, profile, profileLinksText(profile.Links), |
| 94 | aboutRepo, aboutEdit, s.cfg.SiteHost(), |
114 | aboutRepo, aboutEdit, s.cfg.SiteHost(), |
| 95 | s.takeFlash(w, r), r.URL.Query().Get("m"), mailOn, watchOn, theme}) |
115 | s.takeFlash(w, r), r.URL.Query().Get("m"), mailOn, watchOn, pushOn, devices, theme}) |
| 96 | } |
116 | } |
| 97 | |
117 | |
| 98 | // accountExport hands the browser the same bundle `account export` |
118 | // accountExport hands the browser the same bundle `account export` |
| @@ -243,7 +263,7 @@ func (s *Server) accountSubmit(w http.ResponseWriter, r *http.Request, u store.U |
| 243 | return |
263 | return |
| 244 | } |
264 | } |
| 245 | back("", "colour scheme saved") |
265 | back("", "colour scheme saved") |
| 246 | case "notify-mail", "notify-watch": |
266 | case "notify-mail", "notify-watch", "notify-push": |
| 247 | pref := strings.TrimPrefix(r.FormValue("field"), "notify-") |
267 | pref := strings.TrimPrefix(r.FormValue("field"), "notify-") |
| 248 | state := "off" |
268 | state := "off" |
| 249 | if r.FormValue(pref) == "on" { |
269 | if r.FormValue(pref) == "on" { |
| @@ -254,6 +274,12 @@ func (s *Server) accountSubmit(w http.ResponseWriter, r *http.Request, u store.U |
| 254 | return |
274 | return |
| 255 | } |
275 | } |
| 256 | back("", "notification preferences saved") |
276 | back("", "notification preferences saved") |
| |
277 | case "device-remove": |
| |
278 | if _, msg, ok := s.runControl(u, []string{"notifications", "device", "remove", r.FormValue("id")}); !ok { |
| |
279 | back(msg, "") |
| |
280 | return |
| |
281 | } |
| |
282 | back("", "device removed") |
| 257 | case "profile": |
283 | case "profile": |
| 258 | argv := []string{"profile", "set", |
284 | argv := []string{"profile", "set", |
| 259 | "--description", r.FormValue("description"), |
285 | "--description", r.FormValue("description"), |