1
0
Fork 0
mirror of synced 2024-06-28 19:20:25 +12:00

update to use duplicate exception to check email already exists

This commit is contained in:
Damodar Lohani 2021-08-29 17:45:25 +05:45
parent 73c27f9c3d
commit bb666810d9
2 changed files with 10 additions and 14 deletions

View file

@ -1066,17 +1066,15 @@ App::patch('/v1/account/email')
}
$email = \strtolower($email);
$profile = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [\strtolower($email)])]); // Get user by email address
if ($profile) {
throw new Exception('User already registered', 400);
}
$user = $dbForInternal->updateDocument('users', $user->getId(), $user
try {
$user = $dbForInternal->updateDocument('users', $user->getId(), $user
->setAttribute('password', $isAnonymousUser ? Auth::passwordHash($password) : $user->getAttribute('password', ''))
->setAttribute('email', $email)
->setAttribute('emailVerification', false) // After this user needs to confirm mail again
);
);
} catch(Duplicate $th) {
throw new Exception('Email already exists', 409);
}
$audits
->setParam('userId', $user->getId())

View file

@ -484,15 +484,13 @@ App::patch('/v1/users/:userId/email')
throw new Exception('User not found', 404);
}
$email = \strtolower($email);
$profile = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [\strtolower($email)])]); // Get user by email address
if ($profile) {
$email = \strtolower($email);
try {
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('email', $email));
} catch(Duplicate $th) {
throw new Exception('Email already exists', 409);
}
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('email', $email));
$audits
->setParam('userId', $user->getId())
->setParam('event', 'account.update.email')