I am trying to implement the ACL tutorial found here:
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html
I followed all the instructions, however when I try to go to [my_site]/users/add ERR_TOO_MANY_REDIRECTS error.
I found this on the Cakephp website:
This happens when for example we have an element that receives data
from a method of a controller, and the implementation of this method
requires conducting the login would create an infinite loop that
eventually will cause the browser to decline redirects
And they suggest this as the fix:
function beforeFilter () {
$ this -> Auth -> allow ( 'CONTROLLER_NAME' );
}
Which doesn’t seem to work.
If I change the AppController from this:
public function beforeFilter() {
$this->Auth->allow('index', 'view', 'login', 'add');
}
to:
public function beforeFilter() {
$this->Auth->allow('*');
}
I dont get the error anymore but get redirected to [my_site]/users/login
Any suggestions as to what I am doing wrong that I can’t view the User-Add page?
TIA!
UserController:
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
Login function (UsersController):
Public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
Auth Component Loader:
public $components = array(
'Session',
'RequestHandler',
'Auth' => array(
'loginRedirect' => array('controller' => 'projects', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
)
);
I finally managed to solve the problem with help Brian: