Guest User

Untitled

a guest
Apr 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. class myLoginValidator extends sfValidator
  4. {
  5. public function initialize ($context, $parameters = null)
  6. {
  7. //initialize parent
  8. parent::initialize($context);
  9.  
  10. //set defaults
  11. $this->setParameter('login_error','Invalid input');
  12.  
  13. $this->getParameterHolder()->add($parameters);
  14.  
  15. return true;
  16. }
  17.  
  18. public function execute(&$value, &$error)
  19. {
  20. $passowrd_param = $this->getParameter('password');
  21. $password = $this->getContext()->getRequest()->getParameter($password_param);
  22.  
  23. $login = $value;
  24.  
  25. $c = new Criteria();
  26. $c->add(UserPeer::NICKNAME, $login);
  27. $user = UserPeer::doSelectOne($c);
  28.  
  29. //nickname exists?
  30. if ($user)
  31. {
  32. //password is OK?
  33. if (sha1 ($user->getSalt().$password) == $user->getSha1Password())
  34. {
  35. $this->getContext()->getUser()->signIn($user);
  36.  
  37. return true;
  38. }
  39. }
  40.  
  41. $error= $this->getParameter('login_error');
  42. return false;
  43. }
  44. }
Add Comment
Please, Sign In to add comment