I'm trying to get a simple login form to work using CakePHP 2.0...
just Auth, no ACLs for now.

I'm able to see the form and enter the email and password as they are
in the database, but I just get returned to the form and the flash
error message is displayed. Here is my code:

**AppController:**
    class AppController extends Controller
    {
        function beforeFilter()
        {
            $this->Auth->userModel = 'Users';
            $this->Auth->fields = array('username' => 'email',
'password' => 'password'); //have to put both, even if we're just
changing one
            $this->Auth->loginAction = array('controller' => 'users',
'action' => 'login');
            $this->Auth->loginRedirect = array('controller' =>
'hotels', 'action' => 'dashboard');
            $this->Auth->logoutRedirect = array('controller' =>
'users', 'action' => 'login');
        }
    }

**login.ctp:**
    <?php
        echo $this->Form->create(); //'User', array('action' =>
'login'));
        echo $this->Form->input('email');
        echo $this->Form->input('password');
        echo $this->Form->end('Login');
    ?>

**UsersController:**
    <?php

    class UsersController extends AppController
    {
        var $name = 'Users';
        var $helpers = array('Html','Form');
        var $components = array('Auth','Session');

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

        function index() { } //Redirects to login()

        function login()
        {
            if ($this->Auth->login())
            {
                $this->redirect($this->Auth->redirect());
            } else
            {
                $this->Session->setFlash(__('Invalid username or
password, try again'));
            }
        }

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

I appreciate any help with this. Thanks!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to