CakePHP remember Me? (part 2)

So I was having a conversation with Mariano Iglesias and mrwooster(username) on the cakePHP list and Mariano made an instant and awesome suggestion:

Looking at your code, I would have to say that it is not recommended to add
models at the AppController level. Your code is just asking to be made a
component :)
Something like app/controllers/components/remember_me.php:

class RememberMeComponent extends Object 
{ 
        var $components = array('Session', 'Cookie'); 

        var $uses = array('User'); 

        function remember() 
        { 
                if(!$this->Session->check('User') && 
$this->Cookie->check('login')) 
                { 
                        $cookie_arr = $this->cookie->read('login'); 
                        $someone = $this->User->findByEmail($cookie_arr[0]); 

                        if($someone['User']['password'] == $cookie_arr[1]) 
                        { 
                                $this->Session->write('User', 
$someone['User']); 
                        } 
                } 
        } 

}

Then on your AppController you add RememberMe as a component, and on your beforeFilter() you do:

$this->RememberMe->remember();

I will do this. Shortly I will have a component that can remember people using rossoft’s cookie component.

 
Blog comments powered by Disqus