Development

/plugins/sfDoctrineGuardPlugin/trunk/lib/validator/sfGuardValidatorUser.class.php

You must first sign up to be able to contribute.

root/plugins/sfDoctrineGuardPlugin/trunk/lib/validator/sfGuardValidatorUser.class.php

Revision 31850, 2.1 kB (checked in by gimler, 3 years ago)

sfDoctrineGuardPlugin: fix to work with doctrine compiled version

  • Property svn:keywords set to Id
Line 
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$
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()->$method($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_Core::getTable('sfGuardUser');
68   }
69 }
70
Note: See TracBrowser for help on using the browser.