aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-13 20:23:15 +0000
committerr <r@freesoftwareextremist.com>2019-12-13 20:23:15 +0000
commit9ba666009bc5c67f7c09103393e4142f6739c78d (patch)
treed380bcbde1800311fd530a2cefbdd5a5ce8c2f46
parent28226401d76ebedb39129746eaaa1613c452f0eb (diff)
downloadbloat-9ba666009bc5c67f7c09103393e4142f6739c78d.tar.gz
bloat-9ba666009bc5c67f7c09103393e4142f6739c78d.zip
Add signout method
-rw-r--r--service/transport.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/service/transport.go b/service/transport.go
index f4f5ed7..709a2ff 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -29,11 +29,15 @@ func NewHandler(s Service, staticDir string) http.Handler {
http.FileServer(http.Dir(path.Join(".", staticDir)))))
r.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
- err := s.ServeHomePage(ctx, w)
- if err != nil {
- s.ServeErrorPage(ctx, w, err)
- return
+ location := "/signin"
+
+ sessionID, _ := req.Cookie("session_id")
+ if sessionID != nil && len(sessionID.Value) > 0 {
+ location = "/timeline"
}
+
+ w.Header().Add("Location", location)
+ w.WriteHeader(http.StatusSeeOther)
}).Methods(http.MethodGet)
r.HandleFunc("/signin", func(w http.ResponseWriter, req *http.Request) {
@@ -157,9 +161,20 @@ func NewHandler(s Service, staticDir string) http.Handler {
return
}
- w.Header().Add("Location", req.Header.Get("Referer"))
+ location := "/timeline"
+ if len(replyToID) > 0 {
+ location = "/thread/" + replyToID
+ }
+ w.Header().Add("Location", location)
w.WriteHeader(http.StatusSeeOther)
}).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"))
+ w.Header().Add("Location", "/")
+ w.WriteHeader(http.StatusSeeOther)
+ }).Methods(http.MethodGet)
+
return r
}