small pixel drawing of a pufferfish vore

make site more friendly
Jes Olson j3s@c3f.net
Sat, 18 Mar 2023 18:30:09 -0700
commit

43b570b7cc35424e98c7401117f12d13254a066f

parent

33e1086b952396577e2c65c5e25d2eeb650def4b

3 files changed, 29 insertions(+), 25 deletions(-)

jump to
M main.gomain.go

@@ -9,7 +9,16 @@ func main() {

s := New() mux := http.NewServeMux() - mux.HandleFunc("/", s.indexHandler) + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/" { + s.indexHandler(w, r) + return + } + if r.URL.Path == "/" { + s.indexHandler(w, r) + return + } + }) mux.HandleFunc("/login", s.loginHandler) mux.HandleFunc("/logout", s.logoutHandler) mux.HandleFunc("/register", s.registerHandler)
M readmereadme

@@ -10,18 +10,18 @@ [x] GET /login

form (existing account): username & password form (new account): username & password built & maintained by jes - [ ] POST /login + [x] POST /login success: add session cookie - update last_login redirect to /{username} fail: log an existing user in, add session cookie, redirect to /{username} login failure, redirect to /login - [ ] POST /logout + [x] POST /logout delete session cookie if exists redirect to / - [ ] POST /register + TODO: expire session_token from db eventually + [x] POST /register success: add session cookie redirect to /

@@ -29,6 +29,7 @@ fail:

update add new user & hashed password to database register failure: redirect to /login + TODO: validate user input [ ] GET /{username} display pretty feeds for a given user there is a button to view the raw feed list (plaintext)

@@ -43,9 +44,6 @@

if validated, display locked list of feeds with button: submit [ ] POST /{username}/feeds subscribe to all of the feeds in your textbox - - maybe: - rate limiting for logins & registrations background: fetch feeds every ~90m
M site.gosite.go

@@ -31,20 +31,14 @@ func (s *Site) indexHandler(w http.ResponseWriter, r *http.Request) {

if !methodAllowed(w, r, "GET") { return } - // The "/" pattern matches everything, so we need to check - // that we're at the root here. - if r.URL.Path != "/" { - http.NotFound(w, r) - return - } if s.loggedIn(r) { - fmt.Fprintf(w, `<h1>index</h1> - <small>logged in as %s - (<a href="/logout">logout</a>) - </small>`, s.username(r)) + fmt.Fprintf(w, `<!DOCTYPE html> + <title>%s</title> + <p> { %s <a href=/logout>logout</a> }`, s.title, s.username(r)) } else { - fmt.Fprintf(w, `<h1>index</h1> - <a href="/login">login</a>`) + fmt.Fprintf(w, `<!DOCTYPE html> + <title>%s</title> + <a href="/login">login</a>`, s.title) } }

@@ -56,7 +50,8 @@ if r.Method == "GET" {

if s.loggedIn(r) { fmt.Fprintf(w, "you are already logged in :3\n") } else { - fmt.Fprintf(w, `<h1>login</h1> + fmt.Fprintf(w, `<!DOCTYPE html> + <pre>login</pre> <form method="POST" action="/login"> <label for="username">username:</label> <input type="text" name="username" required><br>

@@ -74,9 +69,10 @@ password := r.FormValue("password")

err := s.login(w, username, password) if err != nil { - fmt.Fprintf(w, `<h1>incorrect username/password</h1> - <p>if you want to register a new account, click the tree: - <a href="/register">🌳</a>`) + fmt.Fprintf(w, `<!DOCTYPE html> + <p>⚠️ incorrect username/password ⚠️ + <p>to register a new account, click the skull: + <a href="/register">💀</a>`) return } http.Redirect(w, r, "/", http.StatusSeeOther)

@@ -101,7 +97,8 @@ return

} if r.Method == "GET" { - fmt.Fprintf(w, `<h1>register</h1> + fmt.Fprintf(w, `<!DOCTYPE html> + <pre>register</pre> <form method="POST" action="/register"> <label for="username">username:</label> <input type="text" name="username" required><br>