authlogic 3.8.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.github/triage.md +87 -0
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +62 -6
  5. data/.rubocop_todo.yml +51 -267
  6. data/.travis.yml +4 -26
  7. data/CHANGELOG.md +226 -2
  8. data/CONTRIBUTING.md +15 -5
  9. data/Gemfile +2 -2
  10. data/README.md +183 -91
  11. data/Rakefile +1 -1
  12. data/UPGRADING.md +20 -0
  13. data/authlogic.gemspec +25 -16
  14. data/lib/authlogic.rb +45 -45
  15. data/lib/authlogic/acts_as_authentic/base.rb +18 -11
  16. data/lib/authlogic/acts_as_authentic/email.rb +32 -28
  17. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +1 -1
  18. data/lib/authlogic/acts_as_authentic/login.rb +32 -42
  19. data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
  20. data/lib/authlogic/acts_as_authentic/password.rb +53 -31
  21. data/lib/authlogic/acts_as_authentic/perishable_token.rb +18 -17
  22. data/lib/authlogic/acts_as_authentic/persistence_token.rb +7 -12
  23. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +64 -0
  24. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +11 -3
  25. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +30 -10
  26. data/lib/authlogic/acts_as_authentic/single_access_token.rb +4 -4
  27. data/lib/authlogic/authenticates_many/association.rb +3 -3
  28. data/lib/authlogic/authenticates_many/base.rb +2 -2
  29. data/lib/authlogic/config.rb +0 -1
  30. data/lib/authlogic/controller_adapters/abstract_adapter.rb +11 -4
  31. data/lib/authlogic/controller_adapters/rack_adapter.rb +7 -3
  32. data/lib/authlogic/controller_adapters/rails_adapter.rb +2 -0
  33. data/lib/authlogic/crypto_providers/aes256.rb +1 -1
  34. data/lib/authlogic/crypto_providers/bcrypt.rb +1 -1
  35. data/lib/authlogic/crypto_providers/scrypt.rb +6 -6
  36. data/lib/authlogic/crypto_providers/sha1.rb +10 -5
  37. data/lib/authlogic/crypto_providers/sha256.rb +11 -8
  38. data/lib/authlogic/crypto_providers/wordpress.rb +2 -2
  39. data/lib/authlogic/i18n.rb +4 -2
  40. data/lib/authlogic/random.rb +10 -28
  41. data/lib/authlogic/regex.rb +11 -8
  42. data/lib/authlogic/session/activation.rb +6 -3
  43. data/lib/authlogic/session/active_record_trickery.rb +13 -9
  44. data/lib/authlogic/session/base.rb +15 -4
  45. data/lib/authlogic/session/brute_force_protection.rb +14 -7
  46. data/lib/authlogic/session/callbacks.rb +53 -30
  47. data/lib/authlogic/session/cookies.rb +57 -16
  48. data/lib/authlogic/session/existence.rb +21 -11
  49. data/lib/authlogic/session/foundation.rb +56 -10
  50. data/lib/authlogic/session/http_auth.rb +15 -8
  51. data/lib/authlogic/session/klass.rb +7 -5
  52. data/lib/authlogic/session/magic_columns.rb +24 -11
  53. data/lib/authlogic/session/magic_states.rb +11 -4
  54. data/lib/authlogic/session/params.rb +6 -2
  55. data/lib/authlogic/session/password.rb +46 -73
  56. data/lib/authlogic/session/persistence.rb +11 -7
  57. data/lib/authlogic/session/priority_record.rb +7 -4
  58. data/lib/authlogic/session/scopes.rb +15 -6
  59. data/lib/authlogic/session/session.rb +20 -10
  60. data/lib/authlogic/session/timeout.rb +2 -2
  61. data/lib/authlogic/session/unauthorized_record.rb +1 -1
  62. data/lib/authlogic/session/validation.rb +1 -1
  63. data/lib/authlogic/test_case.rb +65 -2
  64. data/lib/authlogic/test_case/mock_controller.rb +5 -4
  65. data/lib/authlogic/test_case/mock_cookie_jar.rb +11 -2
  66. data/lib/authlogic/test_case/mock_request.rb +5 -1
  67. data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
  68. data/lib/authlogic/version.rb +16 -0
  69. data/test/acts_as_authentic_test/email_test.rb +33 -34
  70. data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
  71. data/test/acts_as_authentic_test/login_test.rb +73 -78
  72. data/test/acts_as_authentic_test/password_test.rb +30 -18
  73. data/test/acts_as_authentic_test/perishable_token_test.rb +9 -3
  74. data/test/acts_as_authentic_test/persistence_token_test.rb +4 -0
  75. data/test/acts_as_authentic_test/session_maintenance_test.rb +66 -14
  76. data/test/adapter_test.rb +21 -0
  77. data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
  78. data/test/gemfiles/Gemfile.rails-5.0.x +2 -2
  79. data/test/gemfiles/Gemfile.rails-master +6 -0
  80. data/test/i18n_test.rb +1 -1
  81. data/test/libs/company.rb +2 -2
  82. data/test/random_test.rb +7 -37
  83. data/test/session_test/active_record_trickery_test.rb +4 -3
  84. data/test/session_test/brute_force_protection_test.rb +8 -8
  85. data/test/session_test/callbacks_test.rb +1 -1
  86. data/test/session_test/cookies_test.rb +27 -4
  87. data/test/session_test/existence_test.rb +15 -4
  88. data/test/session_test/foundation_test.rb +16 -0
  89. data/test/session_test/http_auth_test.rb +3 -1
  90. data/test/session_test/magic_columns_test.rb +10 -12
  91. data/test/session_test/params_test.rb +4 -1
  92. data/test/session_test/password_test.rb +7 -7
  93. data/test/session_test/persistence_test.rb +1 -0
  94. data/test/session_test/scopes_test.rb +7 -7
  95. data/test/session_test/session_test.rb +2 -2
  96. data/test/session_test/timeout_test.rb +1 -1
  97. data/test/session_test/unauthorized_record_test.rb +1 -1
  98. data/test/test_helper.rb +111 -103
  99. metadata +68 -64
  100. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  101. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  102. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
