authlogic 3.4.6 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +33 -0
  4. data/.rubocop_todo.yml +427 -0
  5. data/.travis.yml +24 -3
  6. data/CHANGELOG.md +9 -2
  7. data/CONTRIBUTING.md +40 -1
  8. data/Gemfile +1 -1
  9. data/README.md +295 -0
  10. data/Rakefile +10 -2
  11. data/authlogic.gemspec +6 -5
  12. data/lib/authlogic.rb +2 -2
  13. data/lib/authlogic/acts_as_authentic/base.rb +2 -2
  14. data/lib/authlogic/acts_as_authentic/email.rb +59 -14
  15. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +4 -3
  16. data/lib/authlogic/acts_as_authentic/login.rb +62 -12
  17. data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
  18. data/lib/authlogic/acts_as_authentic/password.rb +107 -53
  19. data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -9
  20. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +2 -0
  21. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +48 -35
  22. data/lib/authlogic/acts_as_authentic/single_access_token.rb +19 -15
  23. data/lib/authlogic/acts_as_authentic/validations_scope.rb +2 -2
  24. data/lib/authlogic/authenticates_many/association.rb +6 -5
  25. data/lib/authlogic/authenticates_many/base.rb +22 -12
  26. data/lib/authlogic/config.rb +2 -1
  27. data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -1
  28. data/lib/authlogic/controller_adapters/rack_adapter.rb +3 -4
  29. data/lib/authlogic/controller_adapters/rails_adapter.rb +26 -14
  30. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +1 -1
  31. data/lib/authlogic/crypto_providers/aes256.rb +16 -12
  32. data/lib/authlogic/crypto_providers/bcrypt.rb +10 -4
  33. data/lib/authlogic/crypto_providers/md5.rb +7 -7
  34. data/lib/authlogic/crypto_providers/scrypt.rb +10 -2
  35. data/lib/authlogic/crypto_providers/sha1.rb +3 -3
  36. data/lib/authlogic/crypto_providers/sha256.rb +3 -3
  37. data/lib/authlogic/crypto_providers/sha512.rb +4 -4
  38. data/lib/authlogic/crypto_providers/wordpress.rb +13 -13
  39. data/lib/authlogic/i18n.rb +22 -16
  40. data/lib/authlogic/i18n/translator.rb +1 -1
  41. data/lib/authlogic/random.rb +13 -12
  42. data/lib/authlogic/regex.rb +3 -3
  43. data/lib/authlogic/session/activation.rb +7 -6
  44. data/lib/authlogic/session/active_record_trickery.rb +1 -2
  45. data/lib/authlogic/session/base.rb +7 -6
  46. data/lib/authlogic/session/brute_force_protection.rb +58 -34
  47. data/lib/authlogic/session/callbacks.rb +16 -12
  48. data/lib/authlogic/session/cookies.rb +29 -14
  49. data/lib/authlogic/session/existence.rb +10 -10
  50. data/lib/authlogic/session/foundation.rb +11 -7
  51. data/lib/authlogic/session/http_auth.rb +6 -5
  52. data/lib/authlogic/session/id.rb +5 -4
  53. data/lib/authlogic/session/klass.rb +2 -1
  54. data/lib/authlogic/session/magic_columns.rb +21 -14
  55. data/lib/authlogic/session/magic_states.rb +25 -14
  56. data/lib/authlogic/session/params.rb +41 -26
  57. data/lib/authlogic/session/password.rb +62 -40
  58. data/lib/authlogic/session/perishable_token.rb +3 -2
  59. data/lib/authlogic/session/persistence.rb +3 -3
  60. data/lib/authlogic/session/priority_record.rb +5 -4
  61. data/lib/authlogic/session/scopes.rb +20 -9
  62. data/lib/authlogic/session/session.rb +9 -4
  63. data/lib/authlogic/session/timeout.rb +40 -23
  64. data/lib/authlogic/session/unauthorized_record.rb +6 -5
  65. data/lib/authlogic/session/validation.rb +18 -9
  66. data/lib/authlogic/test_case.rb +2 -2
  67. data/lib/authlogic/test_case/mock_controller.rb +9 -9
  68. data/lib/authlogic/test_case/mock_cookie_jar.rb +2 -2
  69. data/lib/authlogic/test_case/mock_logger.rb +1 -1
  70. data/lib/authlogic/test_case/mock_request.rb +2 -1
  71. data/lib/authlogic/test_case/rails_request_adapter.rb +5 -5
  72. data/test/acts_as_authentic_test/email_test.rb +29 -17
  73. data/test/acts_as_authentic_test/logged_in_status_test.rb +9 -3
  74. data/test/acts_as_authentic_test/login_test.rb +47 -13
  75. data/test/acts_as_authentic_test/magic_columns_test.rb +4 -4
  76. data/test/acts_as_authentic_test/password_test.rb +31 -21
  77. data/test/acts_as_authentic_test/perishable_token_test.rb +15 -15
  78. data/test/acts_as_authentic_test/session_maintenance_test.rb +20 -13
  79. data/test/acts_as_authentic_test/single_access_test.rb +8 -8
  80. data/test/authenticates_many_test.rb +4 -4
  81. data/test/crypto_provider_test/aes256_test.rb +2 -2
  82. data/test/crypto_provider_test/scrypt_test.rb +1 -1
  83. data/test/crypto_provider_test/sha1_test.rb +3 -3
  84. data/test/crypto_provider_test/sha256_test.rb +1 -1
  85. data/test/crypto_provider_test/sha512_test.rb +2 -2
  86. data/test/gemfiles/Gemfile.rails-3.2.x +2 -2
  87. data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
  88. data/test/i18n_test.rb +5 -5
  89. data/test/libs/affiliate.rb +2 -2
  90. data/test/libs/company.rb +1 -1
  91. data/test/libs/employee.rb +2 -2
  92. data/test/libs/employee_session.rb +1 -1
  93. data/test/libs/ldaper.rb +1 -1
  94. data/test/libs/project.rb +1 -1
  95. data/test/random_test.rb +5 -4
  96. data/test/session_test/activation_test.rb +5 -5
  97. data/test/session_test/active_record_trickery_test.rb +7 -5
  98. data/test/session_test/cookies_test.rb +8 -6
  99. data/test/session_test/existence_test.rb +19 -13
  100. data/test/session_test/http_auth_test.rb +0 -3
  101. data/test/session_test/id_test.rb +2 -2
  102. data/test/session_test/klass_test.rb +1 -1
  103. data/test/session_test/magic_columns_test.rb +0 -3
  104. data/test/session_test/magic_states_test.rb +11 -11
  105. data/test/session_test/params_test.rb +10 -10
  106. data/test/session_test/password_test.rb +4 -5
  107. data/test/session_test/perishability_test.rb +3 -3
  108. data/test/session_test/scopes_test.rb +8 -8
  109. data/test/session_test/session_test.rb +5 -4
  110. data/test/session_test/timeout_test.rb +8 -8
  111. data/test/session_test/unauthorized_record_test.rb +2 -2
  112. data/test/session_test/validation_test.rb +3 -3
  113. data/test/test_helper.rb +9 -5
  114. metadata +54 -24
  115. data/README.rdoc +0 -232
@@ -7,7 +7,7 @@ module Authlogic
7
7
  super("Your session is invalid and has the following errors: #{session.errors.full_messages.to_sentence}")
8
8
  end
9
9
  end
10
-
10
+
11
11
  def self.included(klass)
12
12
  klass.class_eval do
13
13
  extend ClassMethods
@@ -15,9 +15,9 @@ module Authlogic
15
15
  attr_accessor :new_session, :record
16
16
  end
17
17
  end
18
-
18
+
19
19
  module ClassMethods
20
- # A convenince method. The same as:
20
+ # A convenience method. The same as:
21
21
  #
22
22
  # session = UserSession.new(*args)
23
23
  # session.save
@@ -30,7 +30,7 @@ module Authlogic
30
30
  session.save(&block)
31
31
  session
32
32
  end
33
-
33
+
34
34
  # Same as create but calls create!, which raises an exception when validation fails.
35
35
  def create!(*args)
36
36
  session = new(*args)
@@ -38,9 +38,9 @@ module Authlogic
38
38
  session
39
39
  end
40
40
  end
41
-
41
+
42
42
  module InstanceMethods
43
- # Clears all errors and the associated record, you should call this terminate a session, thus requring
43
+ # Clears all errors and the associated record, you should call this terminate a session, thus requiring
44
44
  # the user to authenticate again if it is needed.
