/**
  * Using the given email finds the user and verifies it's password.
  * If the user is not fund or if the password is wrong, it throws.
  *
  * @param array $credentials
  * @throws AuthenticationException
  * @return User|NULL
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     if (!($user = $this->userRepository->findOneBy(['email' => $username]))) {
         throw new AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
     } elseif (!$user->verifyPassword($password)) {
         throw new AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL);
     }
     return $user;
 }
 protected function startup()
 {
     parent::startup();
     if ($this->key) {
         if (($user = $this->userRepository->findOneBy(array('userKey' => $this->key))) === NULL) {
             throw new BadRequestException();
         }
         $this->userRepository->delete($user);
         $this->flashMessage('Byl jste odhlášen z newsletteru.', 'success');
         $this->redirect('this', array('key' => NULL));
     }
 }
Exemple #3
0
 /**
  * @param array $credentials
  * @return UserTable|Nette\Security\IIdentity
  * @throws \Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $query = $this->userRepository->createQuery();
     $query->where('@login', $username);
     try {
         $user = $this->userRepository->findOneBy($query);
     } catch (NotFoundException $e) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     }
     if (!$user->isPasswordValid($password)) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     }
     return $user;
 }
Exemple #4
0
 /**
  * @return array
  */
 public function getUserByUsername($username)
 {
     return $this->repository->findOneBy(array('username' => $username));
 }