I created a simple website and added authentication using the ACL guides found here . I think I followed this letter.
I have a question:
After logging in, if I try to access a valid URL, the route folder will be added again. e.g. Access:
projectpath/controllerpath/action
redirected to
projectpath/projectpath/controllerpath/action
Those things that I noticed:
- This only happens if the user is logged in. If they are not logged in, they are redirected correctly to the login page.
- Only on pages that have controllers does this happen. If I put the wrong page, it throws a Missing Controller Exception.
- , , . , .
Edit:
CakePHP 2.5.3. , . - .
, ?
Edit:
. ACL Auth.
, , , URL-.
AuthComponent::$unauthorizedRedirect . URL- AuthComponent:: $loginAction '/. false, ForbiddenException .
App Controller
public $components = array(
'DebugKit.Toolbar',
'Auth' => array(
'redirectUrl' => array(
'controller' => 'pages',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'user',
'action' => 'login',
'home'
),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish'
)
),
'unauthorizedRedirect'=> false,
'Session',
'authorize' => array('Controller')
)
);
( ). - , ?
Edit
beforeFilter App Controller
public function beforeFilter() {
$this->Auth->allow('display');
/*if($this->Auth->user('role') == 'apa'){
$this->Auth->redirectUrl = "/apa";
}else{
$this->Auth->redirectUrl = "/test";
}*/ //Moved logic to UserController
parent::beforeFilter();
}
UserController
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
if($this->Auth->user('role') == 'apa'){
$this->Auth->redirectUrl = "/apa";
}else{
$this->Auth->redirectUrl = "/test";
}
return $this->redirect($this->Auth->redirectUrl);
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}