45
45
  def destroy
46
46
  before_destroy
@@ -50,16 +50,16 @@ module Authlogic
50
50
  after_destroy
51
51
  true
52
52
  end
53
-
53
+
54
54
  # Returns true if the session is new, meaning no action has been taken on it and a successful save
55
55
  # has not taken place.
56
56
  def new_session?
57
57
  new_session != false
58
58
  end
59
-
59
+
60
60
  # After you have specified all of the details for your session you can try to save it. This will
61
61
  # run validation checks and find the associated record, if all validation passes. If validation
62
- # does not pass, the save will fail and the erorrs will be stored in the errors object.
62
+ # does not pass, the save will fail and the errors will be stored in the errors object.
63
63
  def save(&block)
64
64
  result = nil
65
65
  if valid?
@@ -90,4 +90,4 @@ module Authlogic
90
90
  end
91
91
  end
92
92
  end
93
- end
93
+ end
@@ -1,8 +1,8 @@
1
1
  module Authlogic
2
2
  module Session
3
- # Sort of like an interface, it sets the foundation for the class, such as the required methods. This also allows
4
- # other modules to overwrite methods and call super on them. It's also a place to put "utility" methods used
5
- # throughout Authlogic.
3
+ # Sort of like an interface, it sets the foundation for the class, such as the
4
+ # required methods. This also allows other modules to overwrite methods and call super
5
+ # on them. It's also a place to put "utility" methods used throughout Authlogic.
6
6
  module Foundation
7
7
  def self.included(klass)
8
8
  klass.class_eval do
@@ -16,12 +16,14 @@ module Authlogic
16
16
  self.credentials = args
17
17
  end
18
18
 
19
- # The credentials you passed to create your session. See credentials= for more info.
19
+ # The credentials you passed to create your session. See credentials= for more
20
+ # info.
20
21
  def credentials
21
22
  []
22
23
  end
23
24
 
24
- # Set your credentials before you save your session. You can pass a hash of credentials:
25
+ # Set your credentials before you save your session. You can pass a hash of
26
+ # credentials:
25
27
  #
26
28
  # session.credentials = {:login => "my login", :password => "my password", :remember_me => true}
27
29
  #
@@ -29,8 +31,9 @@ module Authlogic
29
31
  #
30
32
  # session.credentials = [my_user_object, true]
31
33
  #
32
- # and if you need to set an id, just pass it last. This value need be the last item in the array you pass, since the id is something that
33
- # you control yourself, it should never be set from a hash or a form. Examples:
34
+ # and if you need to set an id, just pass it last. This value need be the last
35
+ # item in the array you pass, since the id is something that you control yourself,
36
+ # it should never be set from a hash or a form. Examples:
34
37
  #
35
38
  # session.credentials = [{:login => "my login", :password => "my password", :remember_me => true}, :my_id]
36
39
  # session.credentials = [my_user_object, true, :my_id]
@@ -42,6 +45,7 @@ module Authlogic
42
45
  end
43
46
 
44
47
  private
48
+
45
49
  def build_key(last_part)
46
50
  last_part
47
51
  end
@@ -14,7 +14,7 @@ module Authlogic
14
14
  persist :persist_by_http_auth, :if => :persist_by_http_auth?
15
15
  end
16
16
  end
17
-
17
+
18
18
  # Configuration for the HTTP basic auth feature of Authlogic.
19
19
  module Config
20
20
  # Do you want to allow your users to log in via HTTP basic auth?
@@ -64,14 +64,15 @@ module Authlogic
64
64
  end
65
65
  alias_method :http_basic_auth_realm=, :http_basic_auth_realm
66
66
  end
