How do i override/set authlogic to use the email field instead of the username field for both signup and authentication, having a username + an email is occasionally too intense for some some registration scenarios
Asked
Active
Viewed 3,728 times
3 Answers
11
If you simply remove the login
column and add an email
column, authlogic will do the rest.
See this example readme for all the optional/required DB columns.

bensie
- 5,373
- 1
- 31
- 34
-
12magic!. Also i found using this also worked: acts_as_authentic do |c| c.login_field = :email end – ADAM Mar 18 '10 at 00:14
-
2I needed to login with email, yet retail the username. So I prefer ADAM's comment answer. – Justin Tanner Jun 09 '11 at 16:52
11
better answer try this... well, update authlogic gem if needed!
user_session.rb
class UserSession < Authlogic::Session::Base
find_by_login_method :find_by_email #for example or you can make what ever method see exapmle 2
end
--- example 2
user_session.rb
class UserSession < Authlogic::Session::Base
find_by_login_method :find_by_anything
end
user.rb
class User < ActiveRecord::Base
acts_as_authentic
def self.find_by_anything(login)
find_by_login(login) || find_by_email(login) || find_by_id(login)
end
end

amrnt
- 1,331
- 13
- 30
3
As Adam's comment contains a good answer to this question. Add this to your user model:
class User < ActiveRecord::Base
acts_as_authentic do |c| c.login_field = :email end
end

Justin Tanner
- 14,062
- 17
- 82
- 103