summaryrefslogtreecommitdiff
path: root/pkg/webui/logout.go
blob: 6a281bbfc25e1048808f4aaaeea402d147a96566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
	})
}