67
-
67
+
68
68
  # Instance methods for the HTTP basic auth feature of authlogic.
69
69
  module InstanceMethods
70
70
  private
71
+
71
72
  def persist_by_http_auth?
72
73
  allow_http_basic_auth? && login_field && password_field
73
74
  end
74
-
75
+
75
76
  def persist_by_http_auth
76
77
  login_proc = Proc.new do |login, password|
77
78
  if !login.blank? && !password.blank?
@@ -86,10 +87,10 @@ module Authlogic
86
87
  else
87
88
  controller.authenticate_with_http_basic(&login_proc)
88
89
  end
89
-
90
+
90
91
  false
91
92
  end
92
-
93
+
93
94
  def allow_http_basic_auth?
94
95
  self.class.allow_http_basic_auth == true
95
96
  end
@@ -7,14 +7,14 @@ module Authlogic
7
7
  attr_writer :id
8
8
  end
9
9
  end
10
-
10
+
11
11
  # Setting the id if it is passed in the credentials.
12
12
  def credentials=(value)
13
13
  super
14
14
  values = value.is_a?(Array) ? value : [value]
15
15
  self.id = values.last if values.last.is_a?(Symbol)
16
16
  end
17
-
17
+
18
18
  # Allows you to set a unique identifier for your session, so that you can have more than 1 session at a time.
19
19
  # A good example when this might be needed is when you want to have a normal user session and a "secure" user session.
20
20
  # The secure user session would be created only when they want to modify their billing information, or other sensitive
@@ -30,12 +30,13 @@ module Authlogic
30
30
  def id
31
31
  @id
32
32
  end
33
-
33
+
34
34
  private
35
+
35
36
  # Used for things like cookie_key, session_key, etc.
36
37
  def build_key(last_part)
37
38
  [id, super].compact.join("_")
38
39
  end
39
40
  end
40
41
  end
41
- end
42
+ end
@@ -56,6 +56,7 @@ module Authlogic
56
56
  end
57
57
 
58
58
  private
59
+
59
60
  def klass
60
61
  self.class.klass
61
62
  end
@@ -66,4 +67,4 @@ module Authlogic
66
67
  end
67
68
  end
68
69
  end
69
- end
70
+ end
@@ -1,15 +1,19 @@
1
1
  module Authlogic
2
2
  module Session
3
- # Just like ActiveRecord has "magic" columns, such as: created_at and updated_at. Authlogic has its own "magic" columns too:
3
+ # Just like ActiveRecord has "magic" columns, such as: created_at and updated_at.
4
+ # Authlogic has its own "magic" columns too:
4
5
  #
5
- # Column name Description
6
- # login_count Increased every time an explicit login is made. This will *NOT* increase if logging in by a session, cookie, or basic http auth
7
- # failed_login_count This increases for each consecutive failed login. See Authlogic::Session::BruteForceProtection and the consecutive_failed_logins_limit config option for more details.
8
- # last_request_at Updates every time the user logs in, either by explicitly logging in, or logging in by cookie, session, or http auth
9
- # current_login_at Updates with the current time when an explicit login is made.
10
- # last_login_at Updates with the value of current_login_at before it is reset.
11
- # current_login_ip Updates with the request ip when an explicit login is made.
12
- # last_login_ip Updates with the value of current_login_ip before it is reset.
6
+ # * login_count - Increased every time an explicit login is made. This will *NOT*
7
+ # increase if logging in by a session, cookie, or basic http auth
8
+ # * failed_login_count - This increases for each consecutive failed login. See
9
+ # Authlogic::Session::BruteForceProtection and the consecutive_failed_logins_limit
10
+ # config option for more details.
11
+ # * last_request_at - Updates every time the user logs in, either by explicitly
12
+ # logging in, or logging in by cookie, session, or http auth
13
+ # * current_login_at - Updates with the current time when an explicit login is made.
14
+ # * last_login_at - Updates with the value of current_login_at before it is reset.
15
+ # * current_login_ip - Updates with the request ip when an explicit login is made.
16
+ # * last_login_ip - Updates with the value of current_login_ip before it is reset.
13
17
  module MagicColumns
