8
I’m using Cakephp’s Auth 2.4 and if I try to access a link that needs login it redirects to the login form. For example:
I try to access: /projects/Edit/34 without being logged in. Cakephp then redirects to /login. After informing the user and password and authenticating Cakephp itself redirects me to /projects/Edit/34. Ok, so far so good, but it turns out that when I access the home page of my project and click on the login link (going to /login from the /) and authenticity it redirects me to the previous page, in case the initial of my project.
I would like in this case to be redirected to /panel
How to disable this auto redirect 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 tries to directly access the link /projects/Edit/34 without logging in.
- Cakephp Auth does not allow accessing and redirecting to /login
- After user log in 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 on the "Login" menu and goes to the login/login form
- User logs in and is redirected to the home page /
In this second case, I would not like it to go to the home page but to what is configured in loginRedirect in the case for /panel
You can post the code of how you set up the Auth component?
– bfavaretto
Appcontroller.php added
– rodrigoum
Good that you solved it! Could you edit the question by removing the solution, and posting that part as an answer? It is best suited to the site proposal. And you can/should accept the response itself in this case. Thank you!
– bfavaretto
Oh yes, I was wondering if it was to edit or add new answer. I will edit.
– rodrigoum