authlogic 4.4.2 → 5.0.3
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 +5 -5
- data/lib/authlogic.rb +4 -28
- data/lib/authlogic/acts_as_authentic/base.rb +3 -18
- data/lib/authlogic/acts_as_authentic/email.rb +3 -170
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +3 -1
- data/lib/authlogic/acts_as_authentic/login.rb +7 -174
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +7 -4
- data/lib/authlogic/acts_as_authentic/password.rb +54 -253
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +8 -5
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -4
- data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +36 -20
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +8 -6
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +10 -8
- data/lib/authlogic/config.rb +9 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +7 -4
- data/lib/authlogic/controller_adapters/rack_adapter.rb +2 -0
- data/lib/authlogic/controller_adapters/rails_adapter.rb +19 -19
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +6 -0
- data/lib/authlogic/cookie_credentials.rb +63 -0
- data/lib/authlogic/crypto_providers.rb +5 -20
- data/lib/authlogic/crypto_providers/bcrypt.rb +3 -3
- data/lib/authlogic/crypto_providers/md5.rb +3 -6
- data/lib/authlogic/crypto_providers/scrypt.rb +2 -0
- data/lib/authlogic/crypto_providers/sha1.rb +4 -6
- data/lib/authlogic/crypto_providers/sha256.rb +2 -0
- data/lib/authlogic/crypto_providers/sha512.rb +6 -5
- data/lib/authlogic/i18n.rb +3 -1
- data/lib/authlogic/i18n/translator.rb +3 -0
- data/lib/authlogic/random.rb +2 -0
- data/lib/authlogic/session/base.rb +2087 -39
- data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
- data/lib/authlogic/test_case.rb +4 -0
- data/lib/authlogic/test_case/mock_controller.rb +2 -0
- data/lib/authlogic/test_case/mock_cookie_jar.rb +7 -0
- data/lib/authlogic/test_case/mock_logger.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +2 -0
- data/lib/authlogic/test_case/rails_request_adapter.rb +2 -0
- data/lib/authlogic/version.rb +2 -1
- metadata +136 -182
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
- data/.github/ISSUE_TEMPLATE/feature_proposal.md +0 -32
- data/.github/triage.md +0 -86
- data/.gitignore +0 -15
- data/.rubocop.yml +0 -133
- data/.rubocop_todo.yml +0 -74
- data/.travis.yml +0 -24
- data/CHANGELOG.md +0 -326
- data/CONTRIBUTING.md +0 -91
- data/Gemfile +0 -6
- data/LICENSE +0 -20
- data/README.md +0 -439
- data/Rakefile +0 -21
- data/UPGRADING.md +0 -22
- data/authlogic.gemspec +0 -40
- data/doc/use_normal_rails_validation.md +0 -82
- data/gemfiles/Gemfile.rails-4.2.x +0 -6
- data/gemfiles/Gemfile.rails-5.1.x +0 -6
- data/gemfiles/Gemfile.rails-5.2.x +0 -6
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -106
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -35
- data/lib/authlogic/authenticates_many/association.rb +0 -50
- data/lib/authlogic/authenticates_many/base.rb +0 -81
- data/lib/authlogic/crypto_providers/aes256.rb +0 -71
- data/lib/authlogic/crypto_providers/wordpress.rb +0 -72
- data/lib/authlogic/regex.rb +0 -79
- data/lib/authlogic/session/activation.rb +0 -73
- data/lib/authlogic/session/active_record_trickery.rb +0 -65
- data/lib/authlogic/session/brute_force_protection.rb +0 -127
- data/lib/authlogic/session/callbacks.rb +0 -153
- data/lib/authlogic/session/cookies.rb +0 -296
- data/lib/authlogic/session/existence.rb +0 -103
- data/lib/authlogic/session/foundation.rb +0 -105
- data/lib/authlogic/session/http_auth.rb +0 -107
- data/lib/authlogic/session/id.rb +0 -53
- data/lib/authlogic/session/klass.rb +0 -73
- data/lib/authlogic/session/magic_columns.rb +0 -119
- data/lib/authlogic/session/magic_states.rb +0 -82
- data/lib/authlogic/session/params.rb +0 -130
- data/lib/authlogic/session/password.rb +0 -318
- data/lib/authlogic/session/perishable_token.rb +0 -24
- data/lib/authlogic/session/persistence.rb +0 -77
- data/lib/authlogic/session/priority_record.rb +0 -38
- data/lib/authlogic/session/scopes.rb +0 -138
- data/lib/authlogic/session/session.rb +0 -77
- data/lib/authlogic/session/timeout.rb +0 -103
- data/lib/authlogic/session/unauthorized_record.rb +0 -56
- data/lib/authlogic/session/validation.rb +0 -93
- data/test/acts_as_authentic_test/base_test.rb +0 -27
- data/test/acts_as_authentic_test/email_test.rb +0 -241
- data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -64
- data/test/acts_as_authentic_test/login_test.rb +0 -153
- data/test/acts_as_authentic_test/magic_columns_test.rb +0 -29
- data/test/acts_as_authentic_test/password_test.rb +0 -263
- data/test/acts_as_authentic_test/perishable_token_test.rb +0 -98
- data/test/acts_as_authentic_test/persistence_token_test.rb +0 -62
- data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -48
- data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -150
- data/test/acts_as_authentic_test/single_access_test.rb +0 -46
- data/test/adapter_test.rb +0 -23
- data/test/authenticates_many_test.rb +0 -33
- data/test/config_test.rb +0 -38
- data/test/crypto_provider_test/aes256_test.rb +0 -16
- data/test/crypto_provider_test/bcrypt_test.rb +0 -16
- data/test/crypto_provider_test/scrypt_test.rb +0 -16
- data/test/crypto_provider_test/sha1_test.rb +0 -25
- data/test/crypto_provider_test/sha256_test.rb +0 -16
- data/test/crypto_provider_test/sha512_test.rb +0 -16
- data/test/crypto_provider_test/wordpress_test.rb +0 -26
- data/test/fixtures/companies.yml +0 -5
- data/test/fixtures/employees.yml +0 -17
- data/test/fixtures/projects.yml +0 -3
- data/test/fixtures/users.yml +0 -41
- data/test/i18n/lol.yml +0 -4
- data/test/i18n_test.rb +0 -35
- data/test/libs/affiliate.rb +0 -9
- data/test/libs/company.rb +0 -8
- data/test/libs/employee.rb +0 -9
- data/test/libs/employee_session.rb +0 -4
- data/test/libs/ldaper.rb +0 -5
- data/test/libs/project.rb +0 -5
- data/test/libs/user.rb +0 -9
- data/test/libs/user_session.rb +0 -27
- data/test/random_test.rb +0 -15
- data/test/session_test/activation_test.rb +0 -45
- data/test/session_test/active_record_trickery_test.rb +0 -78
- data/test/session_test/brute_force_protection_test.rb +0 -110
- data/test/session_test/callbacks_test.rb +0 -42
- data/test/session_test/cookies_test.rb +0 -226
- data/test/session_test/credentials_test.rb +0 -0
- data/test/session_test/existence_test.rb +0 -88
- data/test/session_test/foundation_test.rb +0 -24
- data/test/session_test/http_auth_test.rb +0 -60
- data/test/session_test/id_test.rb +0 -19
- data/test/session_test/klass_test.rb +0 -42
- data/test/session_test/magic_columns_test.rb +0 -62
- data/test/session_test/magic_states_test.rb +0 -60
- data/test/session_test/params_test.rb +0 -61
- data/test/session_test/password_test.rb +0 -107
- data/test/session_test/perishability_test.rb +0 -17
- data/test/session_test/persistence_test.rb +0 -35
- data/test/session_test/scopes_test.rb +0 -68
- data/test/session_test/session_test.rb +0 -80
- data/test/session_test/timeout_test.rb +0 -84
- data/test/session_test/unauthorized_record_test.rb +0 -15
- data/test/session_test/validation_test.rb +0 -25
- data/test/test_helper.rb +0 -272
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c45e9cdc0ba30a2e68a34791e72d4f52f2bbc21266ffcd259d5e82ba2d0bd30e
|
4
|
+
data.tar.gz: 84934beca4e75a60b104933ba59210f091f5cc83b5b3d36ec537d34fbe6b2e34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 121dff7866f1bb504176b02e79f6117c6162c61fc5ab8bed9e6b99fd199f5227a8de96f43c30e5a41eae93dce6500260bf05b93b50a598c1675b2d9c705cc0f9
|
7
|
+
data.tar.gz: 8c6f859285eb38a95c8e5618a8177fe711a5b0153503a9fd9f964f18fd85128f1ec2745dbd88154bdc4c9dda344c7b7cfc5facd5cd7ad64b0511c94d721603c1
|
data/lib/authlogic.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Authlogic uses ActiveSupport's core extensions like `strip_heredoc` and
|
2
4
|
# `squish`. ActiveRecord does not `require` these exensions, so we must.
|
3
5
|
#
|
@@ -13,16 +15,13 @@ path = File.dirname(__FILE__) + "/authlogic/"
|
|
13
15
|
[
|
14
16
|
"i18n",
|
15
17
|
"random",
|
16
|
-
"regex",
|
17
18
|
"config",
|
18
19
|
|
19
20
|
"controller_adapters/abstract_adapter",
|
21
|
+
"cookie_credentials",
|
20
22
|
|
21
23
|
"crypto_providers",
|
22
24
|
|
23
|
-
"authenticates_many/base",
|
24
|
-
"authenticates_many/association",
|
25
|
-
|
26
25
|
"acts_as_authentic/email",
|
27
26
|
"acts_as_authentic/logged_in_status",
|
28
27
|
"acts_as_authentic/login",
|
@@ -30,34 +29,11 @@ path = File.dirname(__FILE__) + "/authlogic/"
|
|
30
29
|
"acts_as_authentic/password",
|
31
30
|
"acts_as_authentic/perishable_token",
|
32
31
|
"acts_as_authentic/persistence_token",
|
33
|
-
"acts_as_authentic/restful_authentication",
|
34
32
|
"acts_as_authentic/session_maintenance",
|
35
33
|
"acts_as_authentic/single_access_token",
|
36
|
-
"acts_as_authentic/validations_scope",
|
37
34
|
"acts_as_authentic/base",
|
38
35
|
|
39
|
-
"session/
|
40
|
-
"session/active_record_trickery",
|
41
|
-
"session/brute_force_protection",
|
42
|
-
"session/callbacks",
|
43
|
-
"session/cookies",
|
44
|
-
"session/existence",
|
45
|
-
"session/foundation",
|
46
|
-
"session/http_auth",
|
47
|
-
"session/id",
|
48
|
-
"session/klass",
|
49
|
-
"session/magic_columns",
|
50
|
-
"session/magic_states",
|
51
|
-
"session/params",
|
52
|
-
"session/password",
|
53
|
-
"session/perishable_token",
|
54
|
-
"session/persistence",
|
55
|
-
"session/priority_record",
|
56
|
-
"session/scopes",
|
57
|
-
"session/session",
|
58
|
-
"session/timeout",
|
59
|
-
"session/unauthorized_record",
|
60
|
-
"session/validation",
|
36
|
+
"session/magic_column/assigns_last_request_at",
|
61
37
|
"session/base"
|
62
38
|
].each do |library|
|
63
39
|
require path + library
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
5
|
# Provides the base functionality for acts_as_authentic
|
@@ -28,19 +30,8 @@ module Authlogic
|
|
28
30
|
# end
|
29
31
|
#
|
30
32
|
# See the various sub modules for the configuration they provide.
|
31
|
-
def acts_as_authentic
|
32
|
-
# Stop all configuration if the DB is not set up
|
33
|
+
def acts_as_authentic
|
33
34
|
return unless db_setup?
|
34
|
-
|
35
|
-
unless unsupported_options.nil?
|
36
|
-
raise ArgumentError.new(
|
37
|
-
"You are using the old v1.X.X configuration method for " \
|
38
|
-
"Authlogic. Instead of passing a hash of configuration " \
|
39
|
-
"options to acts_as_authentic, pass a block: " \
|
40
|
-
"acts_as_authentic { |c| c.my_option = my_value }"
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
35
|
yield self if block_given?
|
45
36
|
acts_as_authentic_modules.each { |mod| include mod }
|
46
37
|
end
|
@@ -106,11 +97,5 @@ end
|
|
106
97
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Password
|
107
98
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PerishableToken
|
108
99
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PersistenceToken
|
109
|
-
|
110
|
-
# RestfulAuthentication is deprecated. See comments in
|
111
|
-
# acts_as_authentic/restful_authentication.rb
|
112
|
-
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication
|
113
|
-
|
114
100
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance
|
115
101
|
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken
|
116
|
-
::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::ValidationsScope
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
5
|
# Sometimes models won't have an explicit "login" or "username" field.
|
@@ -9,7 +11,6 @@ module Authlogic
|
|
9
11
|
def self.included(klass)
|
10
12
|
klass.class_eval do
|
11
13
|
extend Config
|
12
|
-
add_acts_as_authentic_module(Methods)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -22,175 +23,7 @@ module Authlogic
|
|
22
23
|
def email_field(value = nil)
|
23
24
|
rw_config(:email_field, value, first_column_to_exist(nil, :email, :email_address))
|
24
25
|
end
|
25
|
-
|
26
|
-
|
27
|
-
# Toggles validating the email field or not.
|
28
|
-
#
|
29
|
-
# * <tt>Default:</tt> true
|
30
|
-
# * <tt>Accepts:</tt> Boolean
|
31
|
-
#
|
32
|
-
# @deprecated
|
33
|
-
def validate_email_field(value = nil)
|
34
|
-
rw_config(:validate_email_field, value, true)
|
35
|
-
end
|
36
|
-
alias_method :validate_email_field=, :validate_email_field
|
37
|
-
|
38
|
-
# A hash of options for the validates_length_of call for the email
|
39
|
-
# field. Allows you to change this however you want.
|
40
|
-
#
|
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>
|
45
|
-
#
|
46
|
-
# * <tt>Default:</tt> {:maximum => 100}
|
47
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
|
48
|
-
#
|
49
|
-
# @deprecated
|
50
|
-
def validates_length_of_email_field_options(value = nil)
|
51
|
-
deprecate_authlogic_config("validates_length_of_email_field_options") if value
|
52
|
-
rw_config(:validates_length_of_email_field_options, value, maximum: 100)
|
53
|
-
end
|
54
|
-
alias_method(
|
55
|
-
:validates_length_of_email_field_options=,
|
56
|
-
:validates_length_of_email_field_options
|
57
|
-
)
|
58
|
-
|
59
|
-
# A convenience function to merge options into the
|
60
|
-
# validates_length_of_email_field_options. So instead of:
|
61
|
-
#
|
62
|
-
# self.validates_length_of_email_field_options =
|
63
|
-
# validates_length_of_email_field_options.merge(:my_option => my_value)
|
64
|
-
#
|
65
|
-
# You can do this:
|
66
|
-
#
|
67
|
-
# merge_validates_length_of_email_field_options :my_option => my_value
|
68
|
-
#
|
69
|
-
# @deprecated
|
70
|
-
def merge_validates_length_of_email_field_options(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)
|
74
|
-
end
|
75
|
-
|
76
|
-
# A hash of options for the validates_format_of call for the email
|
77
|
-
# field. Allows you to change this however you want.
|
78
|
-
#
|
79
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
80
|
-
# possible, so you can completely replace the hash or merge options into
|
81
|
-
# it. Checkout the convenience function
|
82
|
-
# merge_validates_format_of_email_field_options to merge options.</b>
|
83
|
-
#
|
84
|
-
# To validate international email addresses, enable the provided
|
85
|
-
# alternate regex:
|
86
|
-
#
|
87
|
-
# ```
|
88
|
-
# validates_format_of_email_field_options(
|
89
|
-
# with: Authlogic::Regex.email_nonascii
|
90
|
-
# )
|
91
|
-
# ```
|
92
|
-
#
|
93
|
-
# * <tt>Default:</tt>
|
94
|
-
#
|
95
|
-
# {
|
96
|
-
# :with => Authlogic::Regex.email,
|
97
|
-
# :message => Proc.new {
|
98
|
-
# I18n.t(
|
99
|
-
# 'error_messages.email_invalid',
|
100
|
-
# :default => "should look like an email address."
|
101
|
-
# )
|
102
|
-
# }
|
103
|
-
# }
|
104
|
-
#
|
105
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
|
106
|
-
#
|
107
|
-
# @deprecated
|
108
|
-
def validates_format_of_email_field_options(value = nil)
|
109
|
-
deprecate_authlogic_config("validates_format_of_email_field_options") if value
|
110
|
-
rw_config(
|
111
|
-
:validates_format_of_email_field_options,
|
112
|
-
value,
|
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
|
120
|
-
)
|
121
|
-
end
|
122
|
-
alias_method(
|
123
|
-
:validates_format_of_email_field_options=,
|
124
|
-
:validates_format_of_email_field_options
|
125
|
-
)
|
126
|
-
|
127
|
-
# See merge_validates_length_of_email_field_options. The same thing
|
128
|
-
# except for validates_format_of_email_field_options.
|
129
|
-
#
|
130
|
-
# @deprecated
|
131
|
-
def merge_validates_format_of_email_field_options(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)
|
135
|
-
end
|
136
|
-
|
137
|
-
# A hash of options for the validates_uniqueness_of call for the email
|
138
|
-
# field. Allows you to change this however you want.
|
139
|
-
#
|
140
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
141
|
-
# possible, so you can completely replace the hash or merge options into
|
142
|
-
# it. Checkout the convenience function
|
143
|
-
# merge_validates_uniqueness_of_email_field_options to merge
|
144
|
-
# options.</b>
|
145
|
-
#
|
146
|
-
# * <tt>Default:</tt>
|
147
|
-
#
|
148
|
-
# {
|
149
|
-
# :case_sensitive => false,
|
150
|
-
# :scope => validations_scope,
|
151
|
-
# :if => "#{email_field}_changed?".to_sym
|
152
|
-
# }
|
153
|
-
#
|
154
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
|
155
|
-
#
|
156
|
-
# @deprecated
|
157
|
-
def validates_uniqueness_of_email_field_options(value = nil)
|
158
|
-
deprecate_authlogic_config("validates_uniqueness_of_email_field_options") if value
|
159
|
-
rw_config(
|
160
|
-
:validates_uniqueness_of_email_field_options,
|
161
|
-
value,
|
162
|
-
case_sensitive: false,
|
163
|
-
scope: validations_scope,
|
164
|
-
if: "#{email_field}_changed?".to_sym
|
165
|
-
)
|
166
|
-
end
|
167
|
-
alias_method(
|
168
|
-
:validates_uniqueness_of_email_field_options=,
|
169
|
-
:validates_uniqueness_of_email_field_options
|
170
|
-
)
|
171
|
-
|
172
|
-
# See merge_validates_length_of_email_field_options. The same thing
|
173
|
-
# except for validates_uniqueness_of_email_field_options.
|
174
|
-
#
|
175
|
-
# @deprecated
|
176
|
-
def merge_validates_uniqueness_of_email_field_options(options = {})
|
177
|
-
deprecate_authlogic_config("merge_validates_uniqueness_of_email_field_options")
|
178
|
-
self.validates_uniqueness_of_email_field_options =
|
179
|
-
validates_uniqueness_of_email_field_options.merge(options)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
# All methods relating to the email field
|
184
|
-
module Methods
|
185
|
-
def self.included(klass)
|
186
|
-
klass.class_eval do
|
187
|
-
if validate_email_field && email_field
|
188
|
-
validates_length_of email_field, validates_length_of_email_field_options
|
189
|
-
validates_format_of email_field, validates_format_of_email_field_options
|
190
|
-
validates_uniqueness_of email_field, validates_uniqueness_of_email_field_options
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
26
|
+
alias email_field= email_field
|
194
27
|
end
|
195
28
|
end
|
196
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module ActsAsAuthentic
|
3
5
|
# Since web applications are stateless there is not sure fire way to tell if
|
@@ -22,7 +24,7 @@ module Authlogic
|
|
22
24
|
def logged_in_timeout(value = nil)
|
23
25
|
rw_config(:logged_in_timeout, (!value.nil? && value.to_i) || value, 10.minutes.to_i)
|
24
26
|
end
|
25
|
-
|
27
|
+
alias logged_in_timeout= logged_in_timeout
|
26
28
|
end
|
27
29
|
|
28
30
|
# All methods for the logged in status feature seat.
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "authlogic/acts_as_authentic/queries/case_sensitivity"
|
1
4
|
require "authlogic/acts_as_authentic/queries/find_with_case"
|
2
5
|
|
3
6
|
module Authlogic
|
@@ -7,7 +10,6 @@ module Authlogic
|
|
7
10
|
def self.included(klass)
|
8
11
|
klass.class_eval do
|
9
12
|
extend Config
|
10
|
-
add_acts_as_authentic_module(Methods)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
@@ -20,152 +22,7 @@ module Authlogic
|
|
20
22
|
def login_field(value = nil)
|
21
23
|
rw_config(:login_field, value, first_column_to_exist(nil, :login, :username))
|
22
24
|
end
|
23
|
-
|
24
|
-
|
25
|
-
# Whether or not to validate the login field
|
26
|
-
#
|
27
|
-
# * <tt>Default:</tt> true
|
28
|
-
# * <tt>Accepts:</tt> Boolean
|
29
|
-
#
|
30
|
-
# @deprecated
|
31
|
-
def validate_login_field(value = nil)
|
32
|
-
rw_config(:validate_login_field, value, true)
|
33
|
-
end
|
34
|
-
alias_method :validate_login_field=, :validate_login_field
|
35
|
-
|
36
|
-
# A hash of options for the validates_length_of call for the login
|
37
|
-
# field. Allows you to change this however you want.
|
38
|
-
#
|
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_login_field_options to merge options.</b>
|
43
|
-
#
|
44
|
-
# * <tt>Default:</tt> {:within => 3..100}
|
45
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
|
46
|
-
#
|
47
|
-
# @deprecated
|
48
|
-
def validates_length_of_login_field_options(value = nil)
|
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)
|
51
|
-
end
|
52
|
-
alias_method(
|
53
|
-
:validates_length_of_login_field_options=,
|
54
|
-
:validates_length_of_login_field_options
|
55
|
-
)
|
56
|
-
|
57
|
-
# A convenience function to merge options into the
|
58
|
-
# validates_length_of_login_field_options. So instead of:
|
59
|
-
#
|
60
|
-
# self.validates_length_of_login_field_options =
|
61
|
-
# validates_length_of_login_field_options.merge(:my_option => my_value)
|
62
|
-
#
|
63
|
-
# You can do this:
|
64
|
-
#
|
65
|
-
# merge_validates_length_of_login_field_options :my_option => my_value
|
66
|
-
#
|
67
|
-
# @deprecated
|
68
|
-
def merge_validates_length_of_login_field_options(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)
|
72
|
-
end
|
73
|
-
|
74
|
-
# A hash of options for the validates_format_of call for the login
|
75
|
-
# field. Allows you to change this however you want.
|
76
|
-
#
|
77
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
78
|
-
# possible, so you can completely replace the hash or merge options into
|
79
|
-
# it. Checkout the convenience function
|
80
|
-
# merge_validates_format_of_login_field_options to merge options.</b>
|
81
|
-
#
|
82
|
-
# * <tt>Default:</tt>
|
83
|
-
#
|
84
|
-
# {
|
85
|
-
# :with => Authlogic::Regex.login,
|
86
|
-
# :message => lambda {
|
87
|
-
# I18n.t(
|
88
|
-
# 'error_messages.login_invalid',
|
89
|
-
# :default => "should use only letters, numbers, spaces, and .-_@+ please."
|
90
|
-
# )
|
91
|
-
# }
|
92
|
-
# }
|
93
|
-
#
|
94
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
|
95
|
-
#
|
96
|
-
# @deprecated
|
97
|
-
def validates_format_of_login_field_options(value = nil)
|
98
|
-
deprecate_authlogic_config("validates_format_of_login_field_options") if value
|
99
|
-
rw_config(
|
100
|
-
:validates_format_of_login_field_options,
|
101
|
-
value,
|
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
|
109
|
-
)
|
110
|
-
end
|
111
|
-
alias_method(
|
112
|
-
:validates_format_of_login_field_options=,
|
113
|
-
:validates_format_of_login_field_options
|
114
|
-
)
|
115
|
-
|
116
|
-
# See merge_validates_length_of_login_field_options. The same thing,
|
117
|
-
# except for validates_format_of_login_field_options
|
118
|
-
#
|
119
|
-
# @deprecated
|
120
|
-
def merge_validates_format_of_login_field_options(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)
|
124
|
-
end
|
125
|
-
|
126
|
-
# A hash of options for the validates_uniqueness_of call for the login
|
127
|
-
# field. Allows you to change this however you want.
|
128
|
-
#
|
129
|
-
# <b>Keep in mind this is ruby. I wanted to keep this as flexible as
|
130
|
-
# possible, so you can completely replace the hash or merge options into
|
131
|
-
# it. Checkout the convenience function
|
132
|
-
# merge_validates_format_of_login_field_options to merge options.</b>
|
133
|
-
#
|
134
|
-
# * <tt>Default:</tt>
|
135
|
-
#
|
136
|
-
# {
|
137
|
-
# :case_sensitive => false,
|
138
|
-
# :scope => validations_scope,
|
139
|
-
# :if => "#{login_field}_changed?".to_sym
|
140
|
-
# }
|
141
|
-
#
|
142
|
-
# * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
|
143
|
-
#
|
144
|
-
# @deprecated
|
145
|
-
def validates_uniqueness_of_login_field_options(value = nil)
|
146
|
-
deprecate_authlogic_config("validates_uniqueness_of_login_field_options") if value
|
147
|
-
rw_config(
|
148
|
-
:validates_uniqueness_of_login_field_options,
|
149
|
-
value,
|
150
|
-
case_sensitive: false,
|
151
|
-
scope: validations_scope,
|
152
|
-
if: "#{login_field}_changed?".to_sym
|
153
|
-
)
|
154
|
-
end
|
155
|
-
alias_method(
|
156
|
-
:validates_uniqueness_of_login_field_options=,
|
157
|
-
:validates_uniqueness_of_login_field_options
|
158
|
-
)
|
159
|
-
|
160
|
-
# See merge_validates_length_of_login_field_options. The same thing,
|
161
|
-
# except for validates_uniqueness_of_login_field_options
|
162
|
-
#
|
163
|
-
# @deprecated
|
164
|
-
def merge_validates_uniqueness_of_login_field_options(options = {})
|
165
|
-
deprecate_authlogic_config("merge_validates_uniqueness_of_login_field_options")
|
166
|
-
self.validates_uniqueness_of_login_field_options =
|
167
|
-
validates_uniqueness_of_login_field_options.merge(options)
|
168
|
-
end
|
25
|
+
alias login_field= login_field
|
169
26
|
|
170
27
|
# This method allows you to find a record with the given login. If you
|
171
28
|
# notice, with Active Record you have the UniquenessValidator class.
|
@@ -189,19 +46,9 @@ module Authlogic
|
|
189
46
|
#
|
190
47
|
# @api public
|
191
48
|
def find_by_smart_case_login_field(login)
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
login,
|
196
|
-
validates_uniqueness_of_login_field_options[:case_sensitive] != false
|
197
|
-
)
|
198
|
-
else
|
199
|
-
find_with_case(
|
200
|
-
email_field,
|
201
|
-
login,
|
202
|
-
validates_uniqueness_of_email_field_options[:case_sensitive] != false
|
203
|
-
)
|
204
|
-
end
|
49
|
+
field = login_field || email_field
|
50
|
+
sensitive = Queries::CaseSensitivity.new(self, field).sensitive?
|
51
|
+
find_with_case(field, login, sensitive)
|
205
52
|
end
|
206
53
|
|
207
54
|
private
|
@@ -211,20 +58,6 @@ module Authlogic
|
|
211
58
|
Queries::FindWithCase.new(self, field, value, sensitive).execute
|
212
59
|
end
|
213
60
|
end
|
214
|
-
|
215
|
-
# All methods relating to the login field
|
216
|
-
module Methods
|
217
|
-
# Adds in various validations, modules, etc.
|
218
|
-
def self.included(klass)
|
219
|
-
klass.class_eval do
|
220
|
-
if validate_login_field && login_field
|
221
|
-
validates_length_of login_field, validates_length_of_login_field_options
|
222
|
-
validates_format_of login_field, validates_format_of_login_field_options
|
223
|
-
validates_uniqueness_of login_field, validates_uniqueness_of_login_field_options
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
61
|
end
|
229
62
|
end
|
230
63
|
end
|