Thursday, July 26, 2012

Auth Function Issues

Hi All,

I am using some basic Auth code that I have used many times in the past but for some reason this time it is failing. I cannot work it out, there isn't much to the actual code so I cannot see why it would fail.

Can anyone see where I am going wrong? I am not getting any errors to the page when I try and login, when I echo  $this->Auth->login() it comes back as fail, I have tested the password hash and it matches that of the database.

Also this exact code is working on my local computer dev setup but as soon as it goes online it doesn't work.

Any ideas?

Thankyou


AppController.php
public $components = array(
   
'Auth'=> array(
       
'authenticate' => array(
           
'Form' => array(
               
'fields' => array('username' => 'email', 'password' => 'password')
           
)
       
)
   
),
   
'Session',
   
'Cookie',
   
'RequestHandler',
   
'Whmcs'
);  


login.ctp
<?php
    echo $this
->Session->flash('auth');
    echo $this
->Form->input('email', array(
                                           
'class' => 'span2',
                                           
//'div' => array('class' => 'control-group'),
                                           
'div' => false,
                                           
'label' => false,
                                           
'placeholder' => 'Email'
                                           
));
    echo $this
->Form->input('password', array(
                                           
'class' => 'span2',
                                           
//'div' => array('class' => 'control-group'),
                                           
'div' => false,
                                           
'label' => false,
                                           
'placeholder' => 'Password'
                                           
));
?>
<?php echo $this->Form->submit('Login', array(
                                             
'class' => 'btn',
                                             
'div' => false
                                             
));?>
<?php echo $this->Form->end(); ?>


UserController.php
public function login() 
   
{
       
//DEFINE THE LAYOUT
       
// -------------------------------------------------------->
        $this
->layout = 'users_front';

       
//print_r($this->data);

       
if ($this->request->is('post'))
       
{


         
if ($this->Auth->login())
         
{
                   
//print_r($this->data);
                   
// CHECK USER THAT LOGS IN IS ACCOUNTANT OR USER LEVEL
                   
if($this->Auth->user('group_id') == 3 || $this->Auth->user('group_id') == 4)
                   
{
                       
return $this->redirect(array('action' => 'dashboard'));;
                   
}
                   
else // ADMIN GOES TO THEIR AREA
                   
{

                       
return $this->redirect(array('admin' => true, 'action' => 'dashboard'));
                   
}
         
}
         
else
         
{

                    $this
->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');

         
}
       
}
   
}

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: