Pages

Wednesday, April 30, 2014

Configure Authlogic to log in with “username” OR “email”



Its very simple to implement Authlogic to use multiple attributes for login.

For example if you want to enable user to login with either email or username, you just need to add the following things to your code:

class UserSession < Authlogic::Session::Base 
  find_by_login_method :find_by_username_or_email
end
and in user.rb
def self.find_by_username_or_email(login)
  User.find_by_username(login) || User.find_by_email(login)
end

No comments:

Post a Comment