I'm using CakePHP 2.4 Auth and if I try to access a link that needs to login it redirects to the login form. For example:
I try to access: / projects / edit / 34 without being logged in. Then CakePHP redirects to / login. After informing the user and password and authenticating CakePHP itself it redirects me to / projects / edit / 34. Okay, so that's alright, but it happens that when I access the homepage of my project and click on the login link (going to / login from the /) and authentic it redirects me to the previous page, in the case the initial one of my project.
I would like this case to be redirected to / panel
How to disable this auto redirection in CakePHP only for specific actions?
Follow my AppController.php
class AppController extends Controller {
public $components = array(
'DebugKit.Toolbar',
'Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array('username' => 'usuario', 'password' => 'senha'),
'scope' => array('User.status' => 1)
)
),
'authorize' => 'Controller',
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'loginRedirect' => array('controller' => 'users', 'action' => 'painel'),
'logoutRedirect' => array('controller' => 'home', 'action' => 'index'),
'authError' => 'Você não tem permissão para acessar.'
)
);
public function isAuthorized($user){
return true;
}
public $helpers = array('Html', 'Form', 'Session');
}
Two cases:
First:
- User attempts to directly access the / projects / edit / 34 link without logging in.
- CakePHP Auth does not allow access and redirects to / login
- After login Auth redirects to / projects / edit / 34
In the first case it is ok, understood and working as it should. Now in the second case:
- User enters the homepage of the site /
- User clicks the "Login" menu and goes to the login form in / login
- User logs in and is redirected to the home page /
In this second case, I would not want it to go to the home page but rather to what is set up in loginRedirect in the case for / panel