/**
  * Validate a user object.
  *
  * Invokes User::validate(),
  * and additionally tests that the User's email address and username (if set) are unique across all users.'.
  *
  * @param User $user
  * @return array An array of error messages, or an empty array if the User is valid.
  */
 public function validate(User $user)
 {
     $errors = $user->validate();
     // TODO: Delete these, unique indexes solve this
     // Ensure email address is unique.
     $duplicates = $this->entityManager->getRepository($this->getUserClass())->findBy(array('email' => $user->getEmail()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['email'] = 'An account with that email address already exists.';
         }
     }
     // Ensure username is unique.
     $duplicates = $this->entityManager->getRepository($this->getUserClass())->findBy(array('username' => $user->getRealUsername()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['username'] = '******';
         }
     }
     // If username is required, ensure it is set.
     if ($this->isUsernameRequired && !$user->getRealUsername()) {
         $errors['username'] = '******';
     }
     return $errors;
 }
 public function sendResetMessage(User $user)
 {
     $url = $this->urlGenerator->generate(self::ROUTE_RESET_PASSWORD, array('token' => $user->getConfirmationToken()), true);
     $context = array('user' => $user, 'resetUrl' => $url);
     $this->sendMessage($this->resetTemplate, $context, $this->getFromEmail(), $user->getEmail());
 }
 /**
  * Validate a user object.
  *
  * Invokes User::validate(),
  * and additionally tests that the User's email address and username (if set) are unique across all users.'.
  *
  * @param User $user
  * @return array An array of error messages, or an empty array if the User is valid.
  */
 public function validate(User $user)
 {
     $errors = $user->validate();
     // Ensure email address is unique.
     $duplicates = $this->findBy(array($this->getUserColumns('email') => $user->getEmail()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['email'] = 'An account with that email address already exists.';
         }
     }
     // Ensure username is unique.
     $duplicates = $this->findBy(array($this->getUserColumns('username') => $user->getRealUsername()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['username'] = '******';
         }
     }
     // If username is required, ensure it is set.
     if ($this->isUsernameRequired && !$user->getRealUsername()) {
         $errors['username'] = '******';
     }
     return $errors;
 }
 /**
  * Validate a user object.
  *
  * Invokes User::validate(), and additionally tests that the User's email address isn't associated with another User.
  *
  * @param User $user
  * @return array An array of error messages, or an empty array if the User is valid.
  */
 public function validate(User $user)
 {
     $errors = $user->validate();
     $duplicates = $this->findBy(array('email' => $user->getEmail()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['email'] = 'An account with that email address already exists.';
         }
     }
     return $errors;
 }