From 20b4fe0c59357a433042732d46e38da9c3d14c3b Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 5 Apr 2025 20:26:57 +0800 Subject: database shall no longer be a global variable --- http_handle_login.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'http_handle_login.go') diff --git a/http_handle_login.go b/http_handle_login.go index ea1dbae..10bfdcd 100644 --- a/http_handle_login.go +++ b/http_handle_login.go @@ -35,7 +35,7 @@ func (s *server) httpHandleLogin(writer http.ResponseWriter, request *http.Reque username = request.PostFormValue("username") password = request.PostFormValue("password") - err = database.QueryRow(request.Context(), + err = s.database.QueryRow(request.Context(), "SELECT id, COALESCE(password, '') FROM users WHERE username = $1", username, ).Scan(&userID, &passwordHash) @@ -85,7 +85,7 @@ func (s *server) httpHandleLogin(writer http.ResponseWriter, request *http.Reque http.SetCookie(writer, &cookie) - _, err = database.Exec(request.Context(), "INSERT INTO sessions (user_id, session_id) VALUES ($1, $2)", userID, cookieValue) + _, 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()) return -- cgit v1.2.3