aboutsummaryrefslogtreecommitdiff
path: root/http_handle_login.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-13 09:33:19 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-13 09:33:19 +0800
commit91ca7bf1baf7ab077bdd63a7a3930c15af5be325 (patch)
tree1c670aa1da48f1e3edc7144a0c63231aa7b465e2 /http_handle_login.go
parentTODO: Fix diff view (diff)
downloadforge-91ca7bf1baf7ab077bdd63a7a3930c15af5be325.tar.gz
forge-91ca7bf1baf7ab077bdd63a7a3930c15af5be325.tar.zst
forge-91ca7bf1baf7ab077bdd63a7a3930c15af5be325.zip
http_*.go: Use http.Error
Diffstat (limited to 'http_handle_login.go')
-rw-r--r--http_handle_login.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/http_handle_login.go b/http_handle_login.go
index 6f98859..70a8c8b 100644
--- a/http_handle_login.go
+++ b/http_handle_login.go
@@ -16,7 +16,7 @@ func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any)
if r.Method != "POST" {
err := templates.ExecuteTemplate(w, "login", params)
if err != nil {
- fmt.Fprintln(w, "Error rendering template:", err.Error())
+ http.Error(w, "Error rendering template:: "+err.Error(), http.StatusInternalServerError)
}
return
}
@@ -32,17 +32,17 @@ func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any)
params["login_error"] = "Unknown username"
err := templates.ExecuteTemplate(w, "login", params)
if err != nil {
- fmt.Fprintln(w, "Error rendering template:", err.Error())
+ http.Error(w, "Error rendering template:: "+err.Error(), http.StatusInternalServerError)
}
return
}
- fmt.Fprintln(w, "Error querying user information:", err.Error())
+ http.Error(w, "Error querying user information:: "+err.Error(), http.StatusInternalServerError)
return
}
match, err := argon2id.ComparePasswordAndHash(password, password_hash)
if err != nil {
- fmt.Fprintln(w, "Error comparing password and hash:", err.Error())
+ http.Error(w, "Error comparing password and hash:: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -50,7 +50,7 @@ func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any)
params["login_error"] = "Invalid password"
err := templates.ExecuteTemplate(w, "login", params)
if err != nil {
- fmt.Fprintln(w, "Error rendering template:", err.Error())
+ http.Error(w, "Error rendering template:: "+err.Error(), http.StatusInternalServerError)
return
}
return
@@ -75,7 +75,7 @@ func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any)
_, err = database.Exec(r.Context(), "INSERT INTO sessions (user_id, session_id) VALUES ($1, $2)", user_id, cookie_value)
if err != nil {
- fmt.Fprintln(w, "Error inserting session:", err.Error())
+ http.Error(w, "Error inserting session:: "+err.Error(), http.StatusInternalServerError)
return
}