authlogic 3.8.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
- data/.github/ISSUE_TEMPLATE/feature_proposal.md +32 -0
- data/.github/triage.md +86 -0
- data/.gitignore +4 -3
- data/.rubocop.yml +109 -9
- data/.rubocop_todo.yml +38 -355
- data/.travis.yml +11 -35
- data/CHANGELOG.md +345 -2
- data/CONTRIBUTING.md +45 -14
- data/Gemfile +3 -2
- data/README.md +244 -90
- data/Rakefile +10 -10
- data/UPGRADING.md +22 -0
- data/authlogic.gemspec +34 -21
- data/doc/use_normal_rails_validation.md +82 -0
- data/gemfiles/Gemfile.rails-4.2.x +6 -0
- data/{test/gemfiles → gemfiles}/Gemfile.rails-5.1.x +2 -2
- data/{test/gemfiles → gemfiles}/Gemfile.rails-5.2.x +2 -2
- data/lib/authlogic/acts_as_authentic/base.rb +36 -24
- data/lib/authlogic/acts_as_authentic/email.rb +65 -31
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +14 -9
- data/lib/authlogic/acts_as_authentic/login.rb +61 -45
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
- data/lib/authlogic/acts_as_authentic/password.rb +267 -146
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +24 -19
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -15
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +67 -0
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +50 -14
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +88 -60
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +23 -11
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +9 -6
- data/lib/authlogic/authenticates_many/association.rb +7 -7
- data/lib/authlogic/authenticates_many/base.rb +37 -21
- data/lib/authlogic/config.rb +21 -10
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +38 -11
- data/lib/authlogic/controller_adapters/rack_adapter.rb +9 -5
- data/lib/authlogic/controller_adapters/rails_adapter.rb +12 -7
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +2 -2
- data/lib/authlogic/crypto_providers/aes256.rb +37 -32
- data/lib/authlogic/crypto_providers/bcrypt.rb +21 -15
- data/lib/authlogic/crypto_providers/md5.rb +4 -2
- data/lib/authlogic/crypto_providers/scrypt.rb +22 -17
- data/lib/authlogic/crypto_providers/sha1.rb +11 -5
- data/lib/authlogic/crypto_providers/sha256.rb +13 -9
- data/lib/authlogic/crypto_providers/sha512.rb +0 -21
- data/lib/authlogic/crypto_providers/wordpress.rb +32 -3
- data/lib/authlogic/crypto_providers.rb +91 -0
- data/lib/authlogic/i18n.rb +26 -19
- data/lib/authlogic/random.rb +10 -28
- data/lib/authlogic/regex.rb +59 -28
- data/lib/authlogic/session/activation.rb +10 -7
- 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 +40 -33
- data/lib/authlogic/session/callbacks.rb +94 -46
- data/lib/authlogic/session/cookies.rb +130 -45
- data/lib/authlogic/session/existence.rb +21 -11
- data/lib/authlogic/session/foundation.rb +64 -14
- data/lib/authlogic/session/http_auth.rb +35 -28
- data/lib/authlogic/session/id.rb +9 -4
- data/lib/authlogic/session/klass.rb +15 -12
- data/lib/authlogic/session/magic_columns.rb +58 -55
- data/lib/authlogic/session/magic_states.rb +25 -19
- data/lib/authlogic/session/params.rb +42 -28
- data/lib/authlogic/session/password.rb +130 -120
- data/lib/authlogic/session/perishable_token.rb +5 -4
- data/lib/authlogic/session/persistence.rb +18 -12
- data/lib/authlogic/session/priority_record.rb +15 -12
- data/lib/authlogic/session/scopes.rb +51 -32
- data/lib/authlogic/session/session.rb +38 -28
- data/lib/authlogic/session/timeout.rb +13 -13
- data/lib/authlogic/session/unauthorized_record.rb +18 -13
- data/lib/authlogic/session/validation.rb +9 -9
- data/lib/authlogic/test_case/mock_controller.rb +5 -4
- data/lib/authlogic/test_case/mock_cookie_jar.rb +47 -3
- data/lib/authlogic/test_case/mock_request.rb +6 -3
- data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
- data/lib/authlogic/test_case.rb +70 -2
- data/lib/authlogic/version.rb +21 -0
- data/lib/authlogic.rb +51 -49
- data/test/acts_as_authentic_test/base_test.rb +3 -1
- data/test/acts_as_authentic_test/email_test.rb +43 -42
- data/test/acts_as_authentic_test/logged_in_status_test.rb +6 -4
- data/test/acts_as_authentic_test/login_test.rb +77 -80
- data/test/acts_as_authentic_test/magic_columns_test.rb +3 -1
- data/test/acts_as_authentic_test/password_test.rb +51 -37
- data/test/acts_as_authentic_test/perishable_token_test.rb +13 -5
- data/test/acts_as_authentic_test/persistence_token_test.rb +7 -1
- data/test/acts_as_authentic_test/restful_authentication_test.rb +14 -3
- data/test/acts_as_authentic_test/session_maintenance_test.rb +69 -15
- data/test/acts_as_authentic_test/single_access_test.rb +3 -1
- data/test/adapter_test.rb +23 -0
- data/test/authenticates_many_test.rb +3 -1
- data/test/config_test.rb +11 -9
- data/test/crypto_provider_test/aes256_test.rb +3 -1
- data/test/crypto_provider_test/bcrypt_test.rb +3 -1
- data/test/crypto_provider_test/scrypt_test.rb +3 -1
- data/test/crypto_provider_test/sha1_test.rb +3 -1
- data/test/crypto_provider_test/sha256_test.rb +3 -1
- data/test/crypto_provider_test/sha512_test.rb +3 -1
- data/test/crypto_provider_test/wordpress_test.rb +26 -0
- data/test/fixtures/companies.yml +2 -2
- data/test/fixtures/employees.yml +1 -1
- data/test/i18n_test.rb +6 -4
- data/test/libs/affiliate.rb +2 -0
- data/test/libs/company.rb +4 -2
- data/test/libs/employee.rb +2 -0
- data/test/libs/employee_session.rb +2 -0
- data/test/libs/ldaper.rb +2 -0
- data/test/libs/project.rb +2 -0
- data/test/libs/user.rb +2 -0
- data/test/libs/user_session.rb +4 -2
- data/test/random_test.rb +10 -38
- data/test/session_test/activation_test.rb +3 -1
- data/test/session_test/active_record_trickery_test.rb +7 -4
- data/test/session_test/brute_force_protection_test.rb +11 -9
- data/test/session_test/callbacks_test.rb +12 -4
- data/test/session_test/cookies_test.rb +48 -5
- data/test/session_test/existence_test.rb +18 -5
- data/test/session_test/foundation_test.rb +19 -1
- data/test/session_test/http_auth_test.rb +11 -7
- data/test/session_test/id_test.rb +3 -1
- data/test/session_test/klass_test.rb +3 -1
- data/test/session_test/magic_columns_test.rb +13 -13
- data/test/session_test/magic_states_test.rb +3 -1
- data/test/session_test/params_test.rb +13 -5
- data/test/session_test/password_test.rb +10 -8
- data/test/session_test/perishability_test.rb +3 -1
- data/test/session_test/persistence_test.rb +4 -1
- data/test/session_test/scopes_test.rb +16 -8
- data/test/session_test/session_test.rb +6 -4
- data/test/session_test/timeout_test.rb +4 -2
- data/test/session_test/unauthorized_record_test.rb +4 -2
- data/test/session_test/validation_test.rb +3 -1
- data/test/test_helper.rb +84 -45
- metadata +87 -73
- data/.github/ISSUE_TEMPLATE.md +0 -13
- 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/test/gemfiles/Gemfile.rails-4.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-5.0.x +0 -6
@@ -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
|
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 <
|
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
|
31
|
+
def acts_as_authentic(unsupported_options = nil)
|
30
32
|
# Stop all configuration if the DB is not set up
|
31
|
-
return
|
33
|
+
return unless db_setup?
|
32
34
|
|
33
|
-
|
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,
|
47
|
-
# in ActiveRecord itself. A lot of
|
48
|
-
#
|
49
|
-
#
|
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
|
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
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
79
|
+
def db_setup?
|
80
|
+
column_names
|
81
|
+
true
|
82
|
+
rescue StandardError
|
83
|
+
false
|
84
|
+
end
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
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.
|
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
|
@@ -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
|
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
|
38
|
-
#
|
39
|
-
#
|
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
|
-
|
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
|
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
|
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 =
|
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
|
-
|
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
|
-
#
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
131
|
-
|
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
|
4
|
-
# from the database perspective. The best way to
|
5
|
-
#
|
6
|
-
#
|
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
|
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
|
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
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
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
|
-
|
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
|
-
|
127
|
-
|
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(
|
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(
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
-
:
|
21
|
-
:
|
22
|
-
:
|
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
|
-
:
|
27
|
-
:
|
28
|
-
:
|
26
|
+
only_integer: true,
|
27
|
+
greater_than_or_equal_to: 0,
|
28
|
+
allow_nil: true
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|