From 5d58269132a27373ef8932ddcbbbf8b8637fa380 Mon Sep 17 00:00:00 2001 From: r Date: Sun, 2 Feb 2020 08:30:40 +0000 Subject: Add status deletion --- service/transport.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'service/transport.go') diff --git a/service/transport.go b/service/transport.go index cc864e7..6316748 100644 --- a/service/transport.go +++ b/service/transport.go @@ -290,7 +290,7 @@ func NewHandler(s Service, staticDir string) http.Handler { ctx := newCtxWithSesion(req) token := req.URL.Query().Get("code") - _, err := s.Signin(ctx, c, "", token) + _, _, err := s.Signin(ctx, c, "", token) if err != nil { w.WriteHeader(http.StatusInternalServerError) s.ServeErrorPage(ctx, c, err) @@ -513,6 +513,22 @@ func NewHandler(s Service, staticDir string) http.Handler { w.WriteHeader(http.StatusFound) } + delete := func(w http.ResponseWriter, req *http.Request) { + c := newClient(w) + ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token")) + id, _ := mux.Vars(req)["id"] + + err := s.Delete(ctx, c, id) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + s.ServeErrorPage(ctx, c, err) + return + } + + w.Header().Add("Location", req.Header.Get("Referer")) + w.WriteHeader(http.StatusFound) + } + signout := func(w http.ResponseWriter, req *http.Request) { // TODO remove session from database http.SetCookie(w, &http.Cookie{ @@ -622,6 +638,7 @@ func NewHandler(s Service, staticDir string) http.Handler { r.HandleFunc("/settings", settings).Methods(http.MethodPost) r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost) r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost) + r.HandleFunc("/delete/{id}", delete).Methods(http.MethodPost) r.HandleFunc("/signout", signout).Methods(http.MethodGet) r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost) r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost) -- cgit v1.2.3