Ok, got it to work! I guess its a combination of all these
suggestions, but it finally did login when I commented the following:
$this->Auth->userModel = 'Users';
// $this->Auth->fields = array('username' => 'email', 'password' =>
'password'); <-- commented out
$this->Auth->loginAction = array('controller' => 'users', 'action' =>
'login');
$this->Auth->loginRedirect = array('controller' => 'hotels', 'action'
=> 'dashboard');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action'
=> 'login');
I added this to my code, as I explained before:
var $components = array('Session',
'Auth'=> array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' =>
'email')
)
)
)
);
Thanks John and Andras for your help! Really appreciated!
On Nov 7, 7:29 pm, Sandy Wilkins <[email protected]> wrote:
> I commented out all the code in the login method, and when I submit
> the form I see no sql queries in the bottom of the layout. I'm just
> sent back to the same login form, no info below.
>
> On Nov 6, 9:52 am, Andras Kende <[email protected]> wrote:
>
>
>
>
>
>
>
> > The code looks good, You could comment out the
> > $this->redirect($this->Auth->redirect()); from login method
> > and check the sql dump to see if the mysql query is correct …
>
> > Andras Kende
>
> > On Nov 5, 2011, at 9:01 PM, Sandy Wilkins wrote:
>
> > > 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
> > > Tutorialshttp://tv.cakephp.org
> > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > > others with their CakePHP related questions.
>
> > > To unsubscribe from this group, send email to
> > > [email protected] For more options, visit this group
> > > athttp://groups.google.com/group/cake-php
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php