Added session cookie and logout for admin
This commit is contained in:
+16
-1
@@ -74,7 +74,22 @@ func Login(tmpl *template.Template) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: create a session so the admin stays logged in
|
||||
token, err := auth.GenerateSession()
|
||||
if err != nil {
|
||||
tmpl.Execute(w, map[string]string{
|
||||
"SiteName": Cfg.SiteName,
|
||||
"Error": "Something went wrong. Please try again.",
|
||||
})
|
||||
return
|
||||
}
|
||||
auth.SetSessionCookie(w, token)
|
||||
http.Redirect(w, r, "/admin", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
|
||||
func Logout() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
auth.ClearSession(w, r)
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user