From edc30e6d36b51f73d2db31e6fbc55f86e8ca451f Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 5 Apr 2025 23:18:30 +0800 Subject: web: Separate HTTP error pages into its own package --- http_handle_login.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'http_handle_login.go') diff --git a/http_handle_login.go b/http_handle_login.go index e626719..dfb74c8 100644 --- a/http_handle_login.go +++ b/http_handle_login.go @@ -13,6 +13,7 @@ import ( "github.com/alexedwards/argon2id" "github.com/jackc/pgx/v5" + "go.lindenii.runxiyu.org/forge/internal/web" ) // httpHandleLogin provides the login page for local users. @@ -45,7 +46,7 @@ func (s *Server) httpHandleLogin(writer http.ResponseWriter, request *http.Reque renderTemplate(writer, "login", params) return } - errorPage500(writer, params, "Error querying user information: "+err.Error()) + web.ErrorPage500(templates, writer, params, "Error querying user information: "+err.Error()) return } if passwordHash == "" { @@ -55,7 +56,7 @@ func (s *Server) httpHandleLogin(writer http.ResponseWriter, request *http.Reque } if passwordMatches, err = argon2id.ComparePasswordAndHash(password, passwordHash); err != nil { - errorPage500(writer, params, "Error comparing password and hash: "+err.Error()) + web.ErrorPage500(templates, writer, params, "Error comparing password and hash: "+err.Error()) return } @@ -66,7 +67,7 @@ func (s *Server) httpHandleLogin(writer http.ResponseWriter, request *http.Reque } if cookieValue, err = randomUrlsafeStr(16); err != nil { - errorPage500(writer, params, "Error getting random string: "+err.Error()) + web.ErrorPage500(templates, writer, params, "Error getting random string: "+err.Error()) return } @@ -87,7 +88,7 @@ func (s *Server) httpHandleLogin(writer http.ResponseWriter, request *http.Reque _, err = s.database.Exec(request.Context(), "INSERT INTO sessions (user_id, session_id) VALUES ($1, $2)", userID, cookieValue) if err != nil { - errorPage500(writer, params, "Error inserting session: "+err.Error()) + web.ErrorPage500(templates, writer, params, "Error inserting session: "+err.Error()) return } -- cgit v1.2.3