Fix some errors
This commit is contained in:
parent
bd5c6b2abc
commit
d82d4c754e
@ -239,6 +239,7 @@ func (app *application) CreateAuthToken(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
err := app.readJSON(w, r, &userInput)
|
err := app.readJSON(w, r, &userInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
app.errorLog.Println(err)
|
||||||
app.badRequest(w, r, err)
|
app.badRequest(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -246,6 +247,7 @@ func (app *application) CreateAuthToken(w http.ResponseWriter, r *http.Request)
|
|||||||
// get the user from the db by email, send error if invalid email
|
// get the user from the db by email, send error if invalid email
|
||||||
user, err := app.DB.GetUserByEmail(userInput.Email)
|
user, err := app.DB.GetUserByEmail(userInput.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
app.errorLog.Println(err)
|
||||||
app.invalidCredentials(w)
|
app.invalidCredentials(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -253,6 +255,7 @@ func (app *application) CreateAuthToken(w http.ResponseWriter, r *http.Request)
|
|||||||
// validate the password, send error if invalid password
|
// validate the password, send error if invalid password
|
||||||
validPassword, err := app.passwordMatches(user.Password, userInput.Password)
|
validPassword, err := app.passwordMatches(user.Password, userInput.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
app.errorLog.Println(err)
|
||||||
app.invalidCredentials(w)
|
app.invalidCredentials(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ func (app *application) invalidCredentials(w http.ResponseWriter) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) passwordMatches(hash, password string) (bool, error) {
|
func (app *application) passwordMatches(hash, password string) (bool, error) {
|
||||||
|
app.errorLog.Println(hash, password)
|
||||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
|
@ -244,11 +244,12 @@ func (m *DBModel) GetUserByEmail(email string) (User, error) {
|
|||||||
&u.FirstName,
|
&u.FirstName,
|
||||||
&u.LastName,
|
&u.LastName,
|
||||||
&u.Email,
|
&u.Email,
|
||||||
|
&u.Password,
|
||||||
&u.CreatedAt,
|
&u.CreatedAt,
|
||||||
&u.UpdatedAt,
|
&u.UpdatedAt,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return User{}, err
|
return u, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user