Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.24 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * This file is part of the symfony package.
  5.  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10.  
  11. /**
  12.  *
  13.  * @package    symfony
  14.  * @subpackage plugin
  15.  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  16.  * @version    SVN: $Id: sfGuardValidatorUser.class.php 25546 2009-12-17 23:27:55Z Jonathan.Wage $
  17.  */
  18. class sfGuardValidatorUser extends sfValidatorBase
  19. {
  20.   public function configure($options = array(), $messages = array())
  21.   {
  22.     $this->addOption('username_field', 'username');
  23.     $this->addOption('password_field', 'password');
  24.     $this->addOption('throw_global_error', false);
  25.  
  26.     $this->setMessage('invalid', 'The username and/or password is invalid.');
  27.   }
  28.  
  29.   protected function doClean($values)
  30.   {
  31.     $username = isset($values[$this->getOption('username_field')]) ? $values[$this->getOption('username_field')] : '';
  32.     $password = isset($values[$this->getOption('password_field')]) ? $values[$this->getOption('password_field')] : '';
  33.  
  34.     $allowEmail = sfConfig::get('app_sf_guard_plugin_allow_login_with_email', true);
  35.     $method = $allowEmail ? 'retrieveByUsernameOrEmailAddress' : 'retrieveByUsername';
  36.  
  37.     // don't allow to sign in with an empty username
  38.     if ($username)
  39.     {
  40.        if ($callable = sfConfig::get('app_sf_guard_plugin_retrieve_by_username_callable'))
  41.        {
  42.            $user = call_user_func_array($callable, array($username));
  43.        } else {
  44.            $user = $this->getTable()->retrieveByUsername($username);
  45.        }
  46.         // user exists?
  47.        if($user)
  48.        {
  49.           // password is ok?
  50.           if ($user->getIsActive() && $user->checkPassword($password))
  51.           {
  52.             return array_merge($values, array('user' => $user));
  53.           }
  54.        }
  55.     }
  56.  
  57.     if ($this->getOption('throw_global_error'))
  58.     {
  59.       throw new sfValidatorError($this, 'invalid');
  60.     }
  61.  
  62.     throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid')));
  63.   }
  64.  
  65.   protected function getTable()
  66.   {
  67.     return Doctrine::getTable('sfGuardUser');
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement