Zend2, Zfcuser - automatic logout

柔情痞子 提交于 2019-12-25 10:57:08

问题


I'm working with Zend Framework 2, ZfcUser and BjyAuthorize. Logging in and access control works, but under certain circumstances users get logged out: When they try to navigate to a different page while an on the current page an AJAX call is still running.

In Chrome's Network window it shows the AJAX call as cancelled, followed by a call to the page you tried to navigate to, where the following code checks if you're logged in, finds that you're not ( $auth->hasIdentity() returns false ), and sends you to the login page.

$sm = $event->getApplication()->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');
$routeParams = $event->getRouteMatch()->getParams();

// List of action non-authenticated users may access
$whitelist = array('login' => 1, 'register' => 1, 'forgotPassword' => 1, 'resetPassword' => 1);

$hasIdentity = $auth->hasIdentity();

if (!$hasIdentity && !array_key_exists($routeParams['action'], $whitelist) ) {
    $targetUrl = $event->getRouter()->assemble(array(), array('name' => 'zfcuser/login', 'absolute' => true));
    $response = $event->getResponse();
    $response->getHeaders()->addHeaderLine('Location', $targetUrl);
    $response->setStatusCode(302);
    $response->sendHeaders();
}

Apparently the session just disappeared? I'm having some trouble figuring out how/where it is saved. ZfcUser\Authentication\Storage\Db is used, but that uses Storage\Session as storage, and right now I'm not sure anymore what class THAT is.

Anybody encountered something like that before, or has a suggestion where to check?

来源:https://stackoverflow.com/questions/18693960/zend2-zfcuser-automatic-logout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!