doujin4031
2017-04-24 08:58
浏览 27
已采纳

zend框架2:设置会话认证超时

I have the problem that the authentification session doesn't expire , this is my code of authentification :

$adapter = $this->getServiceLocator()->get('doctrine.authenticationadapter.orm_default');
$adapter->setOptions(array(
    'objectManager' => $this->getEntityManager(),
    'identityClass' => 'Application\Entity\User',
    'identityProperty' => 'email',
    'credentialProperty' => 'password'));

$adapter->setIdentityValue($mail);
$adapter->setCredentialValue($password);
$authService = new AuthenticationService();
$result = $authService->authenticate($adapter);

if ($result->isValid()) 
{
    $identity = $result->getIdentity();
    $authService->getStorage()->write($identity);
    echo "valide"; 
}
else
    echo "invalide";

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我遇到的问题是验证会话没有过期,这是我的验证码:

  $ adapter = $ this-> getServiceLocator() - > get('doctrine.authenticationadapter.orm_default'); 
 $ adapter-> setOptions(array(
'objectManager)  '=> $ this-> getEntityManager(),
'identityClass'=>'Application \ Entity \ User',
'identityProperty'=>'email',
'credentialProperty'=>' 密码')); 
 
 $ adapter-> setIdentityValue($ mail); 
 $ adapter-> setCredentialValue($ password); 
 $ authService = new AuthenticationService(); 
 $ result = $ authService  - > authenticate($ adapter); 
 
if($ result-> isValid())
 {
 $ identity = $ result-> getIdentity(); 
 $ authService-> getStorage()  - >写($ identity); 
 echo“valide”;  
} 
else 
 echo“invalide”; 
   
 
 

谢谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douhu8851 2017-05-03 16:16
    已采纳

    Here is how i solved my problem :

    if ($result->isValid()) 
    {
         $session = new Container('Zend_Auth');
         $session->setExpirationSeconds(1800);
        $identity = $result->getIdentity();
        $authService->getStorage()->write($identity);
        echo "valide"; 
    }
    else
        echo "invalide";
    

    I get the Object session Zend_Auth , then i edited the value of expiration time. Hope it helps !

    打赏 评论
  • drbvm26000 2017-04-25 11:33

    You should see https://github.com/bjyoungblood/BjyAuthorize

    for identity provider. and then in config: configure the role_providers.

    打赏 评论

相关推荐 更多相似问题