QA bug fixes
This commit is contained in:
parent
311e9a75dd
commit
42eb051368
|
@ -1160,21 +1160,23 @@ App::patch('/v1/users/:userId/email')
|
||||||
|
|
||||||
$email = \strtolower($email);
|
$email = \strtolower($email);
|
||||||
|
|
||||||
// Makes sure this email is not already used in another identity
|
if (\strlen($email) !== 0) {
|
||||||
$identityWithMatchingEmail = $dbForProject->findOne('identities', [
|
// Makes sure this email is not already used in another identity
|
||||||
Query::equal('providerEmail', [$email]),
|
$identityWithMatchingEmail = $dbForProject->findOne('identities', [
|
||||||
Query::notEqual('userId', $user->getId()),
|
Query::equal('providerEmail', [$email]),
|
||||||
]);
|
Query::notEqual('userId', $user->getId()),
|
||||||
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) {
|
]);
|
||||||
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
|
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) {
|
||||||
}
|
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
$target = $dbForProject->findOne('targets', [
|
$target = $dbForProject->findOne('targets', [
|
||||||
Query::equal('identifier', [$email]),
|
Query::equal('identifier', [$email]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($target instanceof Document && !$target->isEmpty()) {
|
if ($target instanceof Document && !$target->isEmpty()) {
|
||||||
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
|
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$oldEmail = $user->getAttribute('email');
|
$oldEmail = $user->getAttribute('email');
|
||||||
|
@ -1184,7 +1186,6 @@ App::patch('/v1/users/:userId/email')
|
||||||
->setAttribute('emailVerification', false)
|
->setAttribute('emailVerification', false)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
||||||
/**
|
/**
|
||||||
|
@ -1193,7 +1194,11 @@ App::patch('/v1/users/:userId/email')
|
||||||
$oldTarget = $user->find('identifier', $oldEmail, 'targets');
|
$oldTarget = $user->find('identifier', $oldEmail, 'targets');
|
||||||
|
|
||||||
if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) {
|
if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) {
|
||||||
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $email));
|
if (\strlen($email) !== 0) {
|
||||||
|
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $email));
|
||||||
|
} else {
|
||||||
|
$dbForProject->deleteDocument('targets', $oldTarget->getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$dbForProject->deleteCachedDocument('users', $user->getId());
|
$dbForProject->deleteCachedDocument('users', $user->getId());
|
||||||
} catch (Duplicate $th) {
|
} catch (Duplicate $th) {
|
||||||
|
@ -1240,12 +1245,14 @@ App::patch('/v1/users/:userId/phone')
|
||||||
->setAttribute('phoneVerification', false)
|
->setAttribute('phoneVerification', false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$target = $dbForProject->findOne('targets', [
|
if (\strlen($number) !== 0) {
|
||||||
Query::equal('identifier', [$number]),
|
$target = $dbForProject->findOne('targets', [
|
||||||
]);
|
Query::equal('identifier', [$number]),
|
||||||
|
]);
|
||||||
|
|
||||||
if ($target instanceof Document && !$target->isEmpty()) {
|
if ($target instanceof Document && !$target->isEmpty()) {
|
||||||
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
|
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1256,7 +1263,11 @@ App::patch('/v1/users/:userId/phone')
|
||||||
$oldTarget = $user->find('identifier', $oldPhone, 'targets');
|
$oldTarget = $user->find('identifier', $oldPhone, 'targets');
|
||||||
|
|
||||||
if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) {
|
if ($oldTarget instanceof Document && !$oldTarget->isEmpty()) {
|
||||||
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $number));
|
if (\strlen($number) !== 0) {
|
||||||
|
$dbForProject->updateDocument('targets', $oldTarget->getId(), $oldTarget->setAttribute('identifier', $number));
|
||||||
|
} else {
|
||||||
|
$dbForProject->deleteDocument('targets', $oldTarget->getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$dbForProject->deleteCachedDocument('users', $user->getId());
|
$dbForProject->deleteCachedDocument('users', $user->getId());
|
||||||
} catch (Duplicate $th) {
|
} catch (Duplicate $th) {
|
||||||
|
|
Loading…
Reference in a new issue