Пример #1
0
 public function login(InputFilterInterface $filter)
 {
     if (!$filter->isValid()) {
         throw new \LogicException('Form is not valid');
     }
     $this->authAdapter->setIdentity($filter->getValue('login'));
     $this->authAdapter->setCredential($filter->getValue('password'));
     $result = $this->authenticationService->authenticate($this->authAdapter);
     return $result->isValid();
 }
Пример #2
0
 /**
  * @return ViewModel
  */
 public function loginAction()
 {
     $prg = $this->prg('login', true);
     if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
         return $prg;
     } elseif ($prg === false) {
         return new ViewModel();
     }
     $username = $prg['username'];
     $password = $prg['pwd'];
     // instantiate the authentication service
     $auth = new AuthenticationService();
     // Set up the authentication adapter
     $this->authAdapter->setIdentity($username);
     $this->authAdapter->setCredential($password);
     // Attempt authentication, saving the result
     $result = $auth->authenticate($this->authAdapter);
     if ($result->isValid()) {
         $this->flashMessenger()->addSuccessMessage('Successful login');
     } else {
         $this->flashMessenger()->addErrorMessage('Invalid informations');
     }
     return $this->redirect()->toRoute('login');
 }
 /**
  * Sets the identity for binding
  *
  * @param  mixed $identity
  * @return AbstractAdapter
  * @throws Exception\RuntimeException
  */
 public function setIdentity($identity)
 {
     parent::setIdentity($identity);
     foreach ($this->adapters as $adapter) {
         if (!$adapter instanceof AbstractAdapter) {
             throw new Exception\RuntimeException('An adapter must extends AbstractAdapter to be chainable');
         }
         $adapter->setIdentity($identity);
     }
     return $this;
 }
 protected function doAuthentication()
 {
     $this->adapter->setIdentity($this->getIdentity());
     $this->adapter->setCredential($this->getCredential());
     return $this->adapter->authenticate();
 }