chore(webui): rewrite the web session code again while preparing for csrf tokens
#60
This commit is contained in:
parent
3bb5e735c6
commit
895615ad6e
20 changed files with 162 additions and 149 deletions
|
@ -1,6 +1,7 @@
|
|||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
@ -17,15 +18,16 @@ func handleLogoutGET(db *database.DB) http.Handler {
|
|||
}
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value(model.SessionContextKey{}).(*model.Session)
|
||||
sessionId, err := db.MigrateSession(session, nil)
|
||||
sessionId, session, err := db.MigrateSession(session, nil)
|
||||
if err != nil {
|
||||
errorResponse(w, r, http.StatusInternalServerError,
|
||||
fmt.Errorf("failed to migrate session: %w", err))
|
||||
return
|
||||
}
|
||||
setSessionCookie(w, sessionId)
|
||||
ctx := context.WithValue(r.Context(), model.SessionContextKey{}, session)
|
||||
render(w, logoutTemplate, http.StatusOK, logoutPage{
|
||||
Page: makePage(r, &Page{Title: "Logout", Section: "login"}),
|
||||
Page: makePage(r.WithContext(ctx), &Page{Title: "Logout", Section: "login"}),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue