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
  • Default: “find_by_##login_field

  • Accepts: Symbol or String



34
35
36
# File 'lib/authlogic/session/password.rb', line 34

def (value = nil)
  config(:find_by_login_method, value, "find_by_#{}")
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: Uses the configuration option in your model: User.login_field

  • Accepts: Symbol or String



46
47
48
# File 'lib/authlogic/session/password.rb', line 46

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.

  • Default: :password

  • Accepts: Symbol or String



55
56
57
# File 'lib/authlogic/session/password.rb', line 55

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.



64
65
66
# File 'lib/authlogic/session/password.rb', line 64

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