Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 2 Doctrine ORM Authentication

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');
like image 937
user3108205 Avatar asked Jun 25 '26 11:06

user3108205


1 Answers

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'
like image 154
lku Avatar answered Jun 27 '26 11:06

lku



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!