authlogic 3.8.0 → 4.5.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.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
  3. data/.github/ISSUE_TEMPLATE/feature_proposal.md +32 -0
  4. data/.github/triage.md +86 -0
  5. data/.gitignore +4 -3
  6. data/.rubocop.yml +109 -9
  7. data/.rubocop_todo.yml +38 -355
  8. data/.travis.yml +11 -35
  9. data/CHANGELOG.md +345 -2
  10. data/CONTRIBUTING.md +45 -14
  11. data/Gemfile +3 -2
  12. data/README.md +244 -90
  13. data/Rakefile +10 -10
  14. data/UPGRADING.md +22 -0
  15. data/authlogic.gemspec +34 -21
  16. data/doc/use_normal_rails_validation.md +82 -0
  17. data/gemfiles/Gemfile.rails-4.2.x +6 -0
  18. data/{test/gemfiles → gemfiles}/Gemfile.rails-5.1.x +2 -2
  19. data/{test/gemfiles → gemfiles}/Gemfile.rails-5.2.x +2 -2
  20. data/lib/authlogic/acts_as_authentic/base.rb +36 -24
  21. data/lib/authlogic/acts_as_authentic/email.rb +65 -31
  22. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +14 -9
  23. data/lib/authlogic/acts_as_authentic/login.rb +61 -45
  24. data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
  25. data/lib/authlogic/acts_as_authentic/password.rb +267 -146
  26. data/lib/authlogic/acts_as_authentic/perishable_token.rb +24 -19
  27. data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -15
  28. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +67 -0
  29. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +50 -14
  30. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +88 -60
  31. data/lib/authlogic/acts_as_authentic/single_access_token.rb +23 -11
  32. data/lib/authlogic/acts_as_authentic/validations_scope.rb +9 -6
  33. data/lib/authlogic/authenticates_many/association.rb +7 -7
  34. data/lib/authlogic/authenticates_many/base.rb +37 -21
  35. data/lib/authlogic/config.rb +21 -10
  36. data/lib/authlogic/controller_adapters/abstract_adapter.rb +38 -11
  37. data/lib/authlogic/controller_adapters/rack_adapter.rb +9 -5
  38. data/lib/authlogic/controller_adapters/rails_adapter.rb +12 -7
  39. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +2 -2
  40. data/lib/authlogic/crypto_providers/aes256.rb +37 -32
  41. data/lib/authlogic/crypto_providers/bcrypt.rb +21 -15
  42. data/lib/authlogic/crypto_providers/md5.rb +4 -2
  43. data/lib/authlogic/crypto_providers/scrypt.rb +22 -17
  44. data/lib/authlogic/crypto_providers/sha1.rb +11 -5
  45. data/lib/authlogic/crypto_providers/sha256.rb +13 -9
  46. data/lib/authlogic/crypto_providers/sha512.rb +0 -21
  47. data/lib/authlogic/crypto_providers/wordpress.rb +32 -3
  48. data/lib/authlogic/crypto_providers.rb +91 -0
  49. data/lib/authlogic/i18n.rb +26 -19
  50. data/lib/authlogic/random.rb +10 -28
  51. data/lib/authlogic/regex.rb +59 -28
  52. data/lib/authlogic/session/activation.rb +10 -7
  53. data/lib/authlogic/session/active_record_trickery.rb +13 -9
  54. data/lib/authlogic/session/base.rb +15 -4
  55. data/lib/authlogic/session/brute_force_protection.rb +40 -33
  56. data/lib/authlogic/session/callbacks.rb +94 -46
  57. data/lib/authlogic/session/cookies.rb +130 -45
  58. data/lib/authlogic/session/existence.rb +21 -11
  59. data/lib/authlogic/session/foundation.rb +64 -14
  60. data/lib/authlogic/session/http_auth.rb +35 -28
  61. data/lib/authlogic/session/id.rb +9 -4
  62. data/lib/authlogic/session/klass.rb +15 -12
  63. data/lib/authlogic/session/magic_columns.rb +58 -55
  64. data/lib/authlogic/session/magic_states.rb +25 -19
  65. data/lib/authlogic/session/params.rb +42 -28
  66. data/lib/authlogic/session/password.rb +130 -120
  67. data/lib/authlogic/session/perishable_token.rb +5 -4
  68. data/lib/authlogic/session/persistence.rb +18 -12
  69. data/lib/authlogic/session/priority_record.rb +15 -12
  70. data/lib/authlogic/session/scopes.rb +51 -32
  71. data/lib/authlogic/session/session.rb +38 -28
  72. data/lib/authlogic/session/timeout.rb +13 -13
  73. data/lib/authlogic/session/unauthorized_record.rb +18 -13
  74. data/lib/authlogic/session/validation.rb +9 -9
  75. data/lib/authlogic/test_case/mock_controller.rb +5 -4
  76. data/lib/authlogic/test_case/mock_cookie_jar.rb +47 -3
  77. data/lib/authlogic/test_case/mock_request.rb +6 -3
  78. data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
  79. data/lib/authlogic/test_case.rb +70 -2
  80. data/lib/authlogic/version.rb +21 -0
  81. data/lib/authlogic.rb +51 -49
  82. data/test/acts_as_authentic_test/base_test.rb +3 -1
  83. data/test/acts_as_authentic_test/email_test.rb +43 -42
  84. data/test/acts_as_authentic_test/logged_in_status_test.rb +6 -4
  85. data/test/acts_as_authentic_test/login_test.rb +77 -80
  86. data/test/acts_as_authentic_test/magic_columns_test.rb +3 -1
  87. data/test/acts_as_authentic_test/password_test.rb +51 -37
  88. data/test/acts_as_authentic_test/perishable_token_test.rb +13 -5
  89. data/test/acts_as_authentic_test/persistence_token_test.rb +7 -1
  90. data/test/acts_as_authentic_test/restful_authentication_test.rb +14 -3
  91. data/test/acts_as_authentic_test/session_maintenance_test.rb +69 -15
  92. data/test/acts_as_authentic_test/single_access_test.rb +3 -1
  93. data/test/adapter_test.rb +23 -0
  94. data/test/authenticates_many_test.rb +3 -1
  95. data/test/config_test.rb +11 -9
  96. data/test/crypto_provider_test/aes256_test.rb +3 -1
  97. data/test/crypto_provider_test/bcrypt_test.rb +3 -1
  98. data/test/crypto_provider_test/scrypt_test.rb +3 -1
  99. data/test/crypto_provider_test/sha1_test.rb +3 -1
  100. data/test/crypto_provider_test/sha256_test.rb +3 -1
  101. data/test/crypto_provider_test/sha512_test.rb +3 -1
  102. data/test/crypto_provider_test/wordpress_test.rb +26 -0
  103. data/test/fixtures/companies.yml +2 -2
  104. data/test/fixtures/employees.yml +1 -1
  105. data/test/i18n_test.rb +6 -4
  106. data/test/libs/affiliate.rb +2 -0
  107. data/test/libs/company.rb +4 -2
  108. data/test/libs/employee.rb +2 -0
  109. data/test/libs/employee_session.rb +2 -0
  110. data/test/libs/ldaper.rb +2 -0
  111. data/test/libs/project.rb +2 -0
  112. data/test/libs/user.rb +2 -0
  113. data/test/libs/user_session.rb +4 -2
  114. data/test/random_test.rb +10 -38
  115. data/test/session_test/activation_test.rb +3 -1
  116. data/test/session_test/active_record_trickery_test.rb +7 -4
  117. data/test/session_test/brute_force_protection_test.rb +11 -9
  118. data/test/session_test/callbacks_test.rb +12 -4
  119. data/test/session_test/cookies_test.rb +48 -5
  120. data/test/session_test/existence_test.rb +18 -5
  121. data/test/session_test/foundation_test.rb +19 -1
  122. data/test/session_test/http_auth_test.rb +11 -7
  123. data/test/session_test/id_test.rb +3 -1
  124. data/test/session_test/klass_test.rb +3 -1
  125. data/test/session_test/magic_columns_test.rb +13 -13
  126. data/test/session_test/magic_states_test.rb +3 -1
  127. data/test/session_test/params_test.rb +13 -5
  128. data/test/session_test/password_test.rb +10 -8
  129. data/test/session_test/perishability_test.rb +3 -1
  130. data/test/session_test/persistence_test.rb +4 -1
  131. data/test/session_test/scopes_test.rb +16 -8
  132. data/test/session_test/session_test.rb +6 -4
  133. data/test/session_test/timeout_test.rb +4 -2
  134. data/test/session_test/unauthorized_record_test.rb +4 -2
  135. data/test/session_test/validation_test.rb +3 -1
  136. data/test/test_helper.rb +84 -45
  137. metadata +87 -73
  138. data/.github/ISSUE_TEMPLATE.md +0 -13
  139. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  140. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  141. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
  142. data/test/gemfiles/Gemfile.rails-4.2.x +0 -7
  143. data/test/gemfiles/Gemfile.rails-5.0.x +0 -6
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
- gemspec :path => "./../.."
2
+ gemspec :path => ".."
3
3
 
