开发者

sfDoctrineGuardPlugin: login with email

开发者 https://www.devze.com 2022-12-22 07:33 出处:网络
I\'m building a webapp with symgony1.4 and doctrine1.2, and I wanna use the sfDoctrineGuardPlugin, but I have a little problem.

I'm building a webapp with symgony1.4 and doctrine1.2, and I wanna use the sfDoctrineGuardPlugin, but I have a little problem.

sfDoctrineGuardPlugin is built to authen开发者_StackOverflow中文版ticate by username, but I need to change it to ask for an email.

Any idea how to do it?


If I am understanding your question correctly, you want to allow login with e-mail.

sfDoctrineGuardPlugin supports login using e-mail or username, but in version 5.0.0 is broken, according to this ticket:

http://trac.symfony-project.org/ticket/8919

There is a patch there. Apply the patch and create an entry in your app.yml setting allow_login_with_email to true:

all:
  sf_guard_plugin:
    allow_login_with_email: true

Is this what you need?


http://bluehorn.co.nz/2009/06/12/symfony-12-propel-and-sfguardplugin-email-login/

This has been written for propel, but probably is easily applicable with doctrine.


How about keeping sfDoctrineGuard as it is, using the existing username field, but saving emails into it. Your users would then login with their emails. The default field length is VARCHAR(128) which is plenty for any email. If I remember right, the only thing you'd need to tweak is the form label for sfguard signup, signin, etc (wherever you display it). You'd basically just say "Enter email here" instead of saying "Enter username here".

The only downside is that you lose the "username", but you could always put that in a separate profile that's related to sfGuardUser.

If you don't like that approach, you can always tweak the sfDoctrineGuardPlugin code directly, but it's probably going to cause some headache.


I'm going to answer this in case someone else read this question looking for help.

As oznek pointed out, you have to use the "allow_login_with_email" parameter.

However, there's a bug in the plugin (at least in version 5.0.0) that prevents it from working. You have to modify this file: /sfDoctrineGuardPlugin/lib/validator/sfGuardValidatorUser.class.php line 44 replace this:

$user = $this->getTable()->retrieveByUsername($username);

with this:

$user = $this->getTable()->$method($username);

(the "$method" variable is defined a few lines above, but never used)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号