/**
  * @param mixed $user
  * @param TokenInterface $token
  * @throws \InvalidArgumentException
  */
 protected function setUser($user, TokenInterface $token)
 {
     if (!$user) {
         return;
     }
     $userId = filter_var($user, FILTER_VALIDATE_INT);
     if ($userId) {
         $userEntity = $this->registry->getRepository('OroUserBundle:User')->find($userId);
     } else {
         $userEntity = $this->userManager->findUserByUsernameOrEmail($user);
     }
     if ($userEntity) {
         $token->setUser($userEntity);
     } else {
         throw new \InvalidArgumentException(sprintf('Can\'t find user with identifier %s', $user));
     }
 }
 public function testFindUserByEmail()
 {
     $crit = array('email' => self::TEST_EMAIL);
     $this->repository->expects($this->once())->method('findOneBy')->with($this->equalTo($crit))->will($this->returnValue(array()));
     $this->userManager->findUserByUsernameOrEmail(self::TEST_EMAIL);
 }
Exemple #3
0
 /**
  * Finds a user by username.
  * This method is meant to be an extension point for possible child classes.
  *
  * @param  string    $username
  * @return User|null
  */
 protected function findUser($username)
 {
     return $this->userManager->findUserByUsernameOrEmail($username);
 }