4
4
  gem "activerecord", "~> 5.1.0"
5
5
  gem "activesupport", "~> 5.1.0"
6
- gem 'sqlite3', :platforms => :ruby
6
+ gem "sqlite3", "~> 1.3.6", platforms: :ruby
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
- gemspec :path => "./../.."
2
+ gemspec :path => ".."
3
3
 
4
4
  gem "activerecord", "~> 5.2.x"
5
5
  gem "activesupport", "~> 5.2.x"
6
- gem 'sqlite3', :platforms => :ruby
6
+ gem "sqlite3", "~> 1.3.6", platforms: :ruby
@@ -11,11 +11,13 @@ module Authlogic
11
11
  end
12
12
  end
13
13
 
14
+ # The primary configuration of a model (often, `User`) for use with
15
+ # authlogic. These methods become class methods of ::ActiveRecord::Base.
14
16
  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:
17
+ # This includes a lot of helpful methods for authenticating records
18
+ # which the Authlogic::Session module relies on. To use it just do:
17
19
  #
18
- # class User < ActiveRecord::Base
20
+ # class User < ApplicationRecord
19
21
  # acts_as_authentic
20
22
  # end
21
23
  #
@@ -26,11 +28,11 @@ module Authlogic
26
28
  # end
27
29
  #
