0
votes

I have a problem here. I created a cakePHP application using the Bake feature of cakePHP. I baked my Model, my Controller and my views (with default index, add, edit, and view actions). I created a small table called users in my database which contains only three fields (id int auto_increment primary key, username varchar(15), password charr(40)). The problem that I'm having is that when I use the Auth component, I get stuck on the logging page forever (until I take it out). I have tried almost EVERYTHING in my functions login() and beforeFilter() with no success. Any idea please?

I use the Auth component like so in my Users Controller:

var $components = array('Auth');

I have tried this in my function beforeFilter(), but it does not work:

function beforeFilter() {
    $this->Auth->autoRedirect = false;
    parent::beforeFilter();
}

I have even tried to redirect right in my function login() like so:

function login() {
    $this->redirect($this->Auth->redirect());
}

But when I do this I get error 310: TOO MANY REDIRECTS.

I cannot go to my index, or add, or view page. Help please?

2

2 Answers

2
votes

In the code you provided, you don't seem to do anything to make the 'login' action reachable if you are not logged in yet.

function beforeFilter()
{
    parent :: beforeFilter();

    $this->Auth->allow('login');
}

If you don't do that, the login page is protected, making you redirected to... the login page, making you redirected to... the login page, making you redirected to... the login page, making you redirected to... the login page ;-)

0
votes

This piece of code has you caught in an endless loop, because it keeps redirecting you back to the login page:

function login() {
    $this->redirect($this->Auth->redirect());
}

Read up here on list of Auth component variables. Specifically the loginRedirect part. You need to put that in into your beforeFilter function:

function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'index');
}