Cakephp user login conditions

I would like to check if the user account is activated when logging in, but the Torhe Autake component takes care of logging in, since I do not know how to manage it. The cake basically uses an empty login function, and I have no idea how to check the value of User.active.

Thanks in advance

+6
php login cakephp
source share
2 answers

AuthComponent has a property for setting additional conditions in the same way as it is called $ userScope.

Just include this line in the preFilter () Auth settings block:

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

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

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

Then you can leave your login blank, and AuthComponent will add this additional condition when authenticating the visitor.

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

If you do not include this additional area, then inactive users will still be able to log in, and after checking you will have to display them in your login () method.

+11
source share

In your user controller or where you want to place it (action to which the login form is attached):

 function login() { if ($this->Session->read('Auth.User')) { $active = $this->Auth->user('active'); if ($active) { //(do stuff) } else { //(do other stuff) } } } 

This assumes that your user table has an β€œactive” column containing either true or false (or 1 or 0). $ this-> Auth-> user () allows you to access the current user input. More information here: http://book.cakephp.org/view/1264/user

0
source share

All Articles