28
30
  # See the various sub modules for the configuration they provide.
29
- def acts_as_authentic(unsupported_options = nil, &block)
31
+ def acts_as_authentic(unsupported_options = nil)
30
32
  # Stop all configuration if the DB is not set up
31
- return if !db_setup?
33
+ return unless db_setup?
32
34
 
33
- if !unsupported_options.nil?
35
+ unless unsupported_options.nil?
34
36
  raise ArgumentError.new(
35
37
  "You are using the old v1.X.X configuration method for " \
36
38
  "Authlogic. Instead of passing a hash of configuration " \
@@ -43,12 +45,15 @@ module Authlogic
43
45
  acts_as_authentic_modules.each { |mod| include mod }
44
46
  end
45
47
 
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.
48
+ # Since this part of Authlogic deals with another class, ActiveRecord,
49
+ # we can't just start including things in ActiveRecord itself. A lot of
50
+ # these module includes need to be triggered by the acts_as_authentic
51
+ # method call. For example, you don't want to start adding in email
52
+ # validations and what not into a model that has nothing to do with
53
+ # Authlogic.
50
54
  #
51
- # That being said, this is your tool for extending Authlogic and "hooking" into the acts_as_authentic call.
55
+ # That being said, this is your tool for extending Authlogic and
56
+ # "hooking" into the acts_as_authentic call.
52
57
  def add_acts_as_authentic_module(mod, action = :append)
53
58
  modules = acts_as_authentic_modules.clone
54
59
  case action
@@ -61,7 +66,8 @@ module Authlogic
61
66
  self.acts_as_authentic_modules = modules
62
67
  end
63
68
 
64
- # This is the same as add_acts_as_authentic_module, except that it removes the module from the list.
69
+ # This is the same as add_acts_as_authentic_module, except that it
70
+ # removes the module from the list.
65
71
  def remove_acts_as_authentic_module(mod)
66
72
  modules = acts_as_authentic_modules.clone
67
73
  modules.delete(mod)
@@ -70,21 +76,23 @@ module Authlogic
70
76
 
71
77
  private
72
78
 
73
- def db_setup?
74
- begin
75
- column_names
76
- true
77
- rescue StandardError
78
- false
79
- end
80
- end
79
+ def db_setup?
80
+ column_names
81
+ true
82
+ rescue StandardError
83
+ false
84
+ end
81
85
 
82
- def first_column_to_exist(*columns_to_check)
83
- if db_setup?
84
- columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
86
+ def first_column_to_exist(*columns_to_check)
87
+ if db_setup?
88
+ columns_to_check.each do |column_name|
89
+ if column_names.include?(column_name.to_s)
90
+ return column_name.to_sym
91
+ end
85
92
  end
86
- columns_to_check.first && columns_to_check.first.to_sym
87
93
  end
94
+ columns_to_check.first&.to_sym
95
+ end
88
96
  end
89
97
  end
90
98
  end
@@ -98,7 +106,11 @@ end
98
106
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Password
99
107
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PerishableToken
100
108
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PersistenceToken
109
+
110
+ # RestfulAuthentication is deprecated. See comments in
111
+ # acts_as_authentic/restful_authentication.rb
101
112
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication
113
+
102
114
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance
103
115
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken
104
116
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::ValidationsScope
@@ -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
@@ -27,33 +28,49 @@ module Authlogic
27
28
  #
28
29
  # * <tt>Default:</tt> true
29
30
  # * <tt>Accepts:</tt> Boolean
31
+ #
32
+ # @deprecated
30
33
  def validate_email_field(value = nil)
31
34
  rw_config(:validate_email_field, value, true)
32
35
  end
33
36
  alias_method :validate_email_field=, :validate_email_field
34
37
 
35
- # A hash of options for the validates_length_of call for the email field. Allows you to change this however you want.
38
+ # A hash of options for the validates_length_of call for the email
39
+ # field. Allows you to change this however you want.
36
40
  #
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>
41
+ # <b>Keep in mind this is ruby. I wanted to keep this as flexible as
42
+ # possible, so you can completely replace the hash or merge options into
43
+ # it. Checkout the convenience function
44
+ # merge_validates_length_of_email_field_options to merge options.</b>
40
45
  #
41
46
  # * <tt>Default:</tt> {:maximum => 100}
42
47
  # * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
48
+ #
49
+ # @deprecated
43
50
  def validates_length_of_email_field_options(value = nil)
44
- rw_config(:validates_length_of_email_field_options, value, { :maximum => 100 })
51
+ deprecate_authlogic_config("validates_length_of_email_field_options") if value
52
+ rw_config(:validates_length_of_email_field_options, value, maximum: 100)
45
53
  end
46
- alias_method :validates_length_of_email_field_options=, :validates_length_of_email_field_options
54
+ alias_method(
55
+ :validates_length_of_email_field_options=,
56
+ :validates_length_of_email_field_options
57
+ )
47
58
 
48
- # A convenience function to merge options into the validates_length_of_email_field_options. So instead of:
59
+ # A convenience function to merge options into the
60
+ # validates_length_of_email_field_options. So instead of:
49
61
  #
50
- # self.validates_length_of_email_field_options = validates_length_of_email_field_options.merge(:my_option => my_value)
62
+ # self.validates_length_of_email_field_options =
63
+ # validates_length_of_email_field_options.merge(:my_option => my_value)
51
64
  #
52
65
  # You can do this:
53
66
  #
54
67
  # merge_validates_length_of_email_field_options :my_option => my_value
68
+ #
69
+ # @deprecated
55
70
  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)
71
+ deprecate_authlogic_config("merge_validates_length_of_email_field_options")
72
+ self.validates_length_of_email_field_options =
73
+ validates_length_of_email_field_options.merge(options)
57
74
  end
58
75
 
59
76
  # A hash of options for the validates_format_of call for the email
@@ -67,7 +84,11 @@ module Authlogic
67
84
  # To validate international email addresses, enable the provided
68
85
  # alternate regex:
69
86
  #
70
- # * <tt>validates_format_of_email_field_options({:with => Authlogic::Regex.email_nonascii})</tt>
87
+ # ```
88
+ # validates_format_of_email_field_options(
89
+ # with: Authlogic::Regex.email_nonascii
90
+ # )
91
+ # ```
71
92
  #
72
93
  # * <tt>Default:</tt>
73
94
  #
@@ -82,26 +103,35 @@ module Authlogic
82
103
  # }
83
104
  #
84
105
  # * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
106
+ #
107
+ # @deprecated
85
108
  def validates_format_of_email_field_options(value = nil)
109
+ deprecate_authlogic_config("validates_format_of_email_field_options") if value
86
110
  rw_config(
87
111
  :validates_format_of_email_field_options,
88
112
  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
- }
113
+ with: Authlogic::Regex::EMAIL,
114
+ message: proc do
115
+ I18n.t(
116
+ "error_messages.email_invalid",
117
+ default: "should look like an email address."
118
+ )
119
+ end
98
120
  )
