Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
wip
auth/middleware.go | 8 +++++--- config.example.ini | 2 +-
diff --git a/auth/middleware.go b/auth/middleware.go index 041352397cc30e77b7b87fe3d854ba1659bdb2c1..9b9ac39ccac001b8bd18be1d6281d2597a7c5ae8 100644 --- a/auth/middleware.go +++ b/auth/middleware.go @@ -8,6 +8,7 @@ "net/http" "strings" "time" "encoding/json" + "log" "golang.org/x/crypto/bcrypt" @@ -72,6 +73,8 @@ email := r.Form.Get("email") password := r.Form.Get("password") + log.Printf("User email %s", email) + dbConn := db.ForContext(r.Context()) row := dbConn.QueryRow( `SELECT id, email, encrypted_password FROM users WHERE email = $1`, @@ -85,6 +88,7 @@ err = bcrypt.CompareHashAndPassword([]byte(user.EncryptedPassword), []byte(password)) if err != nil { authError(w, "Incorrect Password", http.StatusUnauthorized) + return } @@ -95,14 +99,12 @@ return } - // TODO: Write the cookie part here authCookie := AuthCookie{Email: user.Email} cookieJson, err := json.Marshal(authCookie) signedCookie := keys.Encrypt(cookieJson) - expiration := time.Now().Add(365 * 24 * time.Hour) - cookie := http.Cookie{Name: "dinheiro.v1", Value: string(signedCookie), Expires: expiration} + cookie := http.Cookie{Name: "dinheiro.v1", Value: string(signedCookie)} http.SetCookie(w, &cookie) ctx := context.WithValue(r.Context(), authCtxKey, authCtx) diff --git a/config.example.ini b/config.example.ini index 4d1d4d321ff6d21be356de49746d75eef8c88f4b..feb6cd5de4e2cb54ad8a979389a2640837c82cf0 100644 --- a/config.example.ini +++ b/config.example.ini @@ -7,4 +7,4 @@ environment=development [database] # The database string connection which you'll use -connection-string=postgresql://postgres@localhost/dinheiro_dev +connection-string=postgresql://postgres@localhost/dinheiro_dev?sslmode=disable