diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2018-12-29 05:50:59 -0500 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2018-12-29 05:50:59 -0500 |
| commit | c9fe24ecf99f301889415afea4206b5433480173 (patch) | |
| tree | 595d360d6dc35192d5cac4a44eedaec7cf7a6617 /main.go | |
| parent | 3345ce304365a577aa7d3f86e1b136b906610f1f (diff) | |
| download | id-c9fe24ecf99f301889415afea4206b5433480173.tar.gz | |
Add logout handler
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -37,7 +37,7 @@ func (app *App) validateHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } else { log.Println("Session does not exist:", c.Value) - w.WriteHeader(http.StatusForbidden) + w.WriteHeader(http.StatusUnauthorized) } } } @@ -69,6 +69,12 @@ func (app *App) loginHandler(w http.ResponseWriter, r *http.Request) { } } +func (app *App) logoutHandler(w http.ResponseWriter, r *http.Request) { + c := http.Cookie{Name: "id", Value: "", Domain: ".horel.test", MaxAge: 0} + http.SetCookie(w, &c) + http.Redirect(w, r, "/login", http.StatusSeeOther) +} + func main() { //log.SetFlags(log.LstdFlags) if len(os.Args) == 1 { @@ -79,6 +85,7 @@ func main() { app := &App{store, template} http.HandleFunc("/validate", app.validateHandler) http.HandleFunc("/login", app.loginHandler) + http.HandleFunc("/logout", app.logoutHandler) if err := http.ListenAndServe(":8080", logMux(http.DefaultServeMux)); err != nil { panic(err) } |
