Module: Authlogic::ActsAsAuthentic::Login::Config
- Defined in:
- lib/authlogic/acts_as_authentic/login.rb
Overview
Configuration for the login field.
Instance Method Summary collapse
-
#find_by_smart_case_login_field(login) ⇒ Object
This method allows you to find a record with the given login.
-
#login_field(value = nil) ⇒ Object
(also: #login_field=)
The name of the login field in the database.
-
#merge_validates_format_of_login_field_options(options = {}) ⇒ Object
See merge_validates_length_of_login_field_options.
-
#merge_validates_length_of_login_field_options(options = {}) ⇒ Object
A convenience function to merge options into the validates_length_of_login_field_options.
-
#merge_validates_uniqueness_of_login_field_options(options = {}) ⇒ Object
See merge_validates_length_of_login_field_options.
-
#validate_login_field(value = nil) ⇒ Object
(also: #validate_login_field=)
Whether or not to validate the login field.
-
#validates_format_of_login_field_options(value = nil) ⇒ Object
(also: #validates_format_of_login_field_options=)
A hash of options for the validates_format_of call for the login field.
-
#validates_length_of_login_field_options(value = nil) ⇒ Object
(also: #validates_length_of_login_field_options=)
A hash of options for the validates_length_of call for the login field.
-
#validates_uniqueness_of_login_field_options(value = nil) ⇒ Object
(also: #validates_uniqueness_of_login_field_options=)
A hash of options for the validates_uniqueness_of call for the login field.
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 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 are using the login field and set false for the :case_sensitive option in validates_uniqueness_of_login_field_options this method will modify the query to look something like:
where("#{quoted_table_name}.#{field} LIKE ?", login).first
If you don’t specify this it calls the good old find_by_* method:
find_by_login(login)
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.
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.
108 109 110 111 112 113 114 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 108 def find_by_smart_case_login_field(login) if login_field find_with_case(login_field, login, [:case_sensitive] != false) else find_with_case(email_field, login, [: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
18 19 20 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 18 def login_field(value = nil) rw_config(:login_field, value, first_column_to_exist(nil, :login, :username)) end |
#merge_validates_format_of_login_field_options(options = {}) ⇒ Object
See merge_validates_length_of_login_field_options. The same thing, except for validates_format_of_login_field_options
70 71 72 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 70 def ( = {}) self. = .merge() end |
#merge_validates_length_of_login_field_options(options = {}) ⇒ Object
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
52 53 54 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 52 def ( = {}) self. = .merge() end |
#merge_validates_uniqueness_of_login_field_options(options = {}) ⇒ Object
See merge_validates_length_of_login_field_options. The same thing, except for validates_uniqueness_of_login_field_options
88 89 90 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 88 def ( = {}) self. = .merge() end |
#validate_login_field(value = nil) ⇒ Object Also known as: validate_login_field=
Whether or not to validate the login field
-
Default:
true -
Accepts:
Boolean
27 28 29 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 27 def validate_login_field(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=
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:
=> Authlogic::Regex.login, :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
64 65 66 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 64 def (value = nil) rw_config(:validates_format_of_login_field_options, value, {:with => Authlogic::Regex.login, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}) end |
#validates_length_of_login_field_options(value = nil) ⇒ Object Also known as: validates_length_of_login_field_options=
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
40 41 42 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 40 def (value = nil) 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=
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:
=> false, :scope => validations_scope, :if => “#{login_field_changed?”.to_sym} -
Accepts:
Hash of options accepted by validates_uniqueness_of
82 83 84 |
# File 'lib/authlogic/acts_as_authentic/login.rb', line 82 def (value = nil) rw_config(:validates_uniqueness_of_login_field_options, value, {:case_sensitive => false, :scope => validations_scope, :if => "#{login_field}_changed?".to_sym}) end |