2013-04-15 32 views
0

我有一個Zend 2安裝與Doctrine 2作爲我的ORM。Zend 2認證與Doctrine 2檢查是否登錄

目前我嘗試使用doctrine2實現身份驗證。

This Works。

但現在我想檢查layout.phtml如果用戶登錄或不。

我不知道如何從layout.phtml 訪問authentifcation服務在此頁面(https://github.com/doctrine/DoctrineModule/blob/master/docs/authentication.md)他們說 $這個 - >身份()

但這並沒有工作。它每次返回NULL。

module.config.php

'authentication' => array(
      'orm_default' => array(
       'object_manager' => 'Doctrine\ORM\EntityManager', 
       'identity_class' => 'Application\Model\User', 
       'identity_property' => 'id', 
       'credential_property' => 'password' 
      ), 
     ), 

Module.php

public function getServiceConfig() 
{ 
    return array(
     'factories'=>array(
      'Application\Model\AuthStorage' => function($sm){ 
       return new \Application\Model\AuthStorage('site'); 
      }, 

      'Zend\Authentication\AuthenticationService' => function($serviceManager) { 
       return $serviceManager->get('doctrine.authenticationservice.orm_default'); 
      }, 
     ), 
    ); 
} 

回答

0

如果您使用MD5加密密碼,請嘗試更改orm_default到:

'orm_default' => array(
    'object_manager' => 'Doctrine\ORM\EntityManager', 
    'identity_class' => 'Application\Entity\User', 
    'identity_property' => 'username', 
    'credential_property' => 'password', 
    'credentialCallable' => function ($userObj, $password) { 
     return ($userObj->getPassword() === md5($password)); 
    } 
), 

如果你不使用md5進行加密,你可以根據你的使用情況進行調整。