I have 2 admin roles (super, admin), at first login, everything works fine but after logout and login as a different admin, it redirect be to the super prefix.
Here is my app controller:
class AppController extends Controller {
public $helpers = array('Js', 'Session');
public $components = array(
'Session',
'RequestHandler',
'DebugKit.Toolbar',
'Auth' => array(
'autoRedirect' => false,
'loginAction' => array(
'admin' => false,
'super' => false,
'controller' => 'users',
'action' => 'login'
),
'loginRedirect' => array(
'controller' => 'users',
'action' => 'dashboard',
'admin'=> true,
'super'=> true
),
'logoutRedirect' => array(
'admin' => false,
'super' => false,
'controller' => 'users',
'action' => 'login'
),
'authError' => 'Please login to continue.',
'flash' => array('element' => 'flash/default', 'key' => 'auth', 'params' => array('class' => 'error', 'title' => 'Authentication Error')),
'authorize' => 'Controller',
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array(
'username' => 'email'
),
)
),
)
);
public function isAuthorized($user) {
# Accept if Admin
if($user['admin']){
return true;
}
# Check if current prefix is admin or physician and authenticate user
if(isset($this->request->prefix)) {
switch ($this->request->prefix) {
case 'super':
if(!$user['super']){
$this->Auth->authError = 'Sorry, you do not have permission to access the Manager\'s area';
}
return $user['super'];
break;
case 'admin':
if(!$user['admin']){
$this->Auth->authError = 'Sorry, you do not have permission to access the Administrators\'s area';
}else{
$this->layout = 'admin_layout';
}
return $user['admin'];
break;
}
}else{
$this->layout = 'super_layout';
return true;
}
$this->Auth->authError = 'Sorry, you do not have permission to access the Admin area';
return false;
}
public function beforefilter(){
$this->appSettings = Configure::read('appSettings');
$this->set('appSettings', Configure::read('appSettings'));
if (!$this->Auth->loggedIn()) {
$this->Auth->authError = false;
}
if(isset($this->request->prefix)) {
switch ($this->request->prefix) {
case 'admin':
$this->layout = 'admin_layout';
$admin = true;
break;
case 'super':
$this->layout = 'super_layout';
$super = true;
break;
}
}
}