diff --git a/account/account.go b/account/account.go index e1e6605..cb8c7a0 100644 --- a/account/account.go +++ b/account/account.go @@ -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 diff --git a/account/errors.go b/account/errors.go index ebc4b10..9e41192 100644 --- a/account/errors.go +++ b/account/errors.go @@ -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.",