14
18
  def self.included(klass)
15
19
  klass.class_eval do
@@ -24,10 +28,12 @@ module Authlogic
24
28
 
25
29
  # Configuration for the magic columns feature.
26
30
  module Config
27
- # Every time a session is found the last_request_at field for that record is updated with the current time, if that field exists.
28
- # If you want to limit how frequent that field is updated specify the threshold here. For example, if your user is making a
29
- # request every 5 seconds, and you feel this is too frequent, and feel a minute is a good threshold. Set this to 1.minute.
30
- # Once a minute has passed in between requests the field will be updated.
31
+ # Every time a session is found the last_request_at field for that record is
32
+ # updated with the current time, if that field exists. If you want to limit how
33
+ # frequent that field is updated specify the threshold here. For example, if your
34
+ # user is making a request every 5 seconds, and you feel this is too frequent, and
35
+ # feel a minute is a good threshold. Set this to 1.minute. Once a minute has
36
+ # passed in between requests the field will be updated.
31
37
  #
32
38
  # * <tt>Default:</tt> 0
33
39
  # * <tt>Accepts:</tt> integer representing time in seconds
@@ -40,6 +46,7 @@ module Authlogic
40
46
  # The methods available for an Authlogic::Session::Base object that make up the magic columns feature.
41
47
  module InstanceMethods
42
48
  private
49
+
43
50
  def increase_failed_login_count
44
51
  if invalid_password? && attempted_record.respond_to?(:failed_login_count)
45
52
  attempted_record.failed_login_count ||= 0
@@ -83,7 +90,7 @@ module Authlogic
83
90
  # You can do whatever you want with that method.
84
91
  def set_last_request_at? # :doc:
85
92
  return false if !record || !klass.column_names.include?("last_request_at")
86
- return controller.last_request_update_allowed? if controller.responds_to_last_request_update_allowed?
93
+ return false if controller.responds_to_last_request_update_allowed? && !controller.last_request_update_allowed?
87
94
  record.last_request_at.blank? || last_request_at_threshold.to_i.seconds.ago >= record.last_request_at
88
95
  end
89
96
 
@@ -1,18 +1,25 @@
1
1
  module Authlogic
2
2
  module Session
3
- # Authlogic tries to check the state of the record before creating the session. If your record responds to the following methods and any of them return false, validation will fail:
3
+ # Authlogic tries to check the state of the record before creating the session. If
4
+ # your record responds to the following methods and any of them return false,
5
+ # validation will fail:
4
6
  #
5
7
  # Method name Description
6
8
  # active? Is the record marked as active?
7
9
  # approved? Has the record been approved?
8
- # confirmed? Has the record been conirmed?
10
+ # confirmed? Has the record been confirmed?
9
11
  #
10
- # Authlogic does nothing to define these methods for you, its up to you to define what they mean. If your object responds to these methods Authlogic will use them, otherwise they are ignored.
12
+ # Authlogic does nothing to define these methods for you, its up to you to define what
13
+ # they mean. If your object responds to these methods Authlogic will use them,
14
+ # otherwise they are ignored.
11
15
  #
12
- # What's neat about this is that these are checked upon any type of login. When logging in explicitly, by cookie, session, or basic http auth.
13
- # So if you mark a user inactive in the middle of their session they wont be logged back in next time they refresh the page. Giving you complete control.
16
+ # What's neat about this is that these are checked upon any type of login. When
17
+ # logging in explicitly, by cookie, session, or basic http auth. So if you mark a user
18
+ # inactive in the middle of their session they wont be logged back in next time they
19
+ # refresh the page. Giving you complete control.
14
20
  #
15
- # Need Authlogic to check your own "state"? No problem, check out the hooks section below. Add in a before_validation to do your own checking. The sky is the limit.
21
+ # Need Authlogic to check your own "state"? No problem, check out the hooks section
22
+ # below. Add in a before_validation to do your own checking. The sky is the limit.
16
23
  module MagicStates
17
24
  def self.included(klass)
18
25
  klass.class_eval do
@@ -21,12 +28,14 @@ module Authlogic
21
28
  validate :validate_magic_states, :unless => :disable_magic_states?
