first to say I checked also into this answer and this other answer but it seems that doesn't solve the problem.
Expected result: after a successful login, redirect to "/admin/dashboard/index"
Actual result: after a successful login the application redirects to "/users/login". Login is done right, I can see it in the session. Also, when manually navigating to "/admin/dashboard" in the browser it redirects to "/admin" then following the rule defined in Config/routes.php it goes in infinite redirect loop
Here the relevant code:
in Config/core.php
Configure::write( 'Routing.prefixes', array( 'admin' ) );
in Config/routes.php
Router::connect( '/admin', array( 'controller' => 'dashboard', 'action' => 'index', 'admin' => true ) );
This is in my login action in UsersController
if ( $this->request->is( 'post' ) ) {
if ( $this->Auth->login() ) {
$this->redirect( $this->Auth->redirectUrl() );
} else {
$this->BASession->err( __( 'Login error. Please check your data!' ) );
}
}
And, finally, this is my Auth configuration
$this->Auth->loginAction = array( 'controller' => 'users', 'action' => 'login', 'admin' => false );
$this->Auth->logoutRedirect = array( 'controller' => 'users', 'action' => 'login', 'admin' => false );
$this->Auth->loginRedirect = array( 'controller' => 'dashboard', 'action' => 'index', 'admin' => true );
$this->Auth->autoRedirect = true;
Relevant to say that changing with
$this->Auth->autoRedirect = false;
Does not makes any difference.
A DashboardController class with an empty "admin_index" function exists, even a blank view.
In the login function, debugging "$this->Auth->redirectUrl()" displays "/admin"
PHP version 5.4.10 - cakePHP version 2.5.1
I hope I have given sufficient information, if not, ask for them.
thank you!
public $components = array('Auth' => array('loginAction' => array('controller' => 'users', 'action' => 'login', 'plugin' => false),'loginRedirect' => array('controller' => 'dashboard', 'action' => 'index', 'prefix' => 'admin'), 'authError' => 'You shall not pass'));Sorry, i'm not good with the stack markdonw formatting - hidewak"$this->Auth->redirectUrl()" displays "/admin"This was the hint that authentication and routing was working fine. So the next logical problem was authorization :) If authorization fails a message is set in session. Using DebugKit you can easily check the session values. Plus if you are authenticated$this->Auth->user()would return the user record irrespective of authorization info. - ADmadisAuthorized()should be in AppController not a specific controller. - ADmad