cakephp 2.1 signup and login

Go To StackoverFlow.com

0

I have a problem with cakephp 2.1 and Auth.

In my AppControlles I have a function getUserdetails()

if (($user = $this->Auth->user()) != null)
    {
      $this->loadModel('User');
      $tmp = $this->User->find('first',array(
          'conditions' => array('username' => $user['User']['username'], 
                       'password'=> $user['User']'password'],
                'active' => 1),
          'recursive' => -1));

      if(!isset($tmp['User']))
        return null;

      $this->_userDetails = $tmp['User'];
      $this->set('userDetails', $this->_userDetails);
    }
    else
      return null

When the user firstly signup $this->Auth->user() returns

array(
    'User' => array(
        'password' => '*****',
        'username' => 'me',
        'remember_me' => '1'
    )
)

where password is md5 encoded. If I logout and login again password in the previous array is return in plain text so User->find returns false. Is there a way to make a single function for this? How can I know if password from $this->Auth->user() is md5 or not?

thanks

2012-04-04 18:54
by gong


0

Try this:

public function login() {
    //If a user is already logged in, redirect him
    if ($this->Session->read('Auth.User')) {
        //$this->Session->setFlash('You are logged in!');
        $this->redirect(array('controller' => 'showspage', 'action' => 'home'));
    }

    if ($this->request->is('post')) {
        $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);

        if ($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash('Wrong username or password');
            $this->redirect(array('controller' => 'showspage', 'action' => 'home'));
        }
    }
    $this->Session->setFlash('You aren't legged-in!');
    $this->redirect(array('controller' => 'showspage', 'action' => 'home'));
}

All informations about user are in session and you can find it with AuthComponent:

Es: AuthComponent::user('username');

2012-04-05 05:19
by lezrael
for some reason AuthComponent::user('email') & AuthComponent::user('password') return null - gong 2012-04-05 18:00
Ads