Just following up.  Found a nice, simple solution for making this
work, and wanted to pass it on.  Thanks to Jon Wage for the help on
this one!

I'm using sfDoctrineGuardPlugin.  Also, I've got another table called
sfGuardUserProfile for the profile fields (including email).

In plugins/sfDoctrineGuardPlugin/lib/validator/
sfGuardValidatorUser.class.php there's a line that looks for the
username and gets the user object:

if ($user = Doctrine::getTable('sfGuardUser')->findOneByUsername
($username))

So, to get the user object with the email instead, simply override the
findOneByUsername function in the sfGuardUserTable class:

public function findOneByUsername($username)
        {
                $user = Doctrine::getTable('sfGuardUserProfile')->findOneByEmail
($username);
                return $user->getsfGuardUser();
        }

Hope that helps someone out!

Justin Davis


On May 5, 2:53 pm, justin_davis <jdavis1...@gmail.com> wrote:
> Hey all,
>
> I'm using Symfony 1.2 and Doctrine, with the sfDoctrineGuard plugin.
> I have a table for profile information called sfDoctrineGuardProfile.
> Creating a new user and profile works great.
>
> I want the user to be able to log in with their email address, instead
> of a username.  I set the username field in the sfDoctrineGuard schema
> to allow null values.  I found an email signin validation script here
> (http://bluehorn.co.nz/2009/04/29/implementing-email-login-with-
> sfguardplugin/) and modified it to work with doctrine.  The email
> validation is as follows:
>
> class sfGuardUserByEmailValidator extends sfValidator
> {
> public function initialize($context, $parameters = null)
> {
> // initialize parent
> parent::initialize($context);
>
> // set defaults
> $this->getParameterHolder()->set(’username_error’, ‘Email or password
> is not valid.’);
> $this->getParameterHolder()->set(’password_field’, ‘password’);
> $this->getParameterHolder()->set(’remember_field’, ‘remember’);
>
> $this->getParameterHolder()->add($parameters);
>
> return true;
>
> }
>
> public function execute(&$value, &$error)
> {
> $password_field = $this->getParameterHolder()->get(’password_field’);
> $password = $this->getContext()->getRequest()->getParameter
> ($password_field);
>
> $remember = false;
> $remember_field = $this->getParameterHolder()->get(’remember_field’);
> $remember = $this->getContext()->getRequest()->getParameter
> ($remember_field);
>
> $email = $value;
>
> $profile = sfGuardUserProfileTable::retrieveByEmail($email);
> if (!$profile) return false;
>
> $user = $profile->getsfGuardUser();
>
> // user exists and active?
> if ($user and $user->getIsActive())
> {
> // password is ok?
> if ($user->checkPassword($password))
> {
> $this->getContext()->getUser()->signIn($user, $remember);
>
> return true;
>
> }
> }
>
> $error = $this->getParameterHolder()->get(’username_error’);
>
> return false;
>
> }
> }
>
> How do I make sfGuardAuth use this validator instead of the default
> one?  I tried, per the blog post, creating a signin.yml file with the
> following values:
>
> methods:
>   post: [username, password]
>
> names:
>   username:
>   required:         true
>   required_msg:     Your username is required
>   validators:       [userValidator]
>
> password:
>   required:         true
>   required_msg:     Your password is required
>
> userValidator:
>   class:            sfGuardUserByEmailValidator
>   param:
>     password_field: password
>     remember_field: remember
>
> Placed that in apps/frontend/modules/sfGuardAuth/validate/signin.yml
> and it doesn't seem to be working.  I'm still getting username/
> password errors, instead of email/password errors.
>
> Basically, how do I override the standard sfGuardAuth validator and
> substitute this one?
>
> Thanks so much!
>
> Justin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to