99
121
  end
100
- alias_method :validates_format_of_email_field_options=, :validates_format_of_email_field_options
122
+ alias_method(
123
+ :validates_format_of_email_field_options=,
124
+ :validates_format_of_email_field_options
125
+ )
101
126
 
102
- # See merge_validates_length_of_email_field_options. The same thing except for validates_format_of_email_field_options.
127
+ # See merge_validates_length_of_email_field_options. The same thing
128
+ # except for validates_format_of_email_field_options.
129
+ #
130
+ # @deprecated
103
131
  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)
132
+ deprecate_authlogic_config("merge_validates_format_of_email_field_options")
133
+ self.validates_format_of_email_field_options =
134
+ validates_format_of_email_field_options.merge(options)
105
135
  end
106
136
 
107
137
  # A hash of options for the validates_uniqueness_of call for the email
@@ -122,15 +152,16 @@ module Authlogic
122
152
  # }
123
153
  #
124
154
  # * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
155
+ #
156
+ # @deprecated
125
157
  def validates_uniqueness_of_email_field_options(value = nil)
158
+ deprecate_authlogic_config("validates_uniqueness_of_email_field_options") if value
126
159
  rw_config(
127
160
  :validates_uniqueness_of_email_field_options,
128
161
  value,
129
- {
130
- :case_sensitive => false,
131
- :scope => validations_scope,
132
- :if => "#{email_field}_changed?".to_sym
133
- }
162
+ case_sensitive: false,
163
+ scope: validations_scope,
164
+ if: "#{email_field}_changed?".to_sym
134
165
  )
135
166
  end