22
29
  end
23
30
  end
24
-
31
+
25
32
  # Configuration for the magic states feature.
26
33
  module Config
27
- # Set this to true if you want to disable the checking of active?, approved?, and confirmed? on your record. This is more or less of a
28
- # convenience feature, since 99% of the time if those methods exist and return false you will not want the user logging in. You could
29
- # easily accomplish this same thing with a before_validation method or other callbacks.
34
+ # Set this to true if you want to disable the checking of active?, approved?, and
35
+ # confirmed? on your record. This is more or less of a convenience feature, since
36
+ # 99% of the time if those methods exist and return false you will not want the
37
+ # user logging in. You could easily accomplish this same thing with a
38
+ # before_validation method or other callbacks.
30
39
  #
31
40
  # * <tt>Default:</tt> false
32
41
  # * <tt>Accepts:</tt> Boolean
@@ -35,14 +44,16 @@ module Authlogic
35
44
  end
36
45
  alias_method :disable_magic_states=, :disable_magic_states
37
46
  end
38
-
39
- # The methods available for an Authlogic::Session::Base object that make up the magic states feature.
47
+
48
+ # The methods available for an Authlogic::Session::Base object that make up the
49
+ # magic states feature.
40
50
  module InstanceMethods
41
51
  private
52
+
42
53
  def disable_magic_states?
43
54
  self.class.disable_magic_states == true
44
55
  end
45
-
56
+
46
57
  def validate_magic_states
47
58
  return true if attempted_record.nil?
48
59
  [:active, :approved, :confirmed].each do |required_status|
@@ -56,4 +67,4 @@ module Authlogic
56
67
  end
57
68
  end
58
69
  end
59
- end
70
+ end
@@ -1,15 +1,19 @@
1
1
  module Authlogic
2
2
  module Session
3
- # This module is responsible for authenticating the user via params, which ultimately allows the user to log in using a URL like the following:
3
+ # This module is responsible for authenticating the user via params, which ultimately
4
+ # allows the user to log in using a URL like the following:
4
5
  #
5
6
  # https://www.domain.com?user_credentials=4LiXF7FiGUppIPubBPey
6
7
  #
7
- # Notice the token in the URL, this is a single access token. A single access token is used for single access only, it is not persisted. Meaning the user
8
- # provides it, Authlogic grants them access, and that's it. If they want access again they need to provide the token again. Authlogic will
9
- # *NEVER* try to persist the session after authenticating through this method.
8
+ # Notice the token in the URL, this is a single access token. A single access token is
9
+ # used for single access only, it is not persisted. Meaning the user provides it,
10
+ # Authlogic grants them access, and that's it. If they want access again they need to
11
+ # provide the token again. Authlogic will *NEVER* try to persist the session after
12
+ # authenticating through this method.
10
13
  #
11
- # For added security, this token is *ONLY* allowed for RSS and ATOM requests. You can change this with the configuration. You can also define if
12
- # it is allowed dynamically by defining a single_access_allowed? method in your controller. For example:
14
+ # For added security, this token is *ONLY* allowed for RSS and ATOM requests. You can
15
+ # change this with the configuration. You can also define if it is allowed dynamically
16
+ # by defining a single_access_allowed? method in your controller. For example:
13
17
  #
14
18
  # class UsersController < ApplicationController
15
19
  # private
@@ -17,8 +21,9 @@ module Authlogic
17
21
  # action_name == "index"
18
22
  # end
19
23
  #
20
- # Also, by default, this token is permanent. Meaning if the user changes their password, this token will remain the same. It will only change
21
- # when it is explicitly reset.
24
+ # Also, by default, this token is permanent. Meaning if the user changes their
25
+ # password, this token will remain the same. It will only change when it is explicitly
26
+ # reset.
22
27
  #
23
28
  # You can modify all of this behavior with the Config sub module.
24
29
  module Params
@@ -30,15 +35,19 @@ module Authlogic
30
35
  persist :persist_by_params
31
36
  end
32
37
  end
33
-
38
+
34
39
  # Configuration for the params / single access feature.
35
40
  module Config
