Make sure only one user exists with a particular email when updating
This commit is contained in:
parent
922e688720
commit
594baa921b
|
@ -335,6 +335,19 @@ func UpdateUser(user *User) (updatedUser *User, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// Check if the email is already used
|
||||
if user.Email == "" {
|
||||
user.Email = theUser.Email
|
||||
} else {
|
||||
uu, err := getUser(&User{Email: user.Email}, true)
|
||||
if err != nil && !IsErrUserDoesNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
if uu.ID != user.ID {
|
||||
return nil, &ErrUserEmailExists{Email: user.Email, UserID: uu.ID}
|
||||
}
|
||||
}
|
||||
|
||||
user.Password = theUser.Password // set the password to the one in the database to not accedently resetting it
|
||||
|
||||
// Validate the avatar type
|
||||
|
|
Loading…
Reference in New Issue