Forum: Ruby on Rails Login_engine - auth against email rather that username?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tom T. (Guest)
on 2006-01-02 18:15
(Received via mailing list)
Hi all,

Short of hacking the code apart, is there a method making the
login_engine authenticate against email address rather than username?

I find that people rarely remember usernames, and would prefer to use
email addresses as the identifier.

Thanks!

Tom
Nshbrown N. (Guest)
on 2006-01-02 18:15
(Received via mailing list)
Simple fix would be to remove the email field from the
app/view/signup.rhtml
and rename the username field to email in the text.

What they put into the username field doesn't much make a difference, as
long as it is a string.

-Nb

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Nathaniel S. H. Brown                           http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Derek H. (Guest)
on 2006-01-02 18:15
(Received via mailing list)
I think you have do a couple more things because the user model won't
validate if a login is not provided.

I just re-included the LoginEngine::AuthenticatedUser module in my
User model and commented out the following lines:

#        We aren't using the login and need to comment it out
#        validates_presence_of :login, :on => :create
#        validates_length_of :login, :within => 3..40, :on => :create
#        validates_uniqueness_of :login, :on => :create

Cheers,

Derek



On 1/2/06, Nathaniel S. H. Brown <removed_email_address@domain.invalid> wrote:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Hi all,
> >
>
--
Derek H.
HighGroove Studios - http://www.highgroove.com
Atlanta, GA
Keeping it Simple.
404.593.4879
Francois B. (Guest)
on 2006-01-02 19:55
(Received via mailing list)
Hello Tom !

2006/1/2, Tom T. <removed_email_address@domain.invalid>:
> Short of hacking the code apart, is there a method making the
> login_engine authenticate against email address rather than username?

I simply added a before_validation filter that copies the email field
to the username field.  Then, I lenghtened the login field to
accomodate E-Mails.

Hope that helps !
James A. (Guest)
on 2006-01-02 20:28
(Received via mailing list)
This is all probably indicative of a need to distinguish the 'user
profile' information (name, birthday, favourite colour) from the
actual authentication information (id & password/phrase).

Perhaps the real way forward is either/or/both of:

a) removing the extraneous information (currently the name and email*)
from the authentication system, and
b) giving developers a fairly intuitive means of defining their own
validations on the id field - or a means of selecting between a few
existing ones (login, email address, something else...)

The stealth-launched new site (http://rails-engines.org) has a link to
the Trac system.
Someone submit a ticket, close your eyes and click the heels of your
ruby slippers three times, and perhaps it might get done ;-)

- james

* note that removing the guarantee that one field will contain a valid
email address means that email notification has to be reworked too.
Tom T. (Guest)
on 2006-01-02 21:24
(Received via mailing list)
Tom T. wrote:
> Short of hacking the code apart, is there a method making the
> login_engine authenticate against email address rather than username?

Hi all,

Thanks for your responses. I've managed to make it work by just simply
changing most instances of the 'login' variable to 'email' and
removing/tweaking the validation lines. The code isn't very complex, and
a bit of following it all through did me some good.

In a future version, a flag in the config would be ideal, allowing you
to auth against whatever field you wanted.

Login_engine is great work though - saved me a lot of time writing my
own system!

Thanks again,

Tom
Nshbrown N. (Guest)
on 2006-01-03 01:10
(Received via mailing list)
I was not inferring that he delete the login column and field, rather to
remove the email field and use the login field for both the email and
username.

I see under the validation that you would likely have to extend the
length_of below for the login field to more adequately compensate for
the
longer email addresses.

You still want to ensure that the email is unique, present,

So I suggest only modifying the following line in
LoginEngine::Authenticated
to the following.

        validates_length_of :login, :within => 5..255, :on => :create

Regards,
Nathaniel.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Nathaniel S. H. Brown                           http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This topic is locked and can not be replied to.