mirror of
https://github.com/riwiwa/muzi.git
synced 2026-03-04 00:51:59 -08:00
add logout
This commit is contained in:
11
static/assets/icons/logout.svg
Normal file
11
static/assets/icons/logout.svg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="currentColor"
|
||||||
|
>
|
||||||
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>
|
||||||
|
<polyline points="16 17 21 12 16 7"/>
|
||||||
|
<line x1="21" y1="12" x2="9" y2="12"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 257 B |
@@ -31,6 +31,10 @@
|
|||||||
<img src="/files/assets/icons/user.svg" class="menu-icon" alt="Profile">
|
<img src="/files/assets/icons/user.svg" class="menu-icon" alt="Profile">
|
||||||
<span>My Profile</span>
|
<span>My Profile</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="/logout" class="menu-item">
|
||||||
|
<img src="/files/assets/icons/logout.svg" class="menu-icon" alt="Logout">
|
||||||
|
<span>Logout</span>
|
||||||
|
</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="/login" class="menu-item">
|
<a href="/login" class="menu-item">
|
||||||
<img src="/files/assets/icons/user.svg" class="menu-icon" alt="Login">
|
<img src="/files/assets/icons/user.svg" class="menu-icon" alt="Login">
|
||||||
|
|||||||
@@ -76,3 +76,19 @@ func getUserIdByUsername(ctx context.Context, username string) (int, error) {
|
|||||||
Scan(&userId)
|
Scan(&userId)
|
||||||
return userId, err
|
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.Handle("/files/*", http.StripPrefix("/files", http.FileServer(http.Dir("./static"))))
|
||||||
r.Get("/", rootHandler())
|
r.Get("/", rootHandler())
|
||||||
r.Get("/login", loginPageHandler())
|
r.Get("/login", loginPageHandler())
|
||||||
|
r.Get("/logout", logoutHandler())
|
||||||
r.Get("/createaccount", createAccountPageHandler())
|
r.Get("/createaccount", createAccountPageHandler())
|
||||||
r.Get("/profile/{username}", profilePageHandler())
|
r.Get("/profile/{username}", profilePageHandler())
|
||||||
r.Get("/profile/{username}/artist/{artist}", artistPageHandler())
|
r.Get("/profile/{username}/artist/{artist}", artistPageHandler())
|
||||||
|
|||||||
Reference in New Issue
Block a user