Advertisement
Guest User

Untitled

a guest
Sep 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2. class RememberMeComponent extends Object{
  3. var $components = array('Auth', 'Cookie');
  4. var $controller = null;
  5.  
  6. var $period = '+2 weeks';
  7. var $cookieName = 'User';
  8.  
  9. function startup(&$controller){
  10. $this->controller =& $controller;
  11. }
  12. function remember($username=null, $password=null){
  13. $cookie = array();
  14. $cookie['email'] = $username;
  15. $cookie['password'] = $password;
  16. $this->Cookie->write($this->cookieName, $cookie, true, $this->period);
  17. }
  18.  
  19. function check(){
  20. $cookie = $this->Cookie->read($this->cookieName);
  21.  
  22. if (!is_array($cookie) || $this->Auth->user())
  23. return;
  24.  
  25. if ($this->Auth->login($cookie)){
  26. $this->Cookie->write($this->cookieName, $cookie, true, $this->period);
  27. }else{
  28. $this->delete();
  29. }
  30. }
  31.  
  32. function delete(){
  33. $this->Cookie->delete($this->cookieName);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement