improve user unique check (#3621)
This commit is contained in:
@@ -35,7 +35,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
* )
|
||||
* @UniqueEntity("username")
|
||||
* @UniqueEntity("email")
|
||||
* @Constraints\User(groups={"UserCreate", "Registration", "Default"})
|
||||
* @Constraints\User(groups={"UserCreate", "Registration", "Default", "Profile"})
|
||||
*
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
* @Serializer\VirtualProperty(
|
||||
|
||||
@@ -44,15 +44,14 @@ class UserValidator extends ConstraintValidator
|
||||
|
||||
protected function validateUser(UserEntity $user, ExecutionContextInterface $context)
|
||||
{
|
||||
$matchedEmail = false;
|
||||
if ($user->getEmail() !== null) {
|
||||
$this->validateEmailExists($user->getId(), $user->getEmail(), 'email', User::USER_EXISTING_EMAIL, $context);
|
||||
$this->validateEmailExists($user->getId(), $user->getUsername(), 'username', User::USER_EXISTING_NAME_AS_EMAIL, $context);
|
||||
$this->validateUsernameExists($user->getId(), $user->getEmail(), 'email', User::USER_EXISTING_EMAIL_AS_NAME, $context);
|
||||
}
|
||||
|
||||
if ($user->getUsername() !== null) {
|
||||
$this->validateEmailExists($user->getId(), $user->getUsername(), 'username', User::USER_EXISTING_NAME_AS_EMAIL, $context);
|
||||
$this->validateUsernameExists($user->getId(), $user->getUsername(), 'username', User::USER_EXISTING_NAME, $context);
|
||||
$this->validateUsernameExists($user->getId(), $user->getEmail(), 'email', User::USER_EXISTING_EMAIL_AS_NAME, $context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user