Пример #1
0
 public function __invoke(AuthenticationEvent $e)
 {
     $result = $e->getResult();
     if ($result->isValid()) {
         $this->sessionManager->writeClose();
     }
 }
Пример #2
0
 /**
  * Disable session writes after this point in time.
  *
  * @return void
  */
 public function disableWrite()
 {
     // Set the flag
     $this->disableWrite = true;
     // If the session manager is already instantiated, close it!
     if (null !== $this->manager) {
         $this->manager->writeClose();
     }
 }
Пример #3
0
 /**
  * @param AuthenticationEvent $e
  */
 public function authListener(AuthenticationEvent $e)
 {
     $result = $e->getResult();
     if ($result->isValid()) {
         if ($this->rememberMe) {
             $this->sessionManager->rememberMe();
         } else {
             $this->sessionManager->forgetMe();
         }
         $this->sessionManager->writeClose();
     }
 }
Пример #4
0
 protected function userAuthentication($data)
 {
     $auth = $this->authService;
     $adapter = $auth->getAdapter();
     $adapter->setIdentityValue($data['username']);
     $adapter->setCredentialValue($data['password']);
     $authResult = $auth->authenticate();
     if ($authResult->isValid()) {
         $identity = $authResult->getIdentity();
         $auth->getStorage()->write($identity);
         $sessionManager = new SessionManager();
         if ($data['rememberme']) {
             $sessionManager->rememberMe();
         }
         // store user roles in a session container
         $userContainer = new Container('User');
         $userContainer->offsetSet('id', $identity->getUserId());
         $userRoles = $identity->getRole()->toArray();
         $roleNames = array();
         foreach ($userRoles as $userRole) {
             $roleNames[] = $userRole->getRoleName();
         }
         $userContainer->offsetSet('activeRole', $roleNames[0]);
         $userContainer->offsetSet('allRoles', $roleNames);
         $sessionManager->writeClose();
         return true;
     }
     return false;
 }
Пример #5
0
 /**
  * Write session to save handler and close
  *
  * Once done, the Storage object will be marked as isImmutable.
  *
  * @return void
  */
 public function writeClose()
 {
     // Skip storage writing if validation is failed
     if (!$this->isValid()) {
         //$this->destroy();
         return;
     }
     // Set metadata for validators
     $storage = $this->getStorage();
     if (!$storage->isImmutable() && $this->validators) {
         $storage->setMetaData('_VALID', $this->validators);
     }
     parent::writeClose();
 }
Пример #6
0
 /**
  * According to the PHP manual, session_write_close should always be
  * registered as a shutdown function when using an object as a session
  * handler: http://us.php.net/manual/en/function.session-set-save-handler.php
  *
  * This method sets that up.
  *
  * @param SessionManager $sessionManager Session manager instance
  *
  * @return void
  */
 protected function registerShutdownFunction(SessionManager $sessionManager)
 {
     register_shutdown_function(function () use($sessionManager) {
         // If storage is immutable, the session is already closed:
         if (!$sessionManager->getStorage()->isImmutable()) {
             $sessionManager->writeClose();
         }
     });
 }