Search code examples
phpauthenticationzend-frameworkzend-framework2

zend framework 2 : Set session authentification timeout


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.


Solution

  • 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 !