Created
January 4, 2009 01:58
-
-
Save DBA/42980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This custom version of the authenticate method allows the user to use login or email as unique keys. | |
# Please note that if using this method it's highly recommended that you make the email property, of the user model, a required one. | |
# Also consider adding a unique index to the email field. For that create a migration with: add_index :users, :email, :unique => true | |
# It's equally advisable to remove the nullable option from the email field. | |
def self.authenticate(login, password) | |
return nil if login.blank? || password.blank? | |
u = find :first, :conditions => ['(email = ? OR login = ?) and activated_at IS NOT NULL', login, login] # need to get the salt | |
u && u.authenticated?(password) ? u : nil | |
end |
And which is the best way to achive that ? I mean, are there other pieces of code involved?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certainly, you can change the behavior in whichever way you wish.