refactor: check if the email is the same and return a new error for it
This commit is contained in:
parent
1d60cbf532
commit
080bef354d
|
@ -284,7 +284,7 @@ func (s AccountServiceDefault) UpdateAccountEmail(userId uint, email string, pas
|
|||
return NewAccountError(ErrKeyEmailAlreadyExists, nil)
|
||||
}
|
||||
|
||||
valid, _, err := s.ValidLoginByUserID(userId, password)
|
||||
valid, user, err := s.ValidLoginByUserID(userId, password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -293,6 +293,10 @@ func (s AccountServiceDefault) UpdateAccountEmail(userId uint, email string, pas
|
|||
return NewAccountError(ErrKeyInvalidLogin, nil)
|
||||
}
|
||||
|
||||
if user.Email == email {
|
||||
return NewAccountError(ErrKeyUpdatingSameEmail, nil)
|
||||
}
|
||||
|
||||
var update models.User
|
||||
|
||||
update.Email = email
|
||||
|
|
|
@ -9,6 +9,7 @@ const (
|
|||
// Account creation errors
|
||||
ErrKeyAccountCreationFailed = "ErrAccountCreationFailed"
|
||||
ErrKeyEmailAlreadyExists = "ErrEmailAlreadyExists"
|
||||
ErrKeyUpdatingSameEmail = "ErrUpdatingSameEmail"
|
||||
ErrKeyPasswordHashingFailed = "ErrPasswordHashingFailed"
|
||||
|
||||
// Account lookup and existence verification errors
|
||||
|
@ -56,6 +57,7 @@ var defaultErrorMessages = map[string]string{
|
|||
ErrKeyAccountCreationFailed: "Account creation failed due to an internal error.",
|
||||
ErrKeyEmailAlreadyExists: "The email address provided is already in use.",
|
||||
ErrKeyPasswordHashingFailed: "Failed to secure the password, please try again later.",
|
||||
ErrKeyUpdatingSameEmail: "The email address provided is the same as your current one.",
|
||||
|
||||
// Account lookup and existence verification errors
|
||||
ErrKeyUserNotFound: "The requested user was not found.",
|
||||
|
|
Loading…
Reference in New Issue