summaryrefslogtreecommitdiffstats
path: root/roseh.moe.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-09-25 15:42:15 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-09-25 15:42:15 -0700
commitb7521777cdcd161f2eb9e1a664c4d0e28eefd0da (patch)
tree230c8d1b36fb9ec9b40f6d05874e720278717c99 /roseh.moe.go
parent35469f25cd53707b3e801caaff49121926bb7238 (diff)
downloadroseh.moe-b7521777cdcd161f2eb9e1a664c4d0e28eefd0da.tar.zst
Hard-code the redirect path
We can add back all that garbage when it's necessary
Diffstat (limited to 'roseh.moe.go')
-rw-r--r--roseh.moe.go42
1 files changed, 5 insertions, 37 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index bcadd3e..0c7003f 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -19,7 +19,6 @@ import (
"net/http"
"os"
"path/filepath"
- "strconv"
"strings"
"sync"
"time"
@@ -208,30 +207,6 @@ func cookieAuth(w http.ResponseWriter, r *http.Request) (string, bool) {
return csrfToken, true
}
-type redirectPath int
-
-const (
- redirectInvalid redirectPath = iota
- redirectNotepad
-)
-
-func parseRedirectPath(formVal string) redirectPath {
- i, err := strconv.Atoi(formVal)
- if err != nil {
- return redirectInvalid
- }
- return redirectPath(i)
-}
-
-func (r redirectPath) Path() (string, bool) {
- switch r {
- case redirectNotepad:
- return "/notepad", true
- default:
- return "", false
- }
-}
-
var (
//go:embed templates/login.html.template
loginString string
@@ -239,24 +214,17 @@ var (
)
type loginTemplateArgs struct {
- Error bool
- Redirect redirectPath
+ Error bool
}
func login(w http.ResponseWriter, r *http.Request) {
- redirectPathEnum := parseRedirectPath(r.FormValue("redirect"))
- redirectPath, ok := redirectPathEnum.Path()
- if !ok {
- http.Error(w, "Invalid redirect path", http.StatusBadRequest)
- return
- }
key, pwHash, err := pwhash.Hash(r.FormValue("password"), notepadPasswordSalt)
if err != nil {
http.Error(w, fmt.Sprintf("Unable to hash password: %s", err), http.StatusInternalServerError)
return
}
if subtle.ConstantTimeCompare(pwHash[:], notepadPassword) == 0 {
- if err := loginTemplate.Execute(w, loginTemplateArgs{Error: true, Redirect: redirectPathEnum}); err != nil {
+ if err := loginTemplate.Execute(w, loginTemplateArgs{Error: true}); err != nil {
log.Printf("Warning: login: %s", err)
}
return
@@ -267,7 +235,7 @@ func login(w http.ResponseWriter, r *http.Request) {
}
encryptionKeyMu.Unlock()
attachCookie(w)
- http.Redirect(w, r, redirectPath, http.StatusSeeOther)
+ http.Redirect(w, r, "/notepad", http.StatusSeeOther)
}
func readNotepad(key []byte) (string, error) {
@@ -304,7 +272,7 @@ type notepadTemplateArgs struct {
func notepad(w http.ResponseWriter, r *http.Request) {
csrfToken, ok := cookieAuth(w, r)
if !ok {
- if err := loginTemplate.Execute(w, loginTemplateArgs{Redirect: redirectNotepad}); err != nil {
+ if err := loginTemplate.Execute(w, loginTemplateArgs{}); err != nil {
log.Printf("Warning: login: %s", err)
}
return
@@ -313,7 +281,7 @@ func notepad(w http.ResponseWriter, r *http.Request) {
key := encryptionKey
encryptionKeyMu.Unlock()
if key == nil {
- if err := loginTemplate.Execute(w, loginTemplateArgs{Redirect: redirectNotepad}); err != nil {
+ if err := loginTemplate.Execute(w, loginTemplateArgs{}); err != nil {
log.Printf("Warning: login: %s", err)
}
return