0
votes

I have a Zend 2 installation with Doctrine 2 as my ORM.

At the moment I try to implement a authentication with doctrine2.

This works.

But now I want to check in the layout.phtml if the user is logged in or not.

I don't know how to access the authentifcation service from the layout.phtml On this page (https://github.com/doctrine/DoctrineModule/blob/master/docs/authentication.md) they say $this->identity()

But this didn't work. It returns every time 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');
            },
        ),
    );
}
1
do you get PHPSESSID twice in response after authentication?Łukasz Gawron

1 Answers

0
votes

If you're using md5 to encrypt your password, try to change your orm_default to:

'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));
     }
),

If you're not encrypting with md5, you can adapt this to what you are using.