public function onBootstrap(MvcEvent $e) {
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH, function($e) {
$controller = $e->getTarget();
$auth = new AuthenticationService();
$is_login = $auth->hasIdentity();
//check if action is login
$params = $e->getApplication()->getMvcEvent()->getRouteMatch()->getParams();
if ($params['action'] == 'login') {
if ($is_login) {
return $controller->redirect()->toRoute('adminindex');
}
} else {
if (!$is_login) {
return $controller->redirect()->toRoute('adminauthlogin');
}
}
});
}
a little bit better solution ;)