Added logout
This commit is contained in:
parent
f52674b179
commit
3d3fb3c826
@ -49,6 +49,7 @@ func main() {
|
||||
mux.HandleFunc("GET /create-user/", view.CreateUser)
|
||||
mux.HandleFunc("GET /edit-user/", view.EditUser(db, store))
|
||||
mux.HandleFunc("GET /hub/", view.ShowHub(db, store))
|
||||
mux.HandleFunc("GET /logout/", view.Logout(store))
|
||||
mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(db, store))
|
||||
mux.HandleFunc("GET /rss/", view.ShowRSS(
|
||||
db,
|
||||
|
@ -88,3 +88,25 @@ func Login(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user.Role)
|
||||
}
|
||||
}
|
||||
|
||||
func Logout(s *control.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := s.Get(r, "cookie")
|
||||
if err != nil {
|
||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||
}
|
||||
|
||||
session.Options.MaxAge = -1
|
||||
|
||||
if err = session.Save(r, w); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,6 @@
|
||||
<input name="password" placeholder="Neues Passwort" type="password" />
|
||||
<input name="password2" placeholder="Wiederholen" type="password" />
|
||||
|
||||
<input type="submit" hx-post="/update-user/" hx-target="#page-content" />
|
||||
<input type="submit" value="Aktualisieren" hx-post="/update-user/" hx-target="#page-content" />
|
||||
</form>
|
||||
{{end}}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
<body>
|
||||
<h1>Orient Editor</h1>
|
||||
<button hx-get="logout" hx-target="#page-content">Abmelden</button>
|
||||
|
||||
<div id="page-content">
|
||||
{{template "page-content" .}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user