2
votes

I am using Cakephp 2.0 and Auth Component. My website consists of 2 user roles as follows

1. Admin
2. User

At a Time in a Browser either Admin or User can login to the website using Auth Component. it's not possible to handle Both User roles can log into the website at the same time in same browser. Is there any way to do it CAKEPHP. Now My client wants to login as Admin and User in same browser. But in Joomla and other frameworks has this feature. extremely sorry for this basic question

1
Good Question Never thought of this kind of things. Seems to be possible But need to work around the Auth Components Creating sessions and checking session. This will add more complexity while working with ACL along with Auth. Definitely worth of giving a try. - Vins
Can use multiple browsers... Will be simplest ;-) - Vins
Multiple browser common @Vins - AnNaMaLaI

1 Answers

2
votes

Depends on how your roles are defined and how your admin section is built. If you done it with proper prefix routing (/admin/:controller/:action/) then it is easy.

In you AppController::isAuthorized() just add a check like

if ($this->Auth->user('is_admin') == 1 && $this->request->params['prefix'] == 'admin') {
return true;
}

If you have an array of rules use in_array() to check for the allowed roles.

For more details read this link.