separate logout page + redirect

This commit is contained in:
Simon Martens
2025-05-22 21:33:10 +02:00
parent 36e34d9e7b
commit 2a08e5fec7
6 changed files with 71 additions and 5 deletions

View File

@@ -138,6 +138,10 @@ func (p *LoginPage) POST(engine *templating.Engine, app core.App) HandleFunc {
})
}
return e.Redirect(303, "/reihen")
redirect := "/reihen"
if r := e.Request.URL.Query().Get("redirectTo"); r != "" {
redirect = r
}
return e.Redirect(303, redirect)
}
}

52
pages/logout.go Normal file
View File

@@ -0,0 +1,52 @@
package pages
import (
"net/http"
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/router"
)
func init() {
lp := &LogoutPage{
StaticPage: pagemodels.StaticPage{
Name: pagemodels.P_LOGOUT_NAME,
Layout: "blank",
Template: "/logout/",
URL: "/logout/",
},
}
app.Register(lp)
}
type LogoutPage struct {
pagemodels.StaticPage
}
func (p *LogoutPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
router.GET(p.URL, p.GET())
return nil
}
func (p *LogoutPage) GET() HandleFunc {
return func(e *core.RequestEvent) error {
// TODO: the function to delete tokens is not yet there
// as of right now, the tokens get only deleted from the clients
// We need to delete the tokens from the cache + table.
e.SetCookie(&http.Cookie{
Name: dbmodels.SESSION_COOKIE_NAME,
Path: "/",
MaxAge: -1,
})
e.Response.Header().Set("Clear-Site-Data", "\"cookies\"")
redirect := "/reihen"
if r := e.Request.URL.Query().Get("redirectTo"); r != "" {
redirect = r
}
return e.Redirect(303, redirect)
}
}