Module: Authlogic::ActsAsAuthentic::Login::Methods::ClassMethods

Defined in:
lib/authlogic/acts_as_authentic/login.rb

Overview

Class methods relating to the login field.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Calls alias_method if your login_field name is “out of the norm”.



78
79
80
# File 'lib/authlogic/acts_as_authentic/login.rb', line 78

def self.included(klass)
  klass.send(:alias_method, "find_with_login", "find_with_#{}") if klass. != :login
end

Instance Method Details

#find_with_login(login) ⇒ Object

This method allows you to find a record with the given login. If you notice, with ActiveRecord you have the validates_uniqueness_of validation function. They give you a :case_sensitive option. I handle this in the same manner that they handle that. If you set false for the :case_sensitive option in validates_uniqueness_of_login_field_options this method will modify the query to look something like:

first(:conditions => ["LOWER(#{quoted_table_name}.#{}) = ?", .downcase])

If you don’t specify this it calls the good old find_by_* method:

()

The only reason I need to do the above is for Postgres and SQLite since they perform case sensitive searches with the find_by_* methods.



95
96
97
98
99
100
101
# File 'lib/authlogic/acts_as_authentic/login.rb', line 95

def ()
  if [:case_sensitive] == false
    first(:conditions => ["LOWER(#{quoted_table_name}.#{}) = ?", .downcase])
  else
    send("find_by_#{}", )
  end
end