CakePHP Auth Component Check User Before Login

Atul Dravid picture Atul Dravid · Aug 25, 2010 · Viewed 7.1k times · Source

I want to prevent banned users from logging in to the site and give them a message that they are banned. I tried to use isAuthorized() for this but it allows the user to login and only after that denies him permission to the unauthorized actions.

So, basically I want to know where to put the condition that would check if the user table as banned = true, before the login process takes place. Right now my login function is empty as its being automatically controlled by the Auth Component.

Answer

Atul Dravid picture Atul Dravid · Aug 26, 2010

Finally, I found a solution by going through the API. I wonder if anyone has used this ever, cause nobody pointed me to this, or maybe I wasn't clear enough. Anyways, to add a condition to the login process you just have put it in the variable $this->Auth->userScope

So, to check if a user is banned I just added this line to the beforeFilter() in my AppController,

$this->Auth->userScope = array('User.banned'=>0);

Hope this helps someone.