Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp custom login conditions

I would like to check, whether user's account is activated while loggin in, but cake's Auth component takes care of the login in a way I don't know how to control. Cake basically uses blank login function and I have no idea how to check value of User.active.

Thanks in advance

like image 373
Elwhis Avatar asked Dec 31 '10 14:12

Elwhis


1 Answers

The AuthComponent has a property for setting additional conditions just like this, called $userScope.

Just include this line in your beforeFilter() Auth setup block:

$this->Auth->userScope = array('User.active' => true);

Note: the above applies to Cake 1.x. For 2.x use:

$this->Auth->scope = array('User.active' =>true);

Then you can leave your login method blank and the AuthComponent will append this extra condition when authenticating the visitor.

You can see all the additional properties here: http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlers

If you don't include this extra scope, then inactive users will still be able to log in and you'd have to log them out in your login() method after checking.

like image 153
Jamie Avatar answered Sep 20 '22 01:09

Jamie