Exemplo n.º 1
0
 /**
  * Performs an authentication attempt
  *
  * @return \Zend\Authentication\Result
  * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface If authentication cannot be performed
  */
 public function authenticate()
 {
     try {
         /** @var UserEntity $user */
         $user = $this->userRepository->findOneBy(['login' => $this->getIdentity()]);
     } catch (EntityNotFoundException $e) {
         return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, null);
     } catch (NonUniqueResultException $e) {
         return new Result(Result::FAILURE_IDENTITY_AMBIGUOUS, null);
     }
     if ($user && $this->crypt->verify($this->getCredential(), $user->getPassword())) {
         return new Result(Result::SUCCESS, $user->getId());
     }
     return new Result(Result::FAILURE_CREDENTIAL_INVALID, null);
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function read()
 {
     if (null !== $this->resolvedIdentity) {
         return $this->resolvedIdentity;
     }
     $identity = $this->getStorage()->read();
     if (is_int($identity) || is_scalar($identity)) {
         $identity = $this->userRepository->find($identity);
     }
     if ($identity) {
         $this->resolvedIdentity = $identity;
     } else {
         $this->resolvedIdentity = null;
     }
     return $this->resolvedIdentity;
 }