one more little improvement to make sure a users session and identity is
cleared if he is logged in and revisits the login page:
public function onBootstrap(\Zend\Mvc\MvcEvent $e) {
$app = $e->getParam('application');
$app->getEventManager()->attach('route', array($this,
'onRoute'));
$app->getEventManager()->attach('finish', array($this,
'onFinish'));
}
public function onRoute(\Zend\Mvc\MvcEvent $e){
$app = $e->getTarget();
$match = $app->getMvcEvent()->getRouteMatch();
$controller = $match->getParam('controller');
$action = $match->getParam('action');
$sm = $app->getServiceManager();
$userService = $sm->get('zfcuser_user_service');
$authService = $userService->getAuthService();
if($authService->hasIdentity() AND $controller == 'zfcuser' AND
($action
== 'login')){
$authService->clearIdentity();
}
}
public function onFinish(\Zend\Mvc\MvcEvent $e){
$app = $e->getTarget();
$match = $app->getMvcEvent()->getRouteMatch();
$controller = $match->getParam('controller');
$action = $match->getParam('action');
$sm = $app->getServiceManager();
$userService = $sm->get('zfcuser_user_service');
$authService = $userService->getAuthService();
if(!$authService->hasIdentity() AND $controller == 'zfcuser'
AND ($action
== 'login')){
$config = $sm->get('Config');
$session = new
\Zend\Session\Container($config['application']['sessionname']);
$session->getManager()->destroy();
}
}
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/ZF2-ZfcUser-Clear-Sessions-before-login-tp4657794p4657801.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]