I want to make an aplication where users can login normally and back-end where admins can login.
So far I created this:
routes.php
$prefix = 'admin';
Router::connect(
"/{$prefix}/:plugin/:controller",
array('action' => 'index', 'prefix' => $prefix, $prefix => true)
);
Router::connect(
"/{$prefix}/:plugin/:controller/:action/*",
array('prefix' => $prefix, $prefix => true)
);
Router::connect(
"/{$prefix}/:controller",
array('action' => 'index', 'prefix' => $prefix, $prefix => true)
);
Router::connect(
"/{$prefix}/:controller/:action/*",
array('prefix' => $prefix, $prefix => true)
);
AppController:
public $components = array(
'DebugKit.Toolbar',
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'pages',
'action' => 'display'
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'display',
'home'
),
'authorize' => 'Controller',
'authError' => 'Access denied! Did you really think that you can access that?'
)
);
public function isAuthorized($user) {
// Admin can access every action
if (isset($user['role']) && $user['role'] === 'admin') {
return true;
}
// Default deny
return false;
}
public function beforeFilter() {
$this->Auth->allow('display');
//$this->recordActivity();
if($this->request->prefix == 'admin'){
$this->layout = 'admin';
}
}
With this when I try to access pages on front-end that needs auth it gives me login() action but when a try to access /admin it redirects me to /users/login.
I want to have two separate login systems with diferrent layouts. One for normal users and one for admin users.
Can anybody help please?