3
votes

I'm developing my first real project with ZF2 and Doctrine ORM. And I cannot find any good example of user authentication through doctrine orm authentication adapter. Now I'm using standard Zend Db Adapter authentication. In addition, I use

$adapter->setIdentityColumn(filter_var($request->getPost('useremail'),FILTER_VALIDATE_EMAIL) ? 'useremail' : 'userlogin');

in my login controller to login either via email and login.

But I want to perform all job through doctrine ORM. Could someone show me a similar example with doctrine.authentication.orm_default and storing user identity data in session/storage to access in any controller or module.php? Is it possible to use two fields - userlogin or email for login?

Thank you in advance for your help.

Updated: I kept seaching and as a result this and this helped me so much One problem, that i haven't solved yet. How can I check user status (activated or not) with doctrine adapter? Like

$authAdapter = new AuthAdapter($dbAdapter,'user','username','password','MD5(?) AND status = 1');
2
Did you ever find a solution to your question?David

2 Answers

3
votes

You can use credential_callable option (Doctrine Module doc.). It can be any callable (PHP Manual), for example with closure:

'credential_callable' => function(User $user, $passwordGiven) {
    return md5($passwordGiven) == $user->getPassword() && $user->isActive();
},

or with static class method:

'credential_callable' => 'Application\User\UserService::verifyUser'
0
votes

What about an external module idea? If you are OK with that you can take a look at https://github.com/ZF-Commons/ZfcUser and https://github.com/SocalNick/ScnSocialAuth or the whole modules repositories http://modules.zendframework.com/?query=user. Even if you don't install just download and see what other people do stuff.