Example #1
0
 /**
  * @param string $email
  * @param string $password
  *
  * @return IIdentity
  *
  * @throws AuthenticationException
  */
 public function authenticateWithEmail($email, $password)
 {
     try {
         $user = $this->userRepository->findOneBy(['email' => $email]);
         return $this->authenticate(['authenticator' => self::AUTH_EMAIL, 'user' => $user, 'password' => $password]);
     } catch (IOException $e) {
         throw new AuthenticationException('User not found.');
     }
 }
Example #2
0
 /**
  * Performs an authentication.
  * @param array $credentials
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $row = $this->repository->findOneBy(["email" => $email]);
     if (!$row) {
         throw new Nette\Security\AuthenticationException('The email is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $row['password'])) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($row['password'])) {
         $row->update(array('password' => Passwords::hash($password)));
     }
     $arr = $row->toArray();
     unset($arr['password']);
     return new Nette\Security\Identity($row['id'], $row['role'], $arr);
 }