diff options
author | r <r@freesoftwareextremist.com> | 2019-12-27 08:06:43 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2019-12-27 08:09:40 +0000 |
commit | b9d7eb05beb57926181f91685a75b3069d1f8cf8 (patch) | |
tree | 1aa0b5a28fd8cc0c3fc425c227eb747d8528c910 /service/transport.go | |
parent | 14bb18fbc7e6cdea57f27a44093d645d97bacb64 (diff) | |
download | bloat-b9d7eb05beb57926181f91685a75b3069d1f8cf8.tar.gz bloat-b9d7eb05beb57926181f91685a75b3069d1f8cf8.zip |
Add settings page
Diffstat (limited to 'service/transport.go')
-rw-r--r-- | service/transport.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/service/transport.go b/service/transport.go index c42462f..3ab2546 100644 --- a/service/transport.go +++ b/service/transport.go @@ -7,6 +7,7 @@ import ( "net/http" "path" "strconv" + "web/model" "github.com/gorilla/mux" ) @@ -305,6 +306,36 @@ func NewHandler(s Service, staticDir string) http.Handler { } }).Methods(http.MethodGet) + r.HandleFunc("/settings", func(w http.ResponseWriter, req *http.Request) { + ctx := getContextWithSession(context.Background(), req) + + err := s.ServeSettingsPage(ctx, w, nil) + if err != nil { + s.ServeErrorPage(ctx, w, err) + return + } + }).Methods(http.MethodGet) + + r.HandleFunc("/settings", func(w http.ResponseWriter, req *http.Request) { + ctx := getContextWithSession(context.Background(), req) + + visibility := req.FormValue("visibility") + copyScope := req.FormValue("copy_scope") == "true" + settings := &model.Settings{ + DefaultVisibility: visibility, + CopyScope: copyScope, + } + + err := s.SaveSettings(ctx, w, nil, settings) + if err != nil { + s.ServeErrorPage(ctx, w, err) + return + } + + w.Header().Add("Location", req.Header.Get("Referer")) + w.WriteHeader(http.StatusFound) + }).Methods(http.MethodPost) + r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) { // TODO remove session from database w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=;max-age=0")) |