RoR Devise: Sign in with username OR email

Posted by Patrick Oscity on Stack Overflow See other posts from Stack Overflow or by Patrick Oscity
Published on 2010-06-08T12:20:47Z Indexed on 2010/06/08 13:32 UTC
Read the original article Hit count: 399

Whats the best way to enable users to log in with their email address OR their username? I am using warden + devise for authentication. I think it probably won't be too hard to do it but i guess i need some advice here on where to put all the stuff that is needed. Perhaps devise devise already provides this feature? like in the config/initializers/devise.rb you would write:

config.authentication_keys = [ :email, :username ]

To require both username AND email for signing in. But i really want to have only one field for both username and email and require only one of them. I'll just visualize that with some ASCII art, it should look something like this in the view:

Username or Email:
[____________________]

Password:
[____________________]

[Sign In]

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about authentication