diff options
| -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) } |
