Module: Authlogic::Session::Password::Config

Defined in:
lib/authlogic/session/password.rb

Overview

Password configuration

Instance Method Summary collapse

Instance Method Details

#find_by_login_method(value = nil) ⇒ Object Also known as: find_by_login_method=

Authlogic tries to validate the credentials passed to it. One part of validation is actually finding the user and making sure it exists. What method it uses the do this is up to you.

Let’s say you have a UserSession that is authenticating a User. By default UserSession will call User.find_by_login(login). You can change what method UserSession calls by specifying it here. Then in your User model you can make that method do anything you want, giving you complete control of how users are found by the UserSession.

Let’s take an example: You want to allow users to login by username or email. Set this to the name of the class method that does this in the User model. Let’s call it “find_by_username_or_email”

class User < ActiveRecord::Base
  def self.find_by_username_or_email()
    find_by_username() || find_by_email()
  end
end

Now just specifcy the name of this method for this configuration option and you are all set. You can do anything you want here. Maybe you allow users to have multiple logins and you want to search a has_many relationship, etc. The sky is the limit.

  • Default: “find_by_smart_case_login_field”

  • Accepts: Symbol or String



37
38
39
# File 'lib/authlogic/session/password.rb', line 37

def (value = nil)
  config(:find_by_login_method, value, "find_by_smart_case_login_field")
end

#login_field(value = nil) ⇒ Object Also known as: login_field=

The name of the method you want Authlogic to create for storing the login / username. Keep in mind this is just for your Authlogic::Session, if you want it can be something completely different than the field in your model. So if you wanted people to login with a field called “login” and then find users by email this is compeltely doable. See the find_by_login_method configuration option for more details.

  • Default: klass.login_field || klass.email_field

  • Accepts: Symbol or String



49
50
51
# File 'lib/authlogic/session/password.rb', line 49

def (value = nil)
  config(:login_field, value, klass. || klass.email_field)
end

#password_field(value = nil) ⇒ Object Also known as: password_field=

Works exactly like login_field, but for the password instead. Returns :password if a login_field exists.

  • Default: :password

  • Accepts: Symbol or String



58
59
60
# File 'lib/authlogic/session/password.rb', line 58

def password_field(value = nil)
  config(:password_field, value,  && :password)
end

#verify_password_method(value = nil) ⇒ Object Also known as: verify_password_method=

The name of the method in your model used to verify the password. This should be an instance method. It should also be prepared to accept a raw password and a crytped password.



67
68
69
# File 'lib/authlogic/session/password.rb', line 67

def verify_password_method(value = nil)
  config(:verify_password_method, value, "valid_#{password_field}?")
end