Re: Remember Me with Cookie and Auth Component
Hi Miles, I cannot get the component to work, so I switched back to my own cookie login method. I can successfully login the user with the cookie, however, I only have the email address and password available. Is there anyway that i can initialize the user after he logged in? When i debug $this-Auth-user() I get: email = 'f...@bar.com', password = 'foobar' I would like to add all the additional fields in my DB to the user object. Thanks, 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Remember Me with Cookie and Auth Component
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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Remember Me with Cookie and Auth Component
Here you are: https://github.com/milesj/cake-auto_login On Nov 22, 10:23 am, Jordy van Kuijk jvank...@gmail.com wrote: 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php