Exemplo n.º 1
0
 /**
  * Performs an authentication against e.g. database.
  * and returns IIdentity on success or throws AuthenticationException
  * @return IIdentity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $row = $this->userService->getByEmail($email);
     if (!$row) {
         throw new AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $row->password)) {
         throw new AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($row->password)) {
         $this->userService->edit(['password' => Passwords::hash($password)], ['email' => $email]);
     }
     $row->password = null;
     $this->onSignIn($row->email);
     return new Identity($row->idUser, null, []);
     //TODO: přenášet informace o uživateli?
 }