Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <?php
  2. require_once(sfConfig::get('sf_plugins_dir').'/sfDoctrineGuardPlugin/lib/validator/sfGuardValidatorUser.class.php');
  3.  
  4. class mySfGuardValidatorUser extends sfGuardValidatorUser
  5. {
  6. public function configure($options = array(), $messages = array())
  7. {
  8. $this->addOption('username_field', 'username');
  9. $this->addOption('password_field', 'password');
  10. $this->addOption('throw_global_error', false);
  11. }
  12.  
  13. protected function doClean($values)
  14. {
  15.  
  16. $username = isset($values[$this->getOption('username_field')]) ? $values[$this->getOption('username_field')] : '';
  17. $password = isset($values[$this->getOption('password_field')]) ? $values[$this->getOption('password_field')] : '';
  18.  
  19. $ldap = myLDAPBind::bind($username, $password);
  20. switch($ldap)
  21. {
  22. case 2:
  23. $this->setMessage('invalid', 'Your account is not authorized.');
  24. break;
  25. case 1:
  26. $this->setMessage('invalid', 'The username and/or password is invalid.');
  27. break;
  28. case 0:
  29. return true;
  30. break;
  31. }
  32. throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid')));
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement