public function __invoke(AuthenticationEvent $e) { $result = $e->getResult(); if ($result->isValid()) { $this->sessionManager->writeClose(); } }
/** * 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(); } }
/** * @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(); } }
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; }
/** * 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(); }
/** * 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(); } }); }