feat(webui): implement logout process

This commit is contained in:
Julien Dessaux 2025-01-13 10:11:20 +01:00
parent aef0b00fb9
commit 1292d189cf
Signed by: adyxax
GPG key ID: F92E51B86E07177E
5 changed files with 52 additions and 10 deletions

24
pkg/webui/logout.go Normal file
View file

@ -0,0 +1,24 @@
package webui
import (
"html/template"
"net/http"
"git.adyxax.org/adyxax/tfstated/pkg/database"
"git.adyxax.org/adyxax/tfstated/pkg/model"
)
var logoutTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/logout.html"))
func handleLogoutGET(db *database.DB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value(model.SessionContextKey{})
err := db.DeleteSession(session.(*model.Session))
if err != nil {
errorResponse(w, http.StatusInternalServerError, err)
return
}
unsetSesssionCookie(w)
render(w, logoutTemplate, http.StatusOK, nil)
})
}