From 341762284173ff9a5fb570b126756b7232dfe4eb Mon Sep 17 00:00:00 2001 From: max Date: Fri, 21 Oct 2022 20:17:11 -0500 Subject: [PATCH] Pass response writer to createSessionCookie() --- database/models/user.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/database/models/user.go b/database/models/user.go index 4aca9f6..4b94e05 100644 --- a/database/models/user.go +++ b/database/models/user.go @@ -7,12 +7,13 @@ import ( "database/sql" "encoding/gob" "encoding/hex" - "golang.org/x/crypto/bcrypt" "log" "math" "net/http" "strconv" "time" + + "golang.org/x/crypto/bcrypt" ) type User struct { @@ -77,7 +78,7 @@ func CreateUser(app *app.App, username string, password string, createdAt time.T } // AuthenticateUser validates the password for the specified user if it matches a session cookie is created and returned -func AuthenticateUser(app *app.App, username string, password string) (string, error) { +func AuthenticateUser(app *app.App, w http.ResponseWriter, username string, password string) (string, error) { var hashedPassword []byte // Query row by username, scan password column @@ -105,12 +106,12 @@ func AuthenticateUser(app *app.App, username string, password string) (string, e log.Println(err) return "", err } else { - return createSessionCookie(app, username) + return createSessionCookie(app, w, username) } } // CreateSessionCookie creates a new session token and cookie and returns the token value -func createSessionCookie(app *app.App, username string) (string, error) { +func createSessionCookie(app *app.App, w http.ResponseWriter, username string) (string, error) { // Generate random 64 character string (alpha-numeric) buff := make([]byte, int(math.Ceil(float64(64)/2))) _, err := rand.Read(buff)