Hi all,

I'm trying to add a "remember me" checkbox into my login form.
When users check the box, they log in and a cookie ('Auth.User') is
stored, with 'email' and 'password' fields (this works).
Now in my AppController, I want to see if users can log back in using
their cookie.

I have the following code:

//inside AppController.php
public function beforeFilter(){

  $cookie = $this->Cookie->read('Auth.User');

  if (is_array($cookie) && !$this->Auth->user())
        {
                $this->Auth->login($cookie);
                debug($this->Auth->user());
        }
}

The debug shows me that the user object in Auth contains the email
address and password.
Is there a way to load all of the additional data into the user object
(like firstname, lastname, etc...)?
My UsersController contains the following login function:

public function login(){

                $this->autoRender = false;
                if($this->request->is('post')){
                        if($this->Auth->login()){

                                //see if the remember me cookie has to be set
                                if(!empty($this->request->data) && 
$this->request->data['User']
['remember_me']){
                                        $cookie = array();
                        $cookie['email'] = $this->data['User']['email'];
                        $cookie['password'] = $this->data['User']['password'];
                        $this->Cookie->write('Auth.User', $cookie, true, '+2
weeks');
                        return $this->redirect('../index');
                                }
                                else{
                                        //we logged in, but the user does not 
want to have a cookie.
                                        return $this->redirect('../index');
                                }
                        }
                        else {
                                //we tried to log in the user but it failed
                                
$this->Session->setFlash($this->Auth->authError);
                                return $this->redirect('../index');
                        }
                }
                if(empty($this->request->data)){
                        $cookie = $this->Cookie->read('Auth.User');
                        if(!is_null($cookie)){

                                echo('we found cookie, now trying to log you in 
with it');

                                if($this->Auth->login($cookie)){


                                        $this->Session->delete('Message.auth');

                                        //return $this->redirect('../feed');
                                } else{
                                        //invalid cookie
                                  $this->Cookie->del('Auth.User');
                                }
                        }
                        else{
                                //users accesses this page without a cookie
                                return $this->redirect('../index');
                        }
                }
        }

Please note that I am very new to CakePHP.
Thanks in advance,

Jordy


-- 
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

Reply via email to