aboutsummaryrefslogtreecommitdiff
path: root/service/transport.go
diff options
context:
space:
mode:
Diffstat (limited to 'service/transport.go')
-rw-r--r--service/transport.go31
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"))