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.
- 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
@@ -1,17 +1,19 @@
|
|
1
1
|
module Authlogic
|
2
2
|
module Session
|
3
|
-
# Handles all authentication that deals with basic HTTP auth. Which is
|
3
|
+
# Handles all authentication that deals with basic HTTP auth. Which is
|
4
|
+
# authentication built into the HTTP protocol:
|
4
5
|
#
|
5
6
|
# http://username:password@whatever.com
|
6
7
|
#
|
7
|
-
# Also, if you are not comfortable letting users pass their raw username and
|
8
|
-
#
|
8
|
+
# Also, if you are not comfortable letting users pass their raw username and
|
9
|
+
# password you can always use the single access token. See
|
10
|
+
# Authlogic::Session::Params for more info.
|
9
11
|
module HttpAuth
|
10
12
|
def self.included(klass)
|
11
13
|
klass.class_eval do
|
12
14
|
extend Config
|
13
15
|
include InstanceMethods
|
14
|
-
persist :persist_by_http_auth, :
|
16
|
+
persist :persist_by_http_auth, if: :persist_by_http_auth?
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -19,13 +21,15 @@ module Authlogic
|
|
19
21
|
module Config
|
20
22
|
# Do you want to allow your users to log in via HTTP basic auth?
|
21
23
|
#
|
22
|
-
# I recommend keeping this enabled. The only time I feel this should be
|
23
|
-
#
|
24
|
+
# I recommend keeping this enabled. The only time I feel this should be
|
25
|
+
# disabled is if you are not comfortable having your users provide their
|
26
|
+
# raw username and password. Whatever the reason, you can disable it
|
27
|
+
# here.
|
24
28
|
#
|
25
29
|
# * <tt>Default:</tt> true
|
26
30
|
# * <tt>Accepts:</tt> Boolean
|
27
31
|
def allow_http_basic_auth(value = nil)
|
28
|
-
rw_config(:allow_http_basic_auth, value,
|
32
|
+
rw_config(:allow_http_basic_auth, value, false)
|
29
33
|
end
|
30
34
|
alias_method :allow_http_basic_auth=, :allow_http_basic_auth
|
31
35
|
|
@@ -60,7 +64,7 @@ module Authlogic
|
|
60
64
|
# * <tt>Default:</tt> 'Application'
|
61
65
|
# * <tt>Accepts:</tt> String
|
62
66
|
def http_basic_auth_realm(value = nil)
|
63
|
-
rw_config(:http_basic_auth_realm, value,
|
67
|
+
rw_config(:http_basic_auth_realm, value, "Application")
|
64
68
|
end
|
65
69
|
alias_method :http_basic_auth_realm=, :http_basic_auth_realm
|
66
70
|
end
|
@@ -69,31 +73,34 @@ module Authlogic
|
|
69
73
|
module InstanceMethods
|
70
74
|
private
|
71
75
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
def persist_by_http_auth
|
77
|
-
login_proc = Proc.new do |login, password|
|
78
|
-
if !login.blank? && !password.blank?
|
79
|
-
send("#{login_field}=", login)
|
80
|
-
send("#{password_field}=", password)
|
81
|
-
valid?
|
82
|
-
end
|
83
|
-
end
|
76
|
+
def persist_by_http_auth?
|
77
|
+
allow_http_basic_auth? && login_field && password_field
|
78
|
+
end
|
84
79
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
80
|
+
def persist_by_http_auth
|
81
|
+
login_proc = proc do |login, password|
|
82
|
+
if !login.blank? && !password.blank?
|
83
|
+
send("#{login_field}=", login)
|
84
|
+
send("#{password_field}=", password)
|
85
|
+
valid?
|
89
86
|
end
|
90
|
-
|
91
|
-
false
|
92
87
|
end
|
93
88
|
|
94
|
-
|
95
|
-
|
89
|
+
if self.class.request_http_basic_auth
|
90
|
+
controller.authenticate_or_request_with_http_basic(
|
91
|
+
self.class.http_basic_auth_realm,
|
92
|
+
&login_proc
|
93
|
+
)
|
94
|
+
else
|
95
|
+
controller.authenticate_with_http_basic(&login_proc)
|
96
96
|
end
|
97
|
+
|
98
|
+
false
|
99
|
+
end
|
100
|
+
|
101
|
+
def allow_http_basic_auth?
|
102
|
+
self.class.allow_http_basic_auth == true
|
103
|
+
end
|
97
104
|
end
|
98
105
|
end
|
99
106
|
end
|
data/lib/authlogic/session/id.rb
CHANGED
@@ -3,6 +3,11 @@ module Authlogic
|
|
3
3
|
# Allows you to separate sessions with an id, ultimately letting you create
|
4
4
|
# multiple sessions for the same user.
|
5
5
|
module Id
|
6
|
+
def initialize(*args)
|
7
|
+
@id = nil
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
6
11
|
def self.included(klass)
|
7
12
|
klass.class_eval do
|
8
13
|
attr_writer :id
|
@@ -39,10 +44,10 @@ module Authlogic
|
|
39
44
|
|
40
45
|
private
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
# Used for things like cookie_key, session_key, etc.
|
48
|
+
def build_key(last_part)
|
49
|
+
[id, super].compact.join("_")
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
@@ -16,7 +16,8 @@ module Authlogic
|
|
16
16
|
module Config
|
17
17
|
# Lets you change which model to use for authentication.
|
18
18
|
#
|
19
|
-
# * <tt>Default:</tt> inferred from the class name. UserSession would
|
19
|
+
# * <tt>Default:</tt> inferred from the class name. UserSession would
|
20
|
+
# automatically try User
|
20
21
|
# * <tt>Accepts:</tt> an ActiveRecord class
|
21
22
|
def authenticate_with(klass)
|
22
23
|
@klass_name = klass.name
|
@@ -24,9 +25,10 @@ module Authlogic
|
|
24
25
|
end
|
25
26
|
alias_method :authenticate_with=, :authenticate_with
|
26
27
|
|
27
|
-
# The name of the class that this session is authenticating with. For
|
28
|
-
#
|
29
|
-
#
|
28
|
+
# The name of the class that this session is authenticating with. For
|
29
|
+
# example, the UserSession class will authenticate with the User class
|
30
|
+
# unless you specify otherwise in your configuration. See
|
31
|
+
# authenticate_with for information on how to change this value.
|
30
32
|
def klass
|
31
33
|
@klass ||= klass_name ? klass_name.constantize : nil
|
32
34
|
end
|
@@ -40,7 +42,8 @@ module Authlogic
|
|
40
42
|
end
|
41
43
|
|
42
44
|
module InstanceMethods
|
43
|
-
# Creating an alias method for the "record" method based on the klass
|
45
|
+
# Creating an alias method for the "record" method based on the klass
|
46
|
+
# name, so that we can do:
|
44
47
|
#
|
45
48
|
# session.user
|
46
49
|
#
|
@@ -48,7 +51,7 @@ module Authlogic
|
|
48
51
|
#
|
49
52
|
# session.record
|
50
53
|
def initialize(*args)
|
51
|
-
|
54
|
+
unless self.class.configured_klass_methods
|
52
55
|
self.class.send(:alias_method, klass_name.demodulize.underscore.to_sym, :record)
|
53
56
|
self.class.configured_klass_methods = true
|
54
57
|
end
|
@@ -57,13 +60,13 @@ module Authlogic
|
|
57
60
|
|
58
61
|
private
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
def klass
|
64
|
+
self.class.klass
|
65
|
+
end
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
def klass_name
|
68
|
+
self.class.klass_name
|
69
|
+
end
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
@@ -19,10 +19,10 @@ module Authlogic
|
|
19
19
|
klass.class_eval do
|
20
20
|
extend Config
|
21
21
|
include InstanceMethods
|
22
|
-
after_persisting :set_last_request_at, :
|
22
|
+
after_persisting :set_last_request_at, if: :set_last_request_at?
|
23
23
|
validate :increase_failed_login_count
|
24
24
|
before_save :update_info
|
25
|
-
before_save :set_last_request_at, :
|
25
|
+
before_save :set_last_request_at, if: :set_last_request_at?
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -43,73 +43,76 @@ module Authlogic
|
|
43
43
|
alias_method :last_request_at_threshold=, :last_request_at_threshold
|
44
44
|
end
|
45
45
|
|
46
|
-
# The methods available for an Authlogic::Session::Base object that make
|
46
|
+
# The methods available for an Authlogic::Session::Base object that make
|
47
|
+
# up the magic columns feature.
|
47
48
|
module InstanceMethods
|
48
49
|
private
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
attempted_record.failed_login_count += 1
|
54
|
-
end
|
51
|
+
def clear_failed_login_count
|
52
|
+
if record.respond_to?(:failed_login_count)
|
53
|
+
record.failed_login_count = 0
|
55
54
|
end
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
def increase_failed_login_count
|
58
|
+
if invalid_password? && attempted_record.respond_to?(:failed_login_count)
|
59
|
+
attempted_record.failed_login_count ||= 0
|
60
|
+
attempted_record.failed_login_count += 1
|
61
|
+
end
|
62
|
+
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
def increment_login_cout
|
65
|
+
if record.respond_to?(:login_count)
|
66
|
+
record.login_count = (record.login_count.blank? ? 1 : record.login_count + 1)
|
67
|
+
end
|
68
|
+
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
def update_info
|
71
|
+
increment_login_cout
|
72
|
+
clear_failed_login_count
|
73
|
+
update_login_timestamps
|
74
|
+
update_login_ip_addresses
|
75
|
+
end
|
70
76
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
77
|
+
def update_login_ip_addresses
|
78
|
+
if record.respond_to?(:current_login_ip)
|
79
|
+
record.last_login_ip = record.current_login_ip if record.respond_to?(:last_login_ip)
|
80
|
+
record.current_login_ip = controller.request.ip
|
75
81
|
end
|
82
|
+
end
|
76
83
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
# controller. This allows you to control this method pragmatically in
|
82
|
-
# your controller.
|
83
|
-
#
|
84
|
-
# For example, what if you had a javascript function that polled the
|
85
|
-
# server updating how much time is left in their session before it
|
86
|
-
# times out. Obviously you would want to ignore this request, because
|
87
|
-
# then the user would never time out. So you can do something like
|
88
|
-
# this in your controller:
|
89
|
-
#
|
90
|
-
# def last_request_update_allowed?
|
91
|
-
# action_name != "update_session_time_left"
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# You can do whatever you want with that method.
|
95
|
-
def set_last_request_at? # :doc:
|
96
|
-
if !record || !klass.column_names.include?("last_request_at")
|
97
|
-
return false
|
98
|
-
end
|
99
|
-
if controller.responds_to_last_request_update_allowed? && !controller.last_request_update_allowed?
|
100
|
-
return false
|
101
|
-
end
|
102
|
-
record.last_request_at.blank? ||
|
103
|
-
last_request_at_threshold.to_i.seconds.ago >= record.last_request_at
|
84
|
+
def update_login_timestamps
|
85
|
+
if record.respond_to?(:current_login_at)
|
86
|
+
record.last_login_at = record.current_login_at if record.respond_to?(:last_login_at)
|
87
|
+
record.current_login_at = klass.default_timezone == :utc ? Time.now.utc : Time.now
|
104
88
|
end
|
89
|
+
end
|
105
90
|
|
106
|
-
|
107
|
-
|
91
|
+
# This method lets authlogic know whether it should allow the
|
92
|
+
# last_request_at field to be updated with the current time.
|
93
|
+
#
|
94
|
+
# See also `last_request_update_allowed?` in
|
95
|
+
# `Authlogic::ControllerAdapters::AbstractAdapter`
|
96
|
+
#
|
97
|
+
# @api private
|
98
|
+
def set_last_request_at?
|
99
|
+
if !record || !klass.column_names.include?("last_request_at")
|
100
|
+
return false
|
108
101
|
end
|
109
|
-
|
110
|
-
|
111
|
-
self.class.last_request_at_threshold
|
102
|
+
unless controller.last_request_update_allowed?
|
103
|
+
return false
|
112
104
|
end
|
105
|
+
record.last_request_at.blank? ||
|
106
|
+
last_request_at_threshold.to_i.seconds.ago >= record.last_request_at
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_last_request_at
|
110
|
+
record.last_request_at = klass.default_timezone == :utc ? Time.now.utc : Time.now
|
111
|
+
end
|
112
|
+
|
113
|
+
def last_request_at_threshold
|
114
|
+
self.class.last_request_at_threshold
|
115
|
+
end
|
113
116
|
end
|
114
117
|
end
|
115
118
|
end
|
@@ -25,7 +25,7 @@ module Authlogic
|
|
25
25
|
klass.class_eval do
|
26
26
|
extend Config
|
27
27
|
include InstanceMethods
|
28
|
-
validate :validate_magic_states, :
|
28
|
+
validate :validate_magic_states, unless: :disable_magic_states?
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -50,26 +50,32 @@ module Authlogic
|
|
50
50
|
module InstanceMethods
|
51
51
|
private
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
def disable_magic_states?
|
54
|
+
self.class.disable_magic_states == true
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
57
|
+
# @api private
|
58
|
+
def required_magic_states_for(record)
|
59
|
+
%i[active approved confirmed].select { |state|
|
60
|
+
record.respond_to?("#{state}?")
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_magic_states
|
65
|
+
return true if attempted_record.nil?
|
66
|
+
required_magic_states_for(attempted_record).each do |required_status|
|
67
|
+
next if attempted_record.send("#{required_status}?")
|
68
|
+
errors.add(
|
69
|
+
:base,
|
70
|
+
I18n.t(
|
71
|
+
"error_messages.not_#{required_status}",
|
72
|
+
default: "Your account is not #{required_status}"
|
73
|
+
)
|
74
|
+
)
|
75
|
+
return false
|
72
76
|
end
|
77
|
+
true
|
78
|
+
end
|
73
79
|
end
|
74
80
|
end
|
75
81
|
end
|
@@ -66,7 +66,11 @@ module Authlogic
|
|
66
66
|
# * <tt>Accepts:</tt> String of a request type, or :all or :any to
|
67
67
|
# allow single access authentication for any and all request types
|
68
68
|
def single_access_allowed_request_types(value = nil)
|
69
|
-
rw_config(
|
69
|
+
rw_config(
|
70
|
+
:single_access_allowed_request_types,
|
71
|
+
value,
|
72
|
+
["application/rss+xml", "application/atom+xml"]
|
73
|
+
)
|
70
74
|
end
|
71
75
|
alias_method :single_access_allowed_request_types=, :single_access_allowed_request_types
|
72
76
|
end
|
@@ -76,40 +80,50 @@ module Authlogic
|
|
76
80
|
module InstanceMethods
|
77
81
|
private
|
78
82
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
return controller.single_access_allowed? if controller.responds_to_single_access_allowed?
|
83
|
+
def persist_by_params
|
84
|
+
return false unless params_enabled?
|
85
|
+
self.unauthorized_record = search_for_record(
|
86
|
+
"find_by_single_access_token",
|
87
|
+
params_credentials
|
88
|
+
)
|
89
|
+
self.single_access = valid?
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
single_access_allowed_request_types.include?(:all)
|
93
|
-
else
|
94
|
-
[:all, :any].include?(single_access_allowed_request_types)
|
95
|
-
end
|
92
|
+
def params_enabled?
|
93
|
+
if !params_credentials || !klass.column_names.include?("single_access_token")
|
94
|
+
return false
|
96
95
|
end
|
97
|
-
|
98
|
-
|
99
|
-
build_key(self.class.params_key)
|
96
|
+
if controller.responds_to_single_access_allowed?
|
97
|
+
return controller.single_access_allowed?
|
100
98
|
end
|
99
|
+
params_enabled_by_allowed_request_types?
|
100
|
+
end
|
101
101
|
|
102
|
-
|
103
|
-
|
102
|
+
def params_enabled_by_allowed_request_types?
|
103
|
+
case single_access_allowed_request_types
|
104
|
+
when Array
|
105
|
+
single_access_allowed_request_types.include?(controller.request_content_type) ||
|
106
|
+
single_access_allowed_request_types.include?(:all)
|
107
|
+
else
|
108
|
+
%i[all any].include?(single_access_allowed_request_types)
|
104
109
|
end
|
110
|
+
end
|
105
111
|
|
106
|
-
|
107
|
-
|
108
|
-
|
112
|
+
def params_key
|
113
|
+
build_key(self.class.params_key)
|
114
|
+
end
|
109
115
|
|
110
|
-
|
111
|
-
|
112
|
-
|
116
|
+
def single_access?
|
117
|
+
single_access == true
|
118
|
+
end
|
119
|
+
|
120
|
+
def single_access_allowed_request_types
|
121
|
+
self.class.single_access_allowed_request_types
|
122
|
+
end
|
123
|
+
|
124
|
+
def params_credentials
|
125
|
+
controller.params[params_key]
|
126
|
+
end
|
113
127
|
end
|
114
128
|
end
|
115
129
|
end
|