authlogic 3.8.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
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,17 +1,19 @@
1
1
  module Authlogic
2
2
  module Session
3
- # Handles all authentication that deals with basic HTTP auth. Which is authentication built into the HTTP protocol:
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 password you can always use the single
8
- # access token. See Authlogic::Session::Params for more info.
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, :if => :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 disabled is if you are not comfortable
23
- # having your users provide their raw username and password. Whatever the reason, you can disable it here.
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, true)
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, 'Application')
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
- def persist_by_http_auth?
73
- allow_http_basic_auth? && login_field && password_field
74
- end
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
- if self.class.request_http_basic_auth
86
- controller.authenticate_or_request_with_http_basic(self.class.http_basic_auth_realm, &login_proc)
87
- else
88
- controller.authenticate_with_http_basic(&login_proc)
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
- def allow_http_basic_auth?
95
- self.class.allow_http_basic_auth == true
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
@@ -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
- # Used for things like cookie_key, session_key, etc.
43
- def build_key(last_part)
44
- [id, super].compact.join("_")
45
- end
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 automatically try User
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 example, the UserSession class will
28
- # authenticate with the User class unless you specify otherwise in your configuration. See authenticate_with
29
- # for information on how to change this value.
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 name, so that we can do:
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
- if !self.class.configured_klass_methods
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
- def klass
61
- self.class.klass
62
- end
63
+ def klass
64
+ self.class.klass
65
+ end
63
66
 
64
- def klass_name
65
- self.class.klass_name
66
- end
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, :if => :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, :if => :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 up the magic columns feature.
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
- def increase_failed_login_count
51
- if invalid_password? && attempted_record.respond_to?(:failed_login_count)
52
- attempted_record.failed_login_count ||= 0
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
- def update_info
58
- if record.respond_to?(:login_count)
59
- record.login_count = (record.login_count.blank? ? 1 : record.login_count + 1)
60
- end
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
- if record.respond_to?(:failed_login_count)
63
- record.failed_login_count = 0
64
- end
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
- if record.respond_to?(:current_login_at)
67
- record.last_login_at = record.current_login_at if record.respond_to?(:last_login_at)
68
- record.current_login_at = klass.default_timezone == :utc ? Time.now.utc : Time.now
69
- end
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
- if record.respond_to?(:current_login_ip)
72
- record.last_login_ip = record.current_login_ip if record.respond_to?(:last_login_ip)
73
- record.current_login_ip = controller.request.ip
74
- end
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
- # This method lets authlogic know whether it should allow the
78
- # last_request_at field to be updated with the current time
79
- # (Time.now). One thing to note here is that it also checks for the
80
- # existence of a last_request_update_allowed? method in your
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
- def set_last_request_at
107
- record.last_request_at = klass.default_timezone == :utc ? Time.now.utc : Time.now
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
- def last_request_at_threshold
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, :unless => :disable_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
- def disable_magic_states?
54
- self.class.disable_magic_states == true
55
- end
53
+ def disable_magic_states?
54
+ self.class.disable_magic_states == true
55
+ end
56
56
 
57
- def validate_magic_states
58
- return true if attempted_record.nil?
59
- [:active, :approved, :confirmed].each do |required_status|
60
- if attempted_record.respond_to?("#{required_status}?") && !attempted_record.send("#{required_status}?")
61
- errors.add(
62
- :base,
63
- I18n.t(
64
- "error_messages.not_#{required_status}",
65
- :default => "Your account is not #{required_status}"
66
- )
67
- )
68
- return false
69
- end
70
- end
71
- true
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(:single_access_allowed_request_types, value, ["application/rss+xml", "application/atom+xml"])
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
- def persist_by_params
80
- return false if !params_enabled?
81
- self.unauthorized_record = search_for_record("find_by_single_access_token", params_credentials)
82
- self.single_access = valid?
83
- end
84
-
85
- def params_enabled?
86
- return false if !params_credentials || !klass.column_names.include?("single_access_token")
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
- case single_access_allowed_request_types
90
- when Array
91
- single_access_allowed_request_types.include?(controller.request_content_type) ||
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
- def params_key
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
- def single_access?
103
- single_access == true
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
- def single_access_allowed_request_types
107
- self.class.single_access_allowed_request_types
108
- end
112
+ def params_key
113
+ build_key(self.class.params_key)
114
+ end
109
115
 
110
- def params_credentials
111
- controller.params[params_key]
112
- end
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