summaryrefslogtreecommitdiffstats
path: root/roseh.moe.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-09-24 16:44:50 -0700
committerRose Hogenson <rosehogenson@posteo.net>2026-09-24 16:45:08 -0700
commit766b7586fde4f1321e2c23428001c2dd67576dd4 (patch)
tree0346ffedb96f8812b39a6fe44670e96f43caf185 /roseh.moe.go
parentRevert "Add request logging" (diff)
downloadroseh.moe-766b7586fde4f1321e2c23428001c2dd67576dd4.tar.zst
Add a way to log out
Diffstat (limited to 'roseh.moe.go')
-rw-r--r--roseh.moe.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 54ce6f4..53deb02 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -692,13 +692,10 @@ func makeToken() string {
return base64.RawURLEncoding.EncodeToString(append(t, mac(t, "auth")...))
}
-const cookieExpiration = 7 * 24 * time.Hour
-const authCookieName = "a"
-
-func attachCookie(w http.ResponseWriter) {
- http.SetCookie(w, &http.Cookie{
+func makeCookie(val string) *http.Cookie {
+ return &http.Cookie{
Name: authCookieName,
- Value: makeToken(),
+ Value: val,
Path: "/",
Domain: selfURL.Hostname(),
Expires: time.Now().Add(cookieExpiration),
@@ -706,7 +703,14 @@ func attachCookie(w http.ResponseWriter) {
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
Partitioned: true,
- })
+ }
+}
+
+const cookieExpiration = 7 * 24 * time.Hour
+const authCookieName = "a"
+
+func attachCookie(w http.ResponseWriter) {
+ http.SetCookie(w, makeCookie(makeToken()))
}
func cookieAuth(w http.ResponseWriter, r *http.Request) bool {
@@ -819,6 +823,11 @@ func login(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, redirect, http.StatusSeeOther)
}
+func logout(w http.ResponseWriter, r *http.Request) {
+ http.SetCookie(w, makeCookie("!"))
+ io.WriteString(w, "logged out\n")
+}
+
var (
//go:embed templates/note.html.template
notepadString string
@@ -1131,6 +1140,7 @@ func main() {
mux.HandleFunc("GET /wormhole/{hole}", wormholeDownload)
mux.HandleFunc("GET /login", serveLogin)
mux.HandleFunc("POST /login", login)
+ mux.Handle("GET /logout", &authHandler{h: http.HandlerFunc(logout), noRedirect: true})
mux.Handle("GET /notepad", &authHandler{h: http.HandlerFunc(notepad)})
mux.Handle("POST /notepad", &authHandler{h: http.HandlerFunc(autosave), noRedirect: true})
mux.HandleFunc("GET /cmd/{$}", cmdIndex)