added logout

This commit is contained in:
Stephen McQuay 2013-02-26 22:39:26 -08:00
parent 2fee9546f8
commit a8ff26af15
2 changed files with 9 additions and 0 deletions

View File

@ -24,3 +24,11 @@ func loginHandler(w http.ResponseWriter, req *http.Request) {
} }
T("login.html").Execute(w, map[string]interface{}{}) T("login.html").Execute(w, map[string]interface{}{})
} }
func logoutHandler(w http.ResponseWriter, req *http.Request) {
session, _ := store.Get(req, "creds")
delete(session.Values, "logged in")
session.Save(req, w)
http.Redirect(w, req, "/", http.StatusSeeOther)
return
}

View File

@ -29,6 +29,7 @@ func main() {
} else { } else {
http.HandleFunc("/", homeHandler) http.HandleFunc("/", homeHandler)
http.HandleFunc("/login", loginHandler) http.HandleFunc("/login", loginHandler)
http.HandleFunc("/logout", logoutHandler)
http.Handle("/s/", http.StripPrefix("/s/", http.Handle("/s/", http.StripPrefix("/s/",
http.FileServer(http.Dir(*static_files)))) http.FileServer(http.Dir(*static_files))))
if err := http.ListenAndServe(*addr, nil); err != nil { if err := http.ListenAndServe(*addr, nil); err != nil {