Make sure only one user exists with a particular email when updating

This commit is contained in:
kolaente 2020-08-13 16:41:29 +02:00
parent 922e688720
commit 594baa921b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 13 additions and 0 deletions

View File

@ -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