findUserByUsername() public method

Finds a user by username
public findUserByUsername ( string $username ) : User
$username string
return User
 private function testIfUsernameAlreadyInUse()
 {
     $email = $this->userManager->findUserByUsername($this->submitDatas['email']);
     if ($email) {
         throw new \Exception(json_encode(array("email" => "Cet email est déjà utilisé.")), 403);
     }
 }
Example #2
0
 /**
  * Fonction permettant de savoir si un utilisateur existe déja selon son username et email
  * @since 2.3 fourth argument id has ben removed
  * @param UserManager $userManager
  * @param string $username
  * @param string $userMail
  */
 private function userAlreadyExist(UserManager $userManager, $username, $userMail)
 {
     $alreadyExist = false;
     $userByUsername = $userManager->findUserByUsername($username);
     $userByUserMail = $userManager->findUserByEmail($userMail);
     if (isset($userByUsername)) {
         $this->get('session')->getFlashBag()->add('notice', "Le nom d'utilisateur est déjà utilisé.");
         $alreadyExist = true;
     }
     if (isset($userByUserMail)) {
         $this->get('session')->getFlashBag()->add('notice', "L'adresse e-mail est déjà utilisée.");
         $alreadyExist = true;
     }
     return $alreadyExist;
 }