views:

47

answers:

1

I implemented authlogic for my authentication system. I was hoping if there was a method to log in users by "username" OR "email" . The solution provided here http://goo.gl/Ato1 doesn't work as I don't have a "login" field in the database.

So is it that, I am missing the "login" field in the db? OR is there any other way of handling it?

Login should happen by Username OR email...

+4  A: 

Did you try this:

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

#note login is only the parameter name and does not refer to your model
mark
yup that worked... ! i was thinking there login was a field in database... thanks!
Madhusudhan
There's a popular authlogic tutorial where they use login as the main account username field of user. Hence the solution you linked to where login is discussed and is a field of the user model. Maybe it leads to confusion - you log in with login... hence my comment of it being a parameter in my answer. http://github.com/binarylogic/authlogic_example
mark