zend-frameworkdoctrine-ormdoctrinezend-framework2zend-auth

Zf2 + Doctrine 2 Authentication Adapter with Multiple or Alternate Columns


I am working on a site in which user can enter two email address(primary and secondary) along with password.

If user enters his primary email and password, he gets logged in successfully.

But, what I am trying to provide is if user enters his secondary email instead of primary, even then he gets logged in. And the problem I am getting is how to create an alternate Doctrine Auth Adapter or something like that.

this is what I have done in my module.config.php:

'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
        ),
        'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            )
        )
    ),
    'authentication' => array(
        'orm_default' => array(
            'object_manager' => 'Doctrine\ORM\EntityManager',
            'identity_class' => 'User\Entity\LoginDetails',
            'identity_property' => 'primary_email',
            'credential_property' => 'password',
        ),
    ),
)

Is there any option to add an identity property which will be alternative ?

I am using Zend framework 2 and Doctrine 2

Solution

  • Is there any option to add an identity property which will be alternative ?

    No, there is no such option built-in to DoctrineModule.

    Consider extending DoctrineModule\Authentication\Adapter\ObjectRepository to override the authenticate() method.

    Then, at minimum, you'll want to replace the default adapter with your new more different one. If you look at the various factories in DoctrineModule, you should be off to a good start.

    Basically, one of your modules will want to override the doctrine.authenticationadapter.[orm|odm]_default configuration key in the ServiceManager. That will cause DoctrineModule to inject your extended ObjectRepository into the AuthenticationService in place of you the default one.