fix: login service should test IsEnabled
This commit is contained in:
parent
92dc04041e
commit
5b5bf0a070
@ -22,6 +22,7 @@ const (
|
||||
UserDuplicated Status = 302
|
||||
UserUnauthenticated Status = 303
|
||||
UserUnauthorized Status = 304
|
||||
UserDisabled Status = 305
|
||||
|
||||
RedisError Status = 400
|
||||
)
|
||||
@ -48,6 +49,7 @@ var msgText = map[Status]string{
|
||||
UserDuplicated: "User Duplicated",
|
||||
UserUnauthenticated: "User Unauthenticated",
|
||||
UserUnauthorized: "User Unauthorized",
|
||||
UserDisabled: "User Disabled",
|
||||
|
||||
RedisError: "Redis Error",
|
||||
}
|
||||
|
@ -13,15 +13,19 @@ func (s *service) Login(data *model.User) (*model.User, e.Status) {
|
||||
|
||||
err := s.db.Where(user).First(&user).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return user, e.UserNotFound
|
||||
return nil, e.UserNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return user, e.DatabaseError
|
||||
return nil, e.DatabaseError
|
||||
}
|
||||
|
||||
if !user.IsEnabled {
|
||||
return nil, e.UserDisabled
|
||||
}
|
||||
|
||||
err = bcrypt.CompareHashAndPassword(user.Password, data.Password)
|
||||
if err != nil {
|
||||
return user, e.UserWrongPassword
|
||||
return nil, e.UserWrongPassword
|
||||
}
|
||||
|
||||
return user, e.Success
|
||||
|
Loading…
Reference in New Issue
Block a user