Exemplo n.º 1
0
 /**
  * @param array $credentials
  * @return Identity|\Nette\Security\IIdentity
  * @throws \movi\InvalidStateException
  * @throws \Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     if ($this->users === NULL) {
         throw new InvalidStateException('Service IUsers is not registered.');
     }
     $user = $this->users->login($credentials);
     if (!$user) {
         throw new AuthenticationException(self::INVALID_CREDENTIAL);
     }
     $token = $this->users->generateToken($user);
     return new Identity($user->id, $user->role, $token);
 }