Using email as the login_field

27 views
Skip to first unread message

Dave Kroondyk

unread,
Nov 15, 2011, 12:49:37 PM11/15/11
to Authlogic
I found what I thought to be some strange behavior when using the
email column as the login field. Here is my setup:

User model only has an "email" column - not a "login" or "username"
column.
User model is setup like this:

class User < ActiveRecord::Base
acts_as_authentic do |c|
c.login_field = :email
end
end

What happens is the email gets validated twice - once as the "login
field" and once as the email field. So, even though the email is valid
according to Authlogic::Regex.email, it returns invalid because it
doesn't match Authlogic::Regex.login (e.g. user.n'a...@example.com -
the single quote does not pass the login regex).

The "fix" I came up with was to not validate the login field:

acts_as_authentic do |c|
c.login_field = :email
c.validate_login_field = false
end

Alternatively, I could simply leave off the config all together:

acts_as_authentic

and it worked as expected (only validates using the email regex). So,
what is the intended use? If I just have an email column, I should NOT
specify the login_field in the configuration? Seems like that should
work.

I just tried it with a username column, too. Now, I have to specify
the login_field in the config to use email. But, it still validates
using the login regex.
Reply all
Reply to author
Forward
0 new messages