mirror of
https://github.com/riwiwa/muzi.git
synced 2026-04-20 11:25:51 -07:00
add logout
This commit is contained in:
@@ -76,3 +76,19 @@ func getUserIdByUsername(ctx context.Context, username string) (int, error) {
|
||||
Scan(&userId)
|
||||
return userId, err
|
||||
}
|
||||
|
||||
func logoutHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie("session")
|
||||
if err == nil {
|
||||
deleteSession(cookie.Value)
|
||||
}
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "session",
|
||||
Value: "",
|
||||
Path: "/",
|
||||
MaxAge: -1,
|
||||
})
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ func Start() {
|
||||
r.Handle("/files/*", http.StripPrefix("/files", http.FileServer(http.Dir("./static"))))
|
||||
r.Get("/", rootHandler())
|
||||
r.Get("/login", loginPageHandler())
|
||||
r.Get("/logout", logoutHandler())
|
||||
r.Get("/createaccount", createAccountPageHandler())
|
||||
r.Get("/profile/{username}", profilePageHandler())
|
||||
r.Get("/profile/{username}/artist/{artist}", artistPageHandler())
|
||||
|
||||
Reference in New Issue
Block a user