Module: Authlogic::ActsAsAuthentic::Login::Config

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

Overview

Configuration for the login field.

Instance Method Summary collapse

Instance Method Details

#find_by_smart_case_login_field(login) ⇒ Object

This method allows you to find a record with the given login. If you notice, with Active Record you have the UniquenessValidator class. They give you a :case_sensitive option. I handle this in the same manner that they handle that. If you are using the login field, set false for the :case_sensitive option in validates_uniqueness_of_login_field_options and the column doesn’t have a case-insensitive collation, this method will modify the query to look something like:

"LOWER(#{quoted_table_name}.#{}) = LOWER(#{})"

If you don’t specify this it just uses a regular case-sensitive search (with the binary modifier if necessary):

"BINARY #{} = #{}"

The above also applies for using email as your login, except that you need to set the :case_sensitive in validates_uniqueness_of_email_field_options to false.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/authlogic/acts_as_authentic/login.rb', line 191

def ()
  if 
    find_with_case(
      ,
      ,
      [:case_sensitive] != false
    )
  else
    find_with_case(
      email_field,
      ,
      validates_uniqueness_of_email_field_options[:case_sensitive] != false
    )
  end
end

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

The name of the login field in the database.

  • Default: :login or :username, if they exist

  • Accepts: Symbol



20
21
22
# File 'lib/authlogic/acts_as_authentic/login.rb', line 20

def (value = nil)
  rw_config(:login_field, value, first_column_to_exist(nil, :login, :username))
end

#merge_validates_format_of_login_field_options(options = {}) ⇒ Object

Deprecated.

See merge_validates_length_of_login_field_options. The same thing, except for validates_format_of_login_field_options



120
121
122
123
124
# File 'lib/authlogic/acts_as_authentic/login.rb', line 120

def (options = {})
  deprecate_authlogic_config("merge_validates_format_of_login_field_options")
  self. =
    .merge(options)
end

#merge_validates_length_of_login_field_options(options = {}) ⇒ Object

Deprecated.

A convenience function to merge options into the validates_length_of_login_field_options. So instead of:

self. =
  .merge(:my_option => my_value)

You can do this:

 :my_option => my_value


68
69
70
71
72
# File 'lib/authlogic/acts_as_authentic/login.rb', line 68

def (options = {})
  deprecate_authlogic_config("merge_validates_length_of_login_field_options")
  self. =
    .merge(options)
end

#merge_validates_uniqueness_of_login_field_options(options = {}) ⇒ Object

Deprecated.

See merge_validates_length_of_login_field_options. The same thing, except for validates_uniqueness_of_login_field_options



164
165
166
167
168
# File 'lib/authlogic/acts_as_authentic/login.rb', line 164

def (options = {})
  deprecate_authlogic_config("merge_validates_uniqueness_of_login_field_options")
  self. =
    .merge(options)
end

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

Deprecated.

Whether or not to validate the login field

  • Default: true

  • Accepts: Boolean



31
32
33
# File 'lib/authlogic/acts_as_authentic/login.rb', line 31

def (value = nil)
  rw_config(:validate_login_field, value, true)
end

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

Deprecated.

A hash of options for the validates_format_of call for the login field. Allows you to change this however you want.

Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or merge options into it. Checkout the convenience function merge_validates_format_of_login_field_options to merge options.

  • Default:

    {
      :with => Authlogic::Regex.,
      :message => lambda {
        I18n.t(
          'error_messages.login_invalid',
          :default => "should use only letters, numbers, spaces, and .-_@+ please."
        )
      }
    }
    
  • Accepts: Hash of options accepted by validates_format_of



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/authlogic/acts_as_authentic/login.rb', line 97

def (value = nil)
  deprecate_authlogic_config("validates_format_of_login_field_options") if value
  rw_config(
    :validates_format_of_login_field_options,
    value,
    with: Authlogic::Regex::LOGIN,
    message: proc do
               I18n.t(
                 "error_messages.login_invalid",
                 default: "should use only letters, numbers, spaces, and .-_@+ please."
               )
             end
  )
end

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

Deprecated.

A hash of options for the validates_length_of call for the login field. Allows you to change this however you want.

Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or merge options into it. Checkout the convenience function merge_validates_length_of_login_field_options to merge options.

  • Default: => 3..100

  • Accepts: Hash of options accepted by validates_length_of



48
49
50
51
# File 'lib/authlogic/acts_as_authentic/login.rb', line 48

def (value = nil)
  deprecate_authlogic_config("validates_length_of_login_field_options") if value
  rw_config(:validates_length_of_login_field_options, value, within: 3..100)
end

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

Deprecated.

A hash of options for the validates_uniqueness_of call for the login field. Allows you to change this however you want.

Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or merge options into it. Checkout the convenience function merge_validates_format_of_login_field_options to merge options.

  • Default:

    {
      :case_sensitive => false,
      :scope => validations_scope,
      :if => "#{}_changed?".to_sym
    }
    
  • Accepts: Hash of options accepted by validates_uniqueness_of



145
146
147
148
149
150
151
152
153
154
# File 'lib/authlogic/acts_as_authentic/login.rb', line 145

def (value = nil)
  deprecate_authlogic_config("validates_uniqueness_of_login_field_options") if value
  rw_config(
    :validates_uniqueness_of_login_field_options,
    value,
    case_sensitive: false,
    scope: validations_scope,
    if: "#{}_changed?".to_sym
  )
end