tags:

views:

28

answers:

2

I have an issue with cake's auth that I simply can't seem to get past (i've been debugging and trying different tutorials for the last two days). As far as I can see it should be very simple, the problem is whenever i try to login, it just refreshes the login page. I cannot for the life of me figure out why! My only conclusion is that there must be something (basic) which tutorials take for granted that I have missed.

Here are a couple of snippets:

users_controller.php

class UsersController extends AppController {

    var $name = 'Users';

    function beforeFiler() {
        parent::beforeFilter();
    }
    function login() {
    }

    function logout() {
        $this->Session->setFlash('You have successfully logged out.');
        $this->redirect($this->Auth->logout());
    }
}

app_controller.php

class AppController extends Controller {

    var $helpers = array('Html','Form','Javascript');
    var $components = array('Auth');

    function beforeFilter() {

        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'contents', 'action' => 'index');
        $this->Auth->logoutRedirect = array('controller' => 'contents', 'action' => 'view');
        $this->Auth->loginError = 'Something went wrong';
        $this->Auth->allow('register', 'view');
        $this->Auth->authorize = 'controller';
        $this->set('loggedIn', $this->Auth->user('id'));
    }

    function isAuthorized() {
        return true;
    }
}

login.ctp

<div class="midCol short">
    <h3>Login</h3>
    <div class="loginBox">
    <?php e($form->create('User', array('controller'=>'users','action'=>'login')));?>
        <?php
        echo $this->Form->input('username');
        echo $this->Form->input('password');
        e($this->Form->end(array('label'=>'Login', 'class'=>'loginButton button png')));?>
    </div>
</div>

Any help would be greatly appreciated, this has me tearing my hair out!

A: 

Thanks for the advice, but I ended up scrapping it and building again from scratch. Not exactly sure why it was originally breaking, probably not calling inbuilt functions with American English!

tiltos
A: 

The Auth component will redirect to the page before you logged in. If that page was the login page that's where it'll redirect to.

When you're testing, it's likely that you're refreshing the login page, so on successful login that's where you're redirected to. You can check this by trying to perform an Auth protected action after logging in.

This gives me a lot of headaches as well - I think the current functionality of the component is a little clumsy in that respect.

Leo