示例#1
0
 /**
  * Set an event to use during dispatch
  *
  * By default, will re-cast to AdapterChainEvent if another event type is provided.
  *
  * @param  Event $e
  * @return AdapterChain
  */
 public function setEvent(Event $e)
 {
     if ($e instanceof Event && !$e instanceof AdapterChainEvent) {
         $eventParams = $e->getParams();
         $e = new AdapterChainEvent();
         $e->setParams($eventParams);
         unset($eventParams);
     }
     $this->event = $e;
     return $this;
 }
示例#2
0
文件: Db.php 项目: czester90/gowithme
 public function authenticate(AuthEvent $e)
 {
     if ($this->isSatisfied()) {
         $storage = $this->getStorage()->read();
         $e->setIdentity($storage['identity'])->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
         return;
     }
     $identity = $e->getRequest()->getPost()->get('identity');
     $credential = $e->getRequest()->getPost()->get('credential');
     $remember = $e->getRequest()->getPost()->get('remember');
     $credential = $this->preProcessCredential($credential);
     $userObject = NULL;
     // Cycle through the configured identity sources and test each
     $fields = $this->getOptions()->getAuthIdentityFields();
     while (!is_object($userObject) && count($fields) > 0) {
         $mode = array_shift($fields);
         switch ($mode) {
             case 'username':
                 $userObject = $this->getMapper()->findByUsername($identity);
                 var_dump($userObject);
                 break;
             case 'email':
                 $userObject = $this->getMapper()->findByEmail($identity);
                 var_dump($userObject);
                 break;
         }
     }
     if (!$userObject) {
         $e->setCode(AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND)->setMessages(array('A record with the supplied identity could not be found.'));
         $this->setSatisfied(false);
         return false;
     }
     if ($this->getOptions()->getEnableUserState()) {
         // Don't allow user to login if state is not in allowed list
         if (!in_array($userObject->getState(), $this->getOptions()->getAllowedLoginStates())) {
             $e->setCode(AuthenticationResult::FAILURE_UNCATEGORIZED)->setMessages(array('A record with the supplied identity is not active.'));
             $this->setSatisfied(false);
             return false;
         }
     }
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($this->getOptions()->getPasswordCost());
     var_dump($credential, $userObject->getPassword());
     exit;
     if (!$bcrypt->verify($credential, $userObject->getPassword())) {
         // Password does not match
         $e->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)->setMessages(array('Supplied credential is invalid.'));
         $this->setSatisfied(false);
         return false;
     }
     // Success!
     $e->setIdentity($userObject->getId());
     // Update user's password hash if the cost parameter has changed
     $this->updateUserPasswordHash($userObject, $credential, $bcrypt);
     $this->setSatisfied(true);
     // One Yeah session 31536000 seconds
     if ($remember == 1) {
         $this->getServiceManager()->get('user_remember')->setRememberMe(1);
     }
     $this->setStorage($this->getServiceManager()->get('user_remember'));
     $storage = $this->getStorage()->read();
     $storage['identity'] = $e->getIdentity();
     $this->getStorage()->write($storage);
     $time = 1209600;
     $sessionManager = new \Zend\Session\SessionManager();
     $sessionManager->rememberMe($time);
     $e->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
 }