136
167
  alias_method(
@@ -140,7 +171,10 @@ module Authlogic
140
171
 
141
172
  # See merge_validates_length_of_email_field_options. The same thing
142
173
  # except for validates_uniqueness_of_email_field_options.
174
+ #
175
+ # @deprecated
143
176
  def merge_validates_uniqueness_of_email_field_options(options = {})
177
+ deprecate_authlogic_config("merge_validates_uniqueness_of_email_field_options")
144
178
  self.validates_uniqueness_of_email_field_options =
145
179
  validates_uniqueness_of_email_field_options.merge(options)
146
180
  end
@@ -1,9 +1,10 @@
1
1
  module Authlogic
2
2
  module ActsAsAuthentic
3
- # Since web applications are stateless there is not sure fire way to tell if a user is logged in or not,
4
- # from the database perspective. The best way to do this is to provide a "timeout" based on inactivity.
5
- # So if that user is inactive for a certain amount of time we assume they are logged out. That's what this
6
- # module is all about.
3
+ # Since web applications are stateless there is not sure fire way to tell if
4
+ # a user is logged in or not, from the database perspective. The best way to
5
+ # do this is to provide a "timeout" based on inactivity. So if that user is
6
+ # inactive for a certain amount of time we assume they are logged out.
7
+ # That's what this module is all about.
7
8
  module LoggedInStatus
8
9
  def self.included(klass)
9
10
  klass.class_eval do
@@ -27,7 +28,7 @@ module Authlogic
27
28
  # All methods for the logged in status feature seat.
28
29
  module Methods
29
30
  def self.included(klass)
30
- return if !klass.column_names.include?("last_request_at")
31
+ return unless klass.column_names.include?("last_request_at")
31
32
 
32
33
  klass.class_eval do
33
34
  include InstanceMethods
@@ -52,11 +53,15 @@ module Authlogic
52
53
  end
53
54
  end
54
55
 
56
+ # :nodoc:
55
57
  module InstanceMethods
56
58
  # Returns true if the last_request_at > logged_in_timeout.
57
59
  def logged_in?
58
60
  unless respond_to?(:last_request_at)
59
- raise "Can not determine the records login state because there is no last_request_at column"
61
+ raise(
62
+ "Can not determine the records login state because " \
63
+ "there is no last_request_at column"
64
+ )
60
65
  end
61
66
  !last_request_at.nil? && last_request_at > logged_in_timeout.seconds.ago
62
67
  end
@@ -68,9 +73,9 @@ module Authlogic
68
73
 
69
74
  private
70
75
 
71
- def logged_in_timeout
72
- self.class.logged_in_timeout
73
- end
76
+ def logged_in_timeout
77
+ self.class.logged_in_timeout
78
+ end
74
79
  end
75
80
  end
76
81
  end
@@ -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.
@@ -24,6 +26,8 @@ module Authlogic
24
26
  #
25
27
  # * <tt>Default:</tt> true
26
28
  # * <tt>Accepts:</tt> Boolean
29
+ #
30
+ # @deprecated
27
31
  def validate_login_field(value = nil)
28
32
  rw_config(:validate_login_field, value, true)
29
33
  end
@@ -39,10 +43,16 @@ module Authlogic
39
43
  #
40
44
  # * <tt>Default:</tt> {:within => 3..100}
41
45
  # * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
46
+ #
47
+ # @deprecated
42
48
  def validates_length_of_login_field_options(value = nil)
43
- rw_config(:validates_length_of_login_field_options, value, { :within => 3..100 })
49
+ deprecate_authlogic_config("validates_length_of_login_field_options") if value
50
+ rw_config(:validates_length_of_login_field_options, value, within: 3..100)
44
51
  end
45
- alias_method :validates_length_of_login_field_options=, :validates_length_of_login_field_options
52
+ alias_method(
53
+ :validates_length_of_login_field_options=,
54
+ :validates_length_of_login_field_options
55
+ )
46
56
 
47
57
  # A convenience function to merge options into the
48
58
  # validates_length_of_login_field_options. So instead of:
@@ -53,8 +63,12 @@ module Authlogic
53
63
  # You can do this:
54
64
  #
55
65
  # merge_validates_length_of_login_field_options :my_option => my_value
66
+ #
67
+ # @deprecated
56
68
  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)
69
+ deprecate_authlogic_config("merge_validates_length_of_login_field_options")
70
+ self.validates_length_of_login_field_options =
71
+ validates_length_of_login_field_options.merge(options)
58
72
  end
59
73
 
60
74
  # A hash of options for the validates_format_of call for the login
@@ -78,27 +92,35 @@ module Authlogic
78
92
  # }
79
93
  #
80
94
  # * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
95
+ #
96
+ # @deprecated
81
97
  def validates_format_of_login_field_options(value = nil)
98
+ deprecate_authlogic_config("validates_format_of_login_field_options") if value
82
99
  rw_config(
83
100
  :validates_format_of_login_field_options,
84
101
  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
- }
102
+ with: Authlogic::Regex::LOGIN,
103
+ message: proc do
104
+ I18n.t(
105
+ "error_messages.login_invalid",
106
+ default: "should use only letters, numbers, spaces, and .-_@+ please."
107
+ )
108
+ end
94
109
  )
95
110
  end
