Authenticate authenticates a user
(email, password string)
| 129 | |
| 130 | // Authenticate authenticates a user |
| 131 | func (a *App) Authenticate(email, password string) (*database.User, error) { |
| 132 | user, err := a.GetUserByEmail(email) |
| 133 | if err != nil { |
| 134 | return nil, err |
| 135 | } |
| 136 | |
| 137 | err = bcrypt.CompareHashAndPassword([]byte(user.Password.String), []byte(password)) |
| 138 | if err != nil { |
| 139 | return nil, ErrLoginInvalid |
| 140 | } |
| 141 | |
| 142 | return user, nil |
| 143 | } |
| 144 | |
| 145 | // UpdateUserPassword updates a user's password with validation |
| 146 | func UpdateUserPassword(db *gorm.DB, user *database.User, newPassword string) error { |