update to use duplicate exception to check email already exists
This commit is contained in:
parent
73c27f9c3d
commit
bb666810d9
2 changed files with 10 additions and 14 deletions
|
@ -1066,17 +1066,15 @@ App::patch('/v1/account/email')
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = \strtolower($email);
|
$email = \strtolower($email);
|
||||||
$profile = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [\strtolower($email)])]); // Get user by email address
|
try {
|
||||||
|
|
||||||
if ($profile) {
|
|
||||||
throw new Exception('User already registered', 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = $dbForInternal->updateDocument('users', $user->getId(), $user
|
$user = $dbForInternal->updateDocument('users', $user->getId(), $user
|
||||||
->setAttribute('password', $isAnonymousUser ? Auth::passwordHash($password) : $user->getAttribute('password', ''))
|
->setAttribute('password', $isAnonymousUser ? Auth::passwordHash($password) : $user->getAttribute('password', ''))
|
||||||
->setAttribute('email', $email)
|
->setAttribute('email', $email)
|
||||||
->setAttribute('emailVerification', false) // After this user needs to confirm mail again
|
->setAttribute('emailVerification', false) // After this user needs to confirm mail again
|
||||||
);
|
);
|
||||||
|
} catch(Duplicate $th) {
|
||||||
|
throw new Exception('Email already exists', 409);
|
||||||
|
}
|
||||||
|
|
||||||
$audits
|
$audits
|
||||||
->setParam('userId', $user->getId())
|
->setParam('userId', $user->getId())
|
||||||
|
|
|
@ -485,14 +485,12 @@ App::patch('/v1/users/:userId/email')
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = \strtolower($email);
|
$email = \strtolower($email);
|
||||||
$profile = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [\strtolower($email)])]); // Get user by email address
|
try {
|
||||||
|
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('email', $email));
|
||||||
if ($profile) {
|
} catch(Duplicate $th) {
|
||||||
throw new Exception('Email already exists', 409);
|
throw new Exception('Email already exists', 409);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('email', $email));
|
|
||||||
|
|
||||||
$audits
|
$audits
|
||||||
->setParam('userId', $user->getId())
|
->setParam('userId', $user->getId())
|
||||||
->setParam('event', 'account.update.email')
|
->setParam('event', 'account.update.email')
|
||||||
|
|
Loading…
Reference in a new issue