/** * Set authentication result. */ public function setResult(Result $result) { if (!$result->isValid()) { switch ($result->getCode()) { case Result::FAILURE_IDENTITY_NOT_FOUND: $this->setMessages(['login' => [$this->translate->translate('This user could not be found.')]]); break; case Result::FAILURE_CREDENTIAL_INVALID: $this->setMessages(['password' => [$this->translate->translate('Wrong password provided.')]]); break; } } }
public function __construct($authenticationService, $code, $identity, array $messages = array()) { parent::__construct($code, $identity, $messages); $this->setAuthenticationService($authenticationService); }
/** * Performs an authentication attempt * * @return \Zend\Authentication\Result * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface If authentication cannot be performed */ public function authenticate() { $qb = $this->db->createQueryBuilder(); if (strpos($this->options['credential_treatment'], '?') === false) { $this->options['credential_treatment'] = '?'; } $expression = '(CASE WHEN ? = ' . $this->options['credential_treatment'] . ' THEN 1 ELSE 0 END) AS ?'; $qb->createPositionalParameter($this->options['credential_column']); $qb->createPositionalParameter($this->credential); $qb->createPositionalParameter('zend_auth_credential_match'); $qb->select(['*', $expression])->from($this->options['table_name'])->where($this->options['identity_column'] . ' = ' . $qb->createPositionalParameter($this->identity)); //TODO check fetch type $resultIdentities = $qb->execute()->fetchAll(); if (count($resultIdentities) < 1) { return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, $this->identity, ['A record with the supplied identity could not be found.']); } else { if (count($resultIdentities) > 1) { return new Result(Result::FAILURE_IDENTITY_AMBIGUOUS, $this->identity, ['More than one record matches the supplied identity.']); } } $authResult = new Result(Result::FAILURE, $this->identity); foreach ($resultIdentities as $resultIdentity) { if ((int) $resultIdentity['zend_auth_credential_match'] !== 1) { $authResult = new Result(Result::FAILURE_CREDENTIAL_INVALID, $this->identity, ['Supplied credential is invalid.']); } else { unset($resultIdentity['zend_auth_credential_match']); $this->resultRow = $resultIdentity; $authResult = new Result(Result::SUCCESS, $this->identity, ['Authentication successful.']); } if ($authResult->isValid()) { break; } } return $authResult; }
/** * * @param Result $result * @param string $type */ private function queueAuthenticationResultMessages(Result $result, $type = 'error') { /* /* * add authentication service messages to flash messenger plugin */ foreach ($result->getMessages() as $message) { $this->queueMessage($message, $type); } }
/** * Sets the result code, identity, and failure messages * * @param int $code * @param mixed $identity * @param array $messages * @param string|null $resultBody */ public function __construct($code, $identity, array $messages = array(), $resultBody = null) { parent::__construct($code, $identity, $messages); $this->resultBody = $resultBody; }