diff options
| author | Samuel Johnson <[email protected]> | 2025-11-25 19:47:20 -0500 |
|---|---|---|
| committer | Samuel Johnson <[email protected]> | 2025-11-25 19:47:20 -0500 |
| commit | 3c237fc659c2829042407697ca7aa3e1442a5719 (patch) | |
| tree | 6557b2faa27eb9880ef96c8755bed3f8a461d2ae /cmd/web/handlers/login.go | |
| parent | 368a462bc744d8e9084eacfaddeb9afcaf7f7133 (diff) | |
Add post editing interface
Diffstat (limited to 'cmd/web/handlers/login.go')
| -rw-r--r-- | cmd/web/handlers/login.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/cmd/web/handlers/login.go b/cmd/web/handlers/login.go index e867e07..87684ba 100644 --- a/cmd/web/handlers/login.go +++ b/cmd/web/handlers/login.go @@ -21,13 +21,13 @@ type loginContext struct { func (ctx *loginContext) index(w http.ResponseWriter, r *http.Request) { files := []string{ "ui/html/base.tmpl.html", - "ui/html/login.tmpl.html", "ui/html/music_player.tmpl.html", + "ui/html/pages/login.tmpl.html", } compiled, err := template.ParseFiles(files...) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Server Error")) ctx.err.Printf("Failed to parse templates: %v\n", err) return @@ -35,7 +35,7 @@ func (ctx *loginContext) index(w http.ResponseWriter, r *http.Request) { err = compiled.ExecuteTemplate(w, "base", ctx) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Server Error")) ctx.err.Printf("Failed to parse templates: %v\n", err) return @@ -46,14 +46,14 @@ func (ctx *loginContext) index(w http.ResponseWriter, r *http.Request) { func (ctx *loginContext) login(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { - w.WriteHeader(405) + w.WriteHeader(http.StatusMethodNotAllowed) w.Write([]byte("Method Not Allowed")) return } err := r.ParseForm() if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Error")) ctx.err.Printf("Failed to retrieve form data: %v\n", err) return @@ -65,7 +65,7 @@ func (ctx *loginContext) login(w http.ResponseWriter, r *http.Request) { stmt, err := ctx.db.Prepare("SELECT * FROM logins WHERE name = $1;") if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Error")) ctx.err.Printf("Failed to retrieve form data: %v\n", err) return @@ -77,7 +77,7 @@ func (ctx *loginContext) login(w http.ResponseWriter, r *http.Request) { row := stmt.QueryRow(user) err = row.Scan(&u.Id, &u.Name, &u.Time, &u.PassOne, &u.PassTwo) if err != nil { - w.WriteHeader(401) + w.WriteHeader(http.StatusUnauthorized) w.Write([]byte("Unauthorized")) ctx.err.Printf("Failed to retrieve user info from DB: %v\n", err) return @@ -86,7 +86,7 @@ func (ctx *loginContext) login(w http.ResponseWriter, r *http.Request) { passOneErr := bcrypt.CompareHashAndPassword([]byte(u.PassOne), []byte(passOne)) passTwoErr := bcrypt.CompareHashAndPassword([]byte(u.PassTwo), []byte(passTwo)) if passOneErr != nil || passTwoErr != nil { - w.WriteHeader(401) + w.WriteHeader(http.StatusUnauthorized) w.Write([]byte("Failed to login - not authorized")) return } @@ -103,7 +103,7 @@ func (ctx *loginContext) login(w http.ResponseWriter, r *http.Request) { commit, err := ctx.db.Prepare("INSERT INTO cookies (content, user_id, expiration) VALUES ($1, $2, $3);") if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Error")) ctx.err.Printf("Failed to prepare DB statement: %v\n", err) return @@ -111,7 +111,7 @@ func (ctx *loginContext) login(w http.ResponseWriter, r *http.Request) { _, err = commit.Exec(cookie.Value, u.Id, cookie.Expires) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Error")) ctx.err.Printf("Failed to prepare DB statement: %v\n", err) } @@ -124,14 +124,14 @@ func (ctx *loginContext) login(w http.ResponseWriter, r *http.Request) { func (ctx *loginContext) logout(w http.ResponseWriter, r *http.Request) { cookie, err := r.Cookie("paterissa_session_token") if err != nil { - w.WriteHeader(405) + w.WriteHeader(http.StatusUnauthorized) w.Write([]byte("Unauthorized")) return } stmt, err := ctx.db.Prepare("UPDATE cookies SET expiration = $1 WHERE content = $2;") if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Error")) ctx.err.Printf("Could not prepare DB statement: %v\n", err) return @@ -140,7 +140,7 @@ func (ctx *loginContext) logout(w http.ResponseWriter, r *http.Request) { _, err = stmt.Exec(time.Now(), cookie.Value) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Internal Error")) ctx.err.Printf("Could not execute DB statement: %v\n", err) return |
