summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--roseh.moe.go42
-rw-r--r--templates/login.html.template1
2 files changed, 5 insertions, 38 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
diff --git a/templates/login.html.template b/templates/login.html.template
index 696defe..0cf3469 100644
--- a/templates/login.html.template
+++ b/templates/login.html.template
@@ -7,6 +7,5 @@
<form class="password-form" action="/login" method="post">
<label class="password-label" for="password">Enter password</label>
<input id="password" class="password" type="password" name="password" autofocus>
- <input type="hidden" name="redirect" value="{{.Redirect}}">
</form>
</section>