authlogic 3.8.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/triage.md +87 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +62 -6
- data/.rubocop_todo.yml +51 -267
- data/.travis.yml +4 -26
- data/CHANGELOG.md +226 -2
- data/CONTRIBUTING.md +15 -5
- data/Gemfile +2 -2
- data/README.md +183 -91
- data/Rakefile +1 -1
- data/UPGRADING.md +20 -0
- data/authlogic.gemspec +25 -16
- data/lib/authlogic.rb +45 -45
- data/lib/authlogic/acts_as_authentic/base.rb +18 -11
- data/lib/authlogic/acts_as_authentic/email.rb +32 -28
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +1 -1
- data/lib/authlogic/acts_as_authentic/login.rb +32 -42
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
- data/lib/authlogic/acts_as_authentic/password.rb +53 -31
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +18 -17
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +7 -12
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +64 -0
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +11 -3
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +30 -10
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +4 -4
- data/lib/authlogic/authenticates_many/association.rb +3 -3
- data/lib/authlogic/authenticates_many/base.rb +2 -2
- data/lib/authlogic/config.rb +0 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +11 -4
- data/lib/authlogic/controller_adapters/rack_adapter.rb +7 -3
- data/lib/authlogic/controller_adapters/rails_adapter.rb +2 -0
- data/lib/authlogic/crypto_providers/aes256.rb +1 -1
- data/lib/authlogic/crypto_providers/bcrypt.rb +1 -1
- data/lib/authlogic/crypto_providers/scrypt.rb +6 -6
- data/lib/authlogic/crypto_providers/sha1.rb +10 -5
- data/lib/authlogic/crypto_providers/sha256.rb +11 -8
- data/lib/authlogic/crypto_providers/wordpress.rb +2 -2
- data/lib/authlogic/i18n.rb +4 -2
- data/lib/authlogic/random.rb +10 -28
- data/lib/authlogic/regex.rb +11 -8
- data/lib/authlogic/session/activation.rb +6 -3
- data/lib/authlogic/session/active_record_trickery.rb +13 -9
- data/lib/authlogic/session/base.rb +15 -4
- data/lib/authlogic/session/brute_force_protection.rb +14 -7
- data/lib/authlogic/session/callbacks.rb +53 -30
- data/lib/authlogic/session/cookies.rb +57 -16
- data/lib/authlogic/session/existence.rb +21 -11
- data/lib/authlogic/session/foundation.rb +56 -10
- data/lib/authlogic/session/http_auth.rb +15 -8
- data/lib/authlogic/session/klass.rb +7 -5
- data/lib/authlogic/session/magic_columns.rb +24 -11
- data/lib/authlogic/session/magic_states.rb +11 -4
- data/lib/authlogic/session/params.rb +6 -2
- data/lib/authlogic/session/password.rb +46 -73
- data/lib/authlogic/session/persistence.rb +11 -7
- data/lib/authlogic/session/priority_record.rb +7 -4
- data/lib/authlogic/session/scopes.rb +15 -6
- data/lib/authlogic/session/session.rb +20 -10
- data/lib/authlogic/session/timeout.rb +2 -2
- data/lib/authlogic/session/unauthorized_record.rb +1 -1
- data/lib/authlogic/session/validation.rb +1 -1
- data/lib/authlogic/test_case.rb +65 -2
- data/lib/authlogic/test_case/mock_controller.rb +5 -4
- data/lib/authlogic/test_case/mock_cookie_jar.rb +11 -2
- data/lib/authlogic/test_case/mock_request.rb +5 -1
- data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
- data/lib/authlogic/version.rb +16 -0
- data/test/acts_as_authentic_test/email_test.rb +33 -34
- data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
- data/test/acts_as_authentic_test/login_test.rb +73 -78
- data/test/acts_as_authentic_test/password_test.rb +30 -18
- data/test/acts_as_authentic_test/perishable_token_test.rb +9 -3
- data/test/acts_as_authentic_test/persistence_token_test.rb +4 -0
- data/test/acts_as_authentic_test/session_maintenance_test.rb +66 -14
- data/test/adapter_test.rb +21 -0
- data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +2 -2
- data/test/gemfiles/Gemfile.rails-master +6 -0
- data/test/i18n_test.rb +1 -1
- data/test/libs/company.rb +2 -2
- data/test/random_test.rb +7 -37
- data/test/session_test/active_record_trickery_test.rb +4 -3
- data/test/session_test/brute_force_protection_test.rb +8 -8
- data/test/session_test/callbacks_test.rb +1 -1
- data/test/session_test/cookies_test.rb +27 -4
- data/test/session_test/existence_test.rb +15 -4
- data/test/session_test/foundation_test.rb +16 -0
- data/test/session_test/http_auth_test.rb +3 -1
- data/test/session_test/magic_columns_test.rb +10 -12
- data/test/session_test/params_test.rb +4 -1
- data/test/session_test/password_test.rb +7 -7
- data/test/session_test/persistence_test.rb +1 -0
- data/test/session_test/scopes_test.rb +7 -7
- data/test/session_test/session_test.rb +2 -2
- data/test/session_test/timeout_test.rb +1 -1
- data/test/session_test/unauthorized_record_test.rb +1 -1
- data/test/test_helper.rb +111 -103
- metadata +68 -64
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
data/Rakefile
CHANGED
data/UPGRADING.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Upgrading Authlogic
|
2
|
+
|
3
|
+
Supplemental instructions to complement CHANGELOG.md.
|
4
|
+
|
5
|
+
## 3.4.0
|
6
|
+
|
7
|
+
In version 3.4.0, the default crypto_provider was changed from *Sha512* to *SCrypt*.
|
8
|
+
|
9
|
+
If you never set a crypto_provider and are upgrading, your passwords will break unless you set the original:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
c.crypto_provider = Authlogic::CryptoProviders::Sha512
|
13
|
+
```
|
14
|
+
|
15
|
+
And if you want to automatically upgrade from *Sha512* to *SCrypt* as users login:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
c.transition_from_crypto_providers = [Authlogic::CryptoProviders::Sha512]
|
19
|
+
c.crypto_provider = Authlogic::CryptoProviders::SCrypt
|
20
|
+
```
|
data/authlogic.gemspec
CHANGED
@@ -1,27 +1,36 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "authlogic/version"
|
3
3
|
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.platform
|
8
|
-
s.authors
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
::Gem::Specification.new do |s|
|
5
|
+
s.name = "authlogic"
|
6
|
+
s.version = ::Authlogic.gem_version.to_s
|
7
|
+
s.platform = ::Gem::Platform::RUBY
|
8
|
+
s.authors = [
|
9
|
+
"Ben Johnson",
|
10
|
+
"Tieg Zaharia",
|
11
|
+
"Jared Beck"
|
12
|
+
]
|
13
|
+
s.email = [
|
14
|
+
"bjohnson@binarylogic.com",
|
15
|
+
"tieg.zaharia@gmail.com",
|
16
|
+
"jared@jaredbeck.com"
|
17
|
+
]
|
18
|
+
s.homepage = "http://github.com/binarylogic/authlogic"
|
19
|
+
s.summary = 'A clean, simple, and unobtrusive ruby authentication solution.'
|
13
20
|
s.license = 'MIT'
|
14
21
|
|
15
|
-
s.
|
16
|
-
s.add_dependency '
|
22
|
+
s.required_ruby_version = '>= 2.2.0'
|
23
|
+
s.add_dependency 'activerecord', ['>= 4.2', '< 5.3']
|
24
|
+
s.add_dependency 'activesupport', ['>= 4.2', '< 5.3']
|
17
25
|
s.add_dependency 'request_store', '~> 1.0'
|
18
26
|
s.add_dependency 'scrypt', '>= 1.2', '< 4.0'
|
19
27
|
s.add_development_dependency 'bcrypt', '~> 3.1'
|
28
|
+
s.add_development_dependency 'byebug', '~> 10.0'
|
29
|
+
s.add_development_dependency 'rubocop', '~> 0.51.0'
|
20
30
|
s.add_development_dependency 'timecop', '~> 0.7'
|
21
|
-
s.add_development_dependency 'rubocop', '~> 0.41.2'
|
22
31
|
|
23
|
-
s.files
|
24
|
-
s.test_files
|
25
|
-
s.executables
|
32
|
+
s.files = `git ls-files`.split("\n")
|
33
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
34
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
26
35
|
s.require_paths = ["lib"]
|
27
36
|
end
|
data/lib/authlogic.rb
CHANGED
@@ -9,57 +9,57 @@ require "active_record"
|
|
9
9
|
path = File.dirname(__FILE__) + "/authlogic/"
|
10
10
|
|
11
11
|
[
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
"i18n",
|
13
|
+
"random",
|
14
|
+
"regex",
|
15
|
+
"config",
|
16
16
|
|
17
|
-
|
17
|
+
"controller_adapters/abstract_adapter",
|
18
18
|
|
19
|
-
|
19
|
+
"crypto_providers",
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
"authenticates_many/base",
|
22
|
+
"authenticates_many/association",
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
"acts_as_authentic/email",
|
25
|
+
"acts_as_authentic/logged_in_status",
|
26
|
+
"acts_as_authentic/login",
|
27
|
+
"acts_as_authentic/magic_columns",
|
28
|
+
"acts_as_authentic/password",
|
29
|
+
"acts_as_authentic/perishable_token",
|
30
|
+
"acts_as_authentic/persistence_token",
|
31
|
+
"acts_as_authentic/restful_authentication",
|
32
|
+
"acts_as_authentic/session_maintenance",
|
33
|
+
"acts_as_authentic/single_access_token",
|
34
|
+
"acts_as_authentic/validations_scope",
|
35
|
+
"acts_as_authentic/base",
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
37
|
+
"session/activation",
|
38
|
+
"session/active_record_trickery",
|
39
|
+
"session/brute_force_protection",
|
40
|
+
"session/callbacks",
|
41
|
+
"session/cookies",
|
42
|
+
"session/existence",
|
43
|
+
"session/foundation",
|
44
|
+
"session/http_auth",
|
45
|
+
"session/id",
|
46
|
+
"session/klass",
|
47
|
+
"session/magic_columns",
|
48
|
+
"session/magic_states",
|
49
|
+
"session/params",
|
50
|
+
"session/password",
|
51
|
+
"session/perishable_token",
|
52
|
+
"session/persistence",
|
53
|
+
"session/priority_record",
|
54
|
+
"session/scopes",
|
55
|
+
"session/session",
|
56
|
+
"session/timeout",
|
57
|
+
"session/unauthorized_record",
|
58
|
+
"session/validation",
|
59
|
+
"session/base"
|
60
60
|
].each do |library|
|
61
|
-
|
62
|
-
|
61
|
+
require path + library
|
62
|
+
end
|
63
63
|
|
64
64
|
require path + "controller_adapters/rails_adapter" if defined?(Rails)
|
65
65
|
require path + "controller_adapters/sinatra_adapter" if defined?(Sinatra)
|
@@ -12,8 +12,8 @@ module Authlogic
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module Config
|
15
|
-
# This includes a lot of helpful methods for authenticating records
|
16
|
-
# To use it just do:
|
15
|
+
# This includes a lot of helpful methods for authenticating records
|
16
|
+
# which the Authlogic::Session module relies on. To use it just do:
|
17
17
|
#
|
18
18
|
# class User < ActiveRecord::Base
|
19
19
|
# acts_as_authentic
|
@@ -26,11 +26,11 @@ module Authlogic
|
|
26
26
|
# end
|
27
27
|
#
|
28
28
|
# See the various sub modules for the configuration they provide.
|
29
|
-
def acts_as_authentic(unsupported_options = nil
|
29
|
+
def acts_as_authentic(unsupported_options = nil)
|
30
30
|
# Stop all configuration if the DB is not set up
|
31
|
-
return
|
31
|
+
return unless db_setup?
|
32
32
|
|
33
|
-
|
33
|
+
unless unsupported_options.nil?
|
34
34
|
raise ArgumentError.new(
|
35
35
|
"You are using the old v1.X.X configuration method for " \
|
36
36
|
"Authlogic. Instead of passing a hash of configuration " \
|
@@ -43,12 +43,15 @@ module Authlogic
|
|
43
43
|
acts_as_authentic_modules.each { |mod| include mod }
|
44
44
|
end
|
45
45
|
|
46
|
-
# Since this part of Authlogic deals with another class, ActiveRecord,
|
47
|
-
# in ActiveRecord itself. A lot of
|
48
|
-
#
|
49
|
-
#
|
46
|
+
# Since this part of Authlogic deals with another class, ActiveRecord,
|
47
|
+
# we can't just start including things in ActiveRecord itself. A lot of
|
48
|
+
# these module includes need to be triggered by the acts_as_authentic
|
49
|
+
# method call. For example, you don't want to start adding in email
|
50
|
+
# validations and what not into a model that has nothing to do with
|
51
|
+
# Authlogic.
|
50
52
|
#
|
51
|
-
# That being said, this is your tool for extending Authlogic and
|
53
|
+
# That being said, this is your tool for extending Authlogic and
|
54
|
+
# "hooking" into the acts_as_authentic call.
|
52
55
|
def add_acts_as_authentic_module(mod, action = :append)
|
53
56
|
modules = acts_as_authentic_modules.clone
|
54
57
|
case action
|
@@ -81,7 +84,11 @@ module Authlogic
|
|
81
84
|
|
82
85
|
def first_column_to_exist(*columns_to_check)
|
83
86
|
if db_setup?
|
84
|
-
columns_to_check.each
|
87
|
+
columns_to_check.each do |column_name|
|
88
|
+
if column_names.include?(column_name.to_s)
|
89
|
+
return column_name.to_sym
|
90
|
+
end
|
91
|
+
end
|
85
92
|
end
|
86
93
|
columns_to_check.first && columns_to_check.first.to_sym
|
87
94
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Authlogic
|
2
2
|
module ActsAsAuthentic
|
3
|
-
# Sometimes models won't have an explicit "login" or "username" field.
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# worry
|
3
|
+
# Sometimes models won't have an explicit "login" or "username" field.
|
4
|
+
# Instead they want to use the email field. In this case, authlogic provides
|
5
|
+
# validations to make sure the email submited is actually a valid email.
|
6
|
+
# Don't worry, if you do have a login or username field, Authlogic will
|
7
|
+
# still validate your email field. One less thing you have to worry about.
|
7
8
|
module Email
|
8
9
|
def self.included(klass)
|
9
10
|
klass.class_eval do
|
@@ -32,28 +33,33 @@ module Authlogic
|
|
32
33
|
end
|
33
34
|
alias_method :validate_email_field=, :validate_email_field
|
34
35
|
|
35
|
-
# A hash of options for the validates_length_of call for the email
|
36
|
+
# A hash of options for the validates_length_of call for the email
|
37
|
+
# field. Allows you to change this however you want.
|
36
38
|
#
|
37
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
38
|
-
#
|
39
|
-
#
|
39
|
+
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
40
|
+
# possible, so you can completely replace the hash or merge options into
|
41
|
+
# it. Checkout the convenience function
|
42
|
+
# merge_validates_length_of_email_field_options to merge options.</b>
|
40
43
|
#
|
41
44
|
# * <tt>Default:</tt> {:maximum => 100}
|
42
45
|
# * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
|
43
46
|
def validates_length_of_email_field_options(value = nil)
|
44
|
-
rw_config(:validates_length_of_email_field_options, value,
|
47
|
+
rw_config(:validates_length_of_email_field_options, value, maximum: 100)
|
45
48
|
end
|
46
49
|
alias_method :validates_length_of_email_field_options=, :validates_length_of_email_field_options
|
47
50
|
|
48
|
-
# A convenience function to merge options into the
|
51
|
+
# A convenience function to merge options into the
|
52
|
+
# validates_length_of_email_field_options. So instead of:
|
49
53
|
#
|
50
|
-
# self.validates_length_of_email_field_options =
|
54
|
+
# self.validates_length_of_email_field_options =
|
55
|
+
# validates_length_of_email_field_options.merge(:my_option => my_value)
|
51
56
|
#
|
52
57
|
# You can do this:
|
53
58
|
#
|
54
59
|
# merge_validates_length_of_email_field_options :my_option => my_value
|
55
60
|
def merge_validates_length_of_email_field_options(options = {})
|
56
|
-
self.validates_length_of_email_field_options =
|
61
|
+
self.validates_length_of_email_field_options =
|
62
|
+
validates_length_of_email_field_options.merge(options)
|
57
63
|
end
|
58
64
|
|
59
65
|
# A hash of options for the validates_format_of call for the email
|
@@ -86,22 +92,22 @@ module Authlogic
|
|
86
92
|
rw_config(
|
87
93
|
:validates_format_of_email_field_options,
|
88
94
|
value,
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
}
|
95
|
+
with: Authlogic::Regex.email,
|
96
|
+
message: Proc.new do
|
97
|
+
I18n.t(
|
98
|
+
'error_messages.email_invalid',
|
99
|
+
default: "should look like an email address."
|
100
|
+
)
|
101
|
+
end
|
98
102
|
)
|
99
103
|
end
|
100
104
|
alias_method :validates_format_of_email_field_options=, :validates_format_of_email_field_options
|
101
105
|
|
102
|
-
# See merge_validates_length_of_email_field_options. The same thing
|
106
|
+
# See merge_validates_length_of_email_field_options. The same thing
|
107
|
+
# except for validates_format_of_email_field_options.
|
103
108
|
def merge_validates_format_of_email_field_options(options = {})
|
104
|
-
self.validates_format_of_email_field_options =
|
109
|
+
self.validates_format_of_email_field_options =
|
110
|
+
validates_format_of_email_field_options.merge(options)
|
105
111
|
end
|
106
112
|
|
107
113
|
# A hash of options for the validates_uniqueness_of call for the email
|
@@ -126,11 +132,9 @@ module Authlogic
|
|
126
132
|
rw_config(
|
127
133
|
:validates_uniqueness_of_email_field_options,
|
128
134
|
value,
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
:if => "#{email_field}_changed?".to_sym
|
133
|
-
}
|
135
|
+
case_sensitive: false,
|
136
|
+
scope: validations_scope,
|
137
|
+
if: "#{email_field}_changed?".to_sym
|
134
138
|
)
|
135
139
|
end
|
136
140
|
alias_method(
|
@@ -27,7 +27,7 @@ module Authlogic
|
|
27
27
|
# All methods for the logged in status feature seat.
|
28
28
|
module Methods
|
29
29
|
def self.included(klass)
|
30
|
-
return
|
30
|
+
return unless klass.column_names.include?("last_request_at")
|
31
31
|
|
32
32
|
klass.class_eval do
|
33
33
|
include InstanceMethods
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'authlogic/acts_as_authentic/queries/find_with_case'
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
5
|
# Handles everything related to the login field.
|
@@ -40,7 +42,7 @@ module Authlogic
|
|
40
42
|
# * <tt>Default:</tt> {:within => 3..100}
|
41
43
|
# * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
|
42
44
|
def validates_length_of_login_field_options(value = nil)
|
43
|
-
rw_config(:validates_length_of_login_field_options, value,
|
45
|
+
rw_config(:validates_length_of_login_field_options, value, within: 3..100)
|
44
46
|
end
|
45
47
|
alias_method :validates_length_of_login_field_options=, :validates_length_of_login_field_options
|
46
48
|
|
@@ -54,7 +56,8 @@ module Authlogic
|
|
54
56
|
#
|
55
57
|
# merge_validates_length_of_login_field_options :my_option => my_value
|
56
58
|
def merge_validates_length_of_login_field_options(options = {})
|
57
|
-
self.validates_length_of_login_field_options =
|
59
|
+
self.validates_length_of_login_field_options =
|
60
|
+
validates_length_of_login_field_options.merge(options)
|
58
61
|
end
|
59
62
|
|
60
63
|
# A hash of options for the validates_format_of call for the login
|
@@ -82,15 +85,13 @@ module Authlogic
|
|
82
85
|
rw_config(
|
83
86
|
:validates_format_of_login_field_options,
|
84
87
|
value,
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
}
|
88
|
+
with: Authlogic::Regex.login,
|
89
|
+
message: proc do
|
90
|
+
I18n.t(
|
91
|
+
'error_messages.login_invalid',
|
92
|
+
default: "should use only letters, numbers, spaces, and .-_@+ please."
|
93
|
+
)
|
94
|
+
end
|
94
95
|
)
|
95
96
|
end
|
96
97
|
alias_method :validates_format_of_login_field_options=, :validates_format_of_login_field_options
|
@@ -98,7 +99,8 @@ module Authlogic
|
|
98
99
|
# See merge_validates_length_of_login_field_options. The same thing,
|
99
100
|
# except for validates_format_of_login_field_options
|
100
101
|
def merge_validates_format_of_login_field_options(options = {})
|
101
|
-
self.validates_format_of_login_field_options =
|
102
|
+
self.validates_format_of_login_field_options =
|
103
|
+
validates_format_of_login_field_options.merge(options)
|
102
104
|
end
|
103
105
|
|
104
106
|
# A hash of options for the validates_uniqueness_of call for the login
|
@@ -122,11 +124,9 @@ module Authlogic
|
|
122
124
|
rw_config(
|
123
125
|
:validates_uniqueness_of_login_field_options,
|
124
126
|
value,
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
:if => "#{login_field}_changed?".to_sym
|
129
|
-
}
|
127
|
+
case_sensitive: false,
|
128
|
+
scope: validations_scope,
|
129
|
+
if: "#{login_field}_changed?".to_sym
|
130
130
|
)
|
131
131
|
end
|
132
132
|
alias_method(
|
@@ -160,39 +160,29 @@ module Authlogic
|
|
160
160
|
# The above also applies for using email as your login, except that you
|
161
161
|
# need to set the :case_sensitive in
|
162
162
|
# validates_uniqueness_of_email_field_options to false.
|
163
|
+
#
|
164
|
+
# @api public
|
163
165
|
def find_by_smart_case_login_field(login)
|
164
166
|
if login_field
|
165
|
-
find_with_case(
|
167
|
+
find_with_case(
|
168
|
+
login_field,
|
169
|
+
login,
|
170
|
+
validates_uniqueness_of_login_field_options[:case_sensitive] != false
|
171
|
+
)
|
166
172
|
else
|
167
|
-
find_with_case(
|
173
|
+
find_with_case(
|
174
|
+
email_field,
|
175
|
+
login,
|
176
|
+
validates_uniqueness_of_email_field_options[:case_sensitive] != false
|
177
|
+
)
|
168
178
|
end
|
169
179
|
end
|
170
180
|
|
171
181
|
private
|
172
182
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
relation = if not sensitivity
|
177
|
-
connection.case_insensitive_comparison(arel_table, field.to_s, columns_hash[field.to_s], value)
|
178
|
-
elsif ar_gem_version >= Gem::Version.new('5.0')
|
179
|
-
connection.case_sensitive_comparison(arel_table, field.to_s, columns_hash[field.to_s], value)
|
180
|
-
else
|
181
|
-
if ar_gem_version < Gem::Version.new('4.2')
|
182
|
-
value = connection.case_sensitive_modifier(value)
|
183
|
-
else
|
184
|
-
value = connection.case_sensitive_modifier(value, field.to_s)
|
185
|
-
end
|
186
|
-
arel_table[field.to_s].eq(value)
|
187
|
-
end
|
188
|
-
|
189
|
-
# bind value in rails 5
|
190
|
-
if ar_gem_version >= Gem::Version.new('5')
|
191
|
-
bind = ActiveRecord::Relation::QueryAttribute.new(field.to_s, value, ActiveRecord::Type::Value.new)
|
192
|
-
where(relation, bind).first
|
193
|
-
else
|
194
|
-
where(relation).first
|
195
|
-
end
|
183
|
+
# @api private
|
184
|
+
def find_with_case(field, value, sensitive)
|
185
|
+
Queries::FindWithCase.new(self, field, value, sensitive).execute
|
196
186
|
end
|
197
187
|
end
|
198
188
|
|