96
- alias_method :validates_format_of_login_field_options=, :validates_format_of_login_field_options
111
+ alias_method(
112
+ :validates_format_of_login_field_options=,
113
+ :validates_format_of_login_field_options
114
+ )
97
115
 
98
116
  # See merge_validates_length_of_login_field_options. The same thing,
99
117
  # except for validates_format_of_login_field_options
118
+ #
119
+ # @deprecated
100
120
  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)
121
+ deprecate_authlogic_config("merge_validates_format_of_login_field_options")
122
+ self.validates_format_of_login_field_options =
123
+ validates_format_of_login_field_options.merge(options)
102
124
  end
103
125
 
104
126
  # A hash of options for the validates_uniqueness_of call for the login
@@ -118,15 +140,16 @@ module Authlogic
118
140
  # }
119
141
  #
120
142
  # * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
143
+ #
144
+ # @deprecated
121
145
  def validates_uniqueness_of_login_field_options(value = nil)
146
+ deprecate_authlogic_config("validates_uniqueness_of_login_field_options") if value
122
147
  rw_config(
123
148
  :validates_uniqueness_of_login_field_options,
124
149
  value,
125
- {
126
- :case_sensitive => false,
127
- :scope => validations_scope,
128
- :if => "#{login_field}_changed?".to_sym
129
- }
150
+ case_sensitive: false,
151
+ scope: validations_scope,
152
+ if: "#{login_field}_changed?".to_sym
130
153
  )
131
154
  end
132
155
  alias_method(
@@ -136,7 +159,10 @@ module Authlogic
136
159
 
137
160
  # See merge_validates_length_of_login_field_options. The same thing,
138
161
  # except for validates_uniqueness_of_login_field_options
162
+ #
163
+ # @deprecated
139
164
  def merge_validates_uniqueness_of_login_field_options(options = {})
165
+ deprecate_authlogic_config("merge_validates_uniqueness_of_login_field_options")
140
166
  self.validates_uniqueness_of_login_field_options =
141
167
  validates_uniqueness_of_login_field_options.merge(options)
142
168
  end
@@ -160,40 +186,30 @@ module Authlogic
160
186
  # The above also applies for using email as your login, except that you
161
187
  # need to set the :case_sensitive in
162
188
  # validates_uniqueness_of_email_field_options to false.
189
+ #
190
+ # @api public
163
191
  def find_by_smart_case_login_field(login)
164
192
  if login_field
165
- find_with_case(login_field, login, validates_uniqueness_of_login_field_options[:case_sensitive] != false)
193
+ find_with_case(
194
+ login_field,
195
+ login,
196
+ validates_uniqueness_of_login_field_options[:case_sensitive] != false
197
+ )
166
198
  else
167
- find_with_case(email_field, login, validates_uniqueness_of_email_field_options[:case_sensitive] != false)
199
+ find_with_case(
200
+ email_field,
201
+ login,
202
+ validates_uniqueness_of_email_field_options[:case_sensitive] != false
203
+ )
168
204
  end
169
205
  end
170
206
 
171
207
  private
172
208
 
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
196
- end
209
+ # @api private
210
+ def find_with_case(field, value, sensitive)
211
+ Queries::FindWithCase.new(self, field, value, sensitive).execute
212
+ end
197
213
  end
198
214
 
199
215
  # All methods relating to the login field
@@ -17,15 +17,15 @@ module Authlogic
17
17
  klass.class_eval do
18
18
  if column_names.include?("login_count")
19
19
  validates_numericality_of :login_count,
20
- :only_integer => true,
21
- :greater_than_or_equal_to => 0,
22
- :allow_nil => true
20
+ only_integer: true,
21
+ greater_than_or_equal_to: 0,
22
+ allow_nil: true
23
23
  end
24
24
  if column_names.include?("failed_login_count")
25
25
  validates_numericality_of :failed_login_count,
26
- :only_integer => true,
27
- :greater_than_or_equal_to => 0,
28
- :allow_nil => true
26
+ only_integer: true,
27
+ greater_than_or_equal_to: 0,
28
+ allow_nil: true
29
29
  end
30
30
  end
31
31
  end