0
votes

I am using ACL in my application. I have definned my loginAction in the beforeFilter in my AppController and still its not redirecting to the correct place. What i would like to do is when a users access the app like this - localhost/intraweb it must redirect then to localhost/intraweb/users/login

here is my AppController code

class AppController extends Controller {

public $helpers = array('Html', 'Form', 'CustomFields.Field');

public $components = array(
'CustomFields.Field',
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session',
'Cookie',
);

public $uses = array('User');

public function beforeFilter() {       

//Configure AuthComponent
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->allow('display');

//OTHER CODE

}

and here is my PagesController code

class PagesController extends AppController {

public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
}

//Other code

Does anyone have an idea why its not redirecting to the users/login page?

Thank you in advance

1

1 Answers

0
votes

The loginRedirect means action to call when Auth Session is not found. In simple terms a login page. The actions that are allowed to pass without Authentication being required will never redirect to loginRedirect.

When you access the localhost/intraweb, Cake will render Pages/display and since you have $this->Auth->allow('display'); in your code. The Auth will let it render without redirection to the loginRedirect.

Update:

Redeclaring beforeFilter() in other controllers over-rides all the declaration in AppController. So, if the declarations from the beforeFilter() in AppController are to be inherited,

public function beforeFilter() {
    parent::beforeFilter(); // inherit beforeFilter() from AppController
    // your controller specific declarations
}