36
- # Works exactly like cookie_key, but for params. So a user can login via params just like a cookie or a session. Your URL would look like:
41
+ # Works exactly like cookie_key, but for params. So a user can login via
42
+ # params just like a cookie or a session. Your URL would look like:
37
43
  #
38
44
  # http://www.domain.com?user_credentials=my_single_access_key
39
45
  #
40
- # You can change the "user_credentials" key above with this configuration option. Keep in mind, just like cookie_key, if you supply an id
41
- # the id will be appended to the front. Check out cookie_key for more details. Also checkout the "Single Access / Private Feeds Access" section in the README.
46
+ # You can change the "user_credentials" key above with this
47
+ # configuration option. Keep in mind, just like cookie_key, if you
48
+ # supply an id the id will be appended to the front. Check out
49
+ # cookie_key for more details. Also checkout the "Single Access /
50
+ # Private Feeds Access" section in the README.
42
51
  #
43
52
  # * <tt>Default:</tt> cookie_key
44
53
  # * <tt>Accepts:</tt> String
@@ -46,56 +55,62 @@ module Authlogic
46
55
  rw_config(:params_key, value, cookie_key)
47
56
  end
48
57
  alias_method :params_key=, :params_key
49
-
50
- # Authentication is allowed via a single access token, but maybe this is something you don't want for your application as a whole. Maybe this is
51
- # something you only want for specific request types. Specify a list of allowed request types and single access authentication will only be
58
+
59
+ # Authentication is allowed via a single access token, but maybe this is
60
+ # something you don't want for your application as a whole. Maybe this
61
+ # is something you only want for specific request types. Specify a list
62
+ # of allowed request types and single access authentication will only be
52
63
  # allowed for the ones you specify.
53
64
  #
54
65
  # * <tt>Default:</tt> ["application/rss+xml", "application/atom+xml"]
55
- # * <tt>Accepts:</tt> String of a request type, or :all or :any to allow single access authentication for any and all request types
66
+ # * <tt>Accepts:</tt> String of a request type, or :all or :any to
67
+ # allow single access authentication for any and all request types
56
68
  def single_access_allowed_request_types(value = nil)
57
69
  rw_config(:single_access_allowed_request_types, value, ["application/rss+xml", "application/atom+xml"])
58
70
  end
59
71
  alias_method :single_access_allowed_request_types=, :single_access_allowed_request_types
60
72
  end
61
-
62
- # The methods available for an Authlogic::Session::Base object that make up the params / single access feature.
73
+
74
+ # The methods available for an Authlogic::Session::Base object that make
75
+ # up the params / single access feature.
63
76
  module InstanceMethods
64
77
  private
78
+
65
79
  def persist_by_params
66
80
  return false if !params_enabled?
67
81
  self.unauthorized_record = search_for_record("find_by_single_access_token", params_credentials)
68
82
  self.single_access = valid?
69
83
  end
70
-
84
+
71
85
  def params_enabled?
72
86
  return false if !params_credentials || !klass.column_names.include?("single_access_token")
73
87
  return controller.single_access_allowed? if controller.responds_to_single_access_allowed?
74
-
88
+
75
89
  case single_access_allowed_request_types
76
90
  when Array
77
- single_access_allowed_request_types.include?(controller.request_content_type) || single_access_allowed_request_types.include?(:all)
91
+ single_access_allowed_request_types.include?(controller.request_content_type) ||
92
+ single_access_allowed_request_types.include?(:all)
78
93
  else
79
94
  [:all, :any].include?(single_access_allowed_request_types)
80
95
  end
81
96
  end
82
-
97
+
83
98
  def params_key
84
99
  build_key(self.class.params_key)
85
100
  end
86
-
101
+
87
102
  def single_access?
88
103
  single_access == true
89
104
  end
90
-
105
+
91
106
  def single_access_allowed_request_types
92
107
  self.class.single_access_allowed_request_types
93
108
  end
94
-
109
+
95
110
  def params_credentials
96
111
  controller.params[params_key]
97
112
  end
98
113
  end
99
114
  end
100
115
  end
101
- end
116
+ end