data/Rakefile CHANGED
@@ -18,4 +18,4 @@ end
18
18
  require "rubocop/rake_task"
19
19
  RuboCop::RakeTask.new
20
20
 
21
- task :default => [:rubocop, :test]
21
+ task default: [:rubocop, :test]
@@ -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
+ ```
@@ -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 = "authlogic"
6
- s.version = "3.8.0"
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["Ben Johnson"]
9
- s.email = ["bjohnson@binarylogic.com"]
10
- s.homepage = "http://github.com/binarylogic/authlogic"
11
- s.summary = 'A clean, simple, and unobtrusive ruby authentication solution.'
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.add_dependency 'activerecord', ['>= 3.2', '< 5.3']
16
- s.add_dependency 'activesupport', ['>= 3.2', '< 5.3']
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 = `git ls-files`.split("\n")
24
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
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
@@ -9,57 +9,57 @@ require "active_record"
9
9
  path = File.dirname(__FILE__) + "/authlogic/"
10
10
 
11
11
  [
12
- "i18n",
13
- "random",
14
- "regex",
15
- "config",
12
+ "i18n",
13
+ "random",
14
+ "regex",
15
+ "config",
16
16
 
17
- "controller_adapters/abstract_adapter",
17
+ "controller_adapters/abstract_adapter",
18
18
 
19
- "crypto_providers",
19
+ "crypto_providers",
20
20
 
21
- "authenticates_many/base",
22
- "authenticates_many/association",
21
+ "authenticates_many/base",
22
+ "authenticates_many/association",
23
23
 
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",
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
- "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"
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
- require path + library
62
- end
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 which The Authlogic::Session module relies on.
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, &block)
29
+ def acts_as_authentic(unsupported_options = nil)
30
30
  # Stop all configuration if the DB is not set up
31
- return if !db_setup?
31
+ return unless db_setup?
32
32
 
33
- if !unsupported_options.nil?
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, we can't just start including things
47
- # in ActiveRecord itself. A lot of these module includes need to be triggered by the acts_as_authentic method
48
- # call. For example, you don't want to start adding in email validations and what not into a model that has
49
- # nothing to do with Authlogic.
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 "hooking" into the acts_as_authentic call.
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 { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
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. Instead they want to use the email field.
4
- # In this case, authlogic provides validations to make sure the email submited is actually a valid email. Don't worry,
5
- # if you do have a login or username field, Authlogic will still validate your email field. One less thing you have to
6
- # worry about.
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 field. Allows you to change this however you want.
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 possible, so you can completely replace the hash or
38
- # merge options into it. Checkout the convenience function merge_validates_length_of_email_field_options to merge
39
- # options.</b>
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, { :maximum => 100 })
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 validates_length_of_email_field_options. So instead of:
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 = validates_length_of_email_field_options.merge(:my_option => my_value)
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 = validates_length_of_email_field_options.merge(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
- :with => Authlogic::Regex.email,
91
- :message => Proc.new do
92
- I18n.t(
93
- 'error_messages.email_invalid',
94
- :default => "should look like an email address."
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 except for validates_format_of_email_field_options.
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 = validates_format_of_email_field_options.merge(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
- :case_sensitive => false,
131
- :scope => validations_scope,
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 if !klass.column_names.include?("last_request_at")
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, { :within => 3..100 })
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 = validates_length_of_login_field_options.merge(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
- :with => Authlogic::Regex.login,
87
- :message => proc do
88
- I18n.t(
89
- 'error_messages.login_invalid',
90
- :default => "should use only letters, numbers, spaces, and .-_@+ please."
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 = validates_format_of_login_field_options.merge(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
- :case_sensitive => false,
127
- :scope => validations_scope,
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(login_field, login, validates_uniqueness_of_login_field_options[:case_sensitive] != false)
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(email_field, login, validates_uniqueness_of_email_field_options[:case_sensitive] != false)
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
- def find_with_case(field, value, sensitivity = true)
174
- ar_gem_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
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