Added session cookie and logout for admin

This commit is contained in:
2026-05-20 15:57:09 +02:00
parent 4d53a6b471
commit 93ca9ea33b
3 changed files with 86 additions and 1 deletions
+16 -1
View File
@@ -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)
}
}