authlogic 1.4.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of authlogic might be problematic. Click here for more details.

Files changed (131) hide show
  1. data/CHANGELOG.rdoc +19 -0
  2. data/Manifest.txt +111 -0
  3. data/README.rdoc +116 -389
  4. data/Rakefile +14 -7
  5. data/lib/authlogic.rb +33 -35
  6. data/lib/authlogic/acts_as_authentic/base.rb +91 -0
  7. data/lib/authlogic/acts_as_authentic/email.rb +77 -0
  8. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +54 -0
  9. data/lib/authlogic/acts_as_authentic/login.rb +65 -0
  10. data/lib/authlogic/acts_as_authentic/magic_columns.rb +24 -0
  11. data/lib/authlogic/acts_as_authentic/password.rb +215 -0
  12. data/lib/authlogic/acts_as_authentic/perishable_token.rb +100 -0
  13. data/lib/authlogic/acts_as_authentic/persistence_token.rb +66 -0
  14. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +60 -0
  15. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +127 -0
  16. data/lib/authlogic/acts_as_authentic/single_access_token.rb +58 -0
  17. data/lib/authlogic/acts_as_authentic/validations_scope.rb +32 -0
  18. data/lib/authlogic/{session/authenticates_many_association.rb → authenticates_many/association.rb} +10 -6
  19. data/lib/authlogic/authenticates_many/base.rb +55 -0
  20. data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -3
  21. data/lib/authlogic/controller_adapters/merb_adapter.rb +0 -4
  22. data/lib/authlogic/controller_adapters/rails_adapter.rb +0 -4
  23. data/lib/authlogic/crypto_providers/aes256.rb +0 -2
  24. data/lib/authlogic/crypto_providers/bcrypt.rb +0 -2
  25. data/lib/authlogic/crypto_providers/md5.rb +34 -0
  26. data/lib/authlogic/crypto_providers/sha1.rb +0 -2
  27. data/lib/authlogic/crypto_providers/sha512.rb +1 -3
  28. data/lib/authlogic/i18n.rb +1 -4
  29. data/lib/authlogic/random.rb +33 -0
  30. data/lib/authlogic/session/activation.rb +56 -0
  31. data/lib/authlogic/session/active_record_trickery.rb +15 -7
  32. data/lib/authlogic/session/base.rb +31 -456
  33. data/lib/authlogic/session/brute_force_protection.rb +50 -27
  34. data/lib/authlogic/session/callbacks.rb +24 -15
  35. data/lib/authlogic/session/cookies.rb +108 -22
  36. data/lib/authlogic/session/existence.rb +89 -0
  37. data/lib/authlogic/session/foundation.rb +63 -0
  38. data/lib/authlogic/session/http_auth.rb +23 -0
  39. data/lib/authlogic/session/id.rb +41 -0
  40. data/lib/authlogic/session/klass.rb +75 -0
  41. data/lib/authlogic/session/magic_columns.rb +75 -0
  42. data/lib/authlogic/session/magic_states.rb +58 -0
  43. data/lib/authlogic/session/params.rb +82 -19
  44. data/lib/authlogic/session/password.rb +156 -0
  45. data/lib/authlogic/session/{perishability.rb → perishable_token.rb} +4 -4
  46. data/lib/authlogic/session/persistence.rb +70 -0
  47. data/lib/authlogic/session/priority_record.rb +34 -0
  48. data/lib/authlogic/session/scopes.rb +57 -53
  49. data/lib/authlogic/session/session.rb +46 -31
  50. data/lib/authlogic/session/timeout.rb +65 -31
  51. data/lib/authlogic/session/unauthorized_record.rb +50 -0
  52. data/lib/authlogic/session/validation.rb +76 -0
  53. data/lib/authlogic/testing/test_unit_helpers.rb +3 -3
  54. data/lib/authlogic/version.rb +3 -3
  55. data/test/acts_as_authentic_test/base_test.rb +12 -0
  56. data/test/acts_as_authentic_test/email_test.rb +79 -0
  57. data/test/acts_as_authentic_test/logged_in_status_test.rb +36 -0
  58. data/test/acts_as_authentic_test/login_test.rb +79 -0
  59. data/test/acts_as_authentic_test/magic_columns_test.rb +27 -0
  60. data/test/acts_as_authentic_test/password_test.rb +212 -0
  61. data/test/acts_as_authentic_test/perishable_token_test.rb +56 -0
  62. data/test/acts_as_authentic_test/persistence_token_test.rb +55 -0
  63. data/test/acts_as_authentic_test/session_maintenance_test.rb +68 -0
  64. data/test/acts_as_authentic_test/single_access_test.rb +39 -0
  65. data/test/authenticates_many_test.rb +16 -0
  66. data/test/{crypto_provider_tests → crypto_provider_test}/aes256_test.rb +1 -1
  67. data/test/{crypto_provider_tests → crypto_provider_test}/bcrypt_test.rb +1 -1
  68. data/test/{crypto_provider_tests → crypto_provider_test}/sha1_test.rb +1 -1
  69. data/test/{crypto_provider_tests → crypto_provider_test}/sha512_test.rb +1 -1
  70. data/test/fixtures/employees.yml +4 -4
  71. data/test/fixtures/users.yml +6 -6
  72. data/test/libs/company.rb +6 -0
  73. data/test/libs/employee.rb +7 -0
  74. data/test/libs/employee_session.rb +2 -0
  75. data/test/libs/project.rb +3 -0
  76. data/test/libs/user_session.rb +2 -0
  77. data/test/random_test.rb +49 -0
  78. data/test/session_test/activation_test.rb +43 -0
  79. data/test/session_test/active_record_trickery_test.rb +26 -0
  80. data/test/session_test/brute_force_protection_test.rb +76 -0
  81. data/test/session_test/callbacks_test.rb +6 -0
  82. data/test/session_test/cookies_test.rb +107 -0
  83. data/test/session_test/credentials_test.rb +0 -0
  84. data/test/session_test/existence_test.rb +64 -0
  85. data/test/session_test/http_auth_test.rb +16 -0
  86. data/test/session_test/id_test.rb +17 -0
  87. data/test/session_test/klass_test.rb +35 -0
  88. data/test/session_test/magic_columns_test.rb +59 -0
  89. data/test/session_test/magic_states_test.rb +60 -0
  90. data/test/session_test/params_test.rb +53 -0
  91. data/test/session_test/password_test.rb +84 -0
  92. data/test/{session_tests → session_test}/perishability_test.rb +1 -1
  93. data/test/session_test/persistence_test.rb +21 -0
  94. data/test/{session_tests → session_test}/scopes_test.rb +2 -3
  95. data/test/session_test/session_test.rb +59 -0
  96. data/test/session_test/timeout_test.rb +43 -0
  97. data/test/session_test/unauthorized_record_test.rb +13 -0
  98. data/test/session_test/validation_test.rb +23 -0
  99. data/test/test_helper.rb +14 -29
  100. metadata +120 -112
  101. data/Manifest +0 -76
  102. data/authlogic.gemspec +0 -38
  103. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/base.rb +0 -22
  104. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb +0 -238
  105. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb +0 -155
  106. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb +0 -51
  107. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb +0 -71
  108. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb +0 -94
  109. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb +0 -87
  110. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb +0 -61
  111. data/lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb +0 -58
  112. data/lib/authlogic/session/config.rb +0 -421
  113. data/lib/authlogic/session/errors.rb +0 -18
  114. data/lib/authlogic/session/record_info.rb +0 -24
  115. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb +0 -154
  116. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb +0 -157
  117. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb +0 -24
  118. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb +0 -41
  119. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb +0 -54
  120. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb +0 -62
  121. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb +0 -41
  122. data/test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb +0 -32
  123. data/test/session_tests/active_record_trickery_test.rb +0 -14
  124. data/test/session_tests/authenticates_many_association_test.rb +0 -28
  125. data/test/session_tests/base_test.rb +0 -307
  126. data/test/session_tests/brute_force_protection_test.rb +0 -53
  127. data/test/session_tests/config_test.rb +0 -184
  128. data/test/session_tests/cookies_test.rb +0 -32
  129. data/test/session_tests/params_test.rb +0 -32
  130. data/test/session_tests/session_test.rb +0 -45
  131. data/test/session_tests/timeout_test.rb +0 -71
@@ -0,0 +1,100 @@
1
+ module Authlogic
2
+ module ActsAsAuthentic
3
+ # This provides a handy token that is "perishable". Meaning the token is only good for a certain amount of time. This is perfect for
4
+ # resetting password, confirming accounts, etc. Typically during these actions you send them this token in via their email. Once they
5
+ # use the token and do what they need to do, that token should expire. Don't worry about maintaining this, changing it, or expiring it
6
+ # yourself. Authlogic does all of this for you. See the sub modules for all of the tools Authlogic provides to you.
7
+ module PerishableToken
8
+ def self.included(klass)
9
+ klass.class_eval do
10
+ extend Config
11
+ add_acts_as_authentic_module(Methods)
12
+ end
13
+ end
14
+
15
+ # Change how the perishable token works.
16
+ module Config
17
+ # When using the find_using_perishable_token method the token can expire. If the token is expired, no
18
+ # record will be returned. Use this option to specify how long the token is valid for.
19
+ #
20
+ # * <tt>Default:</tt> 10.minutes
21
+ # * <tt>Accepts:</tt> Fixnum
22
+ def perishable_token_valid_for(value = nil)
23
+ config(:perishable_token_valid_for, (!value.nil? && value.to_i) || value, 10.minutes.to_i)
24
+ end
25
+ alias_method :perishable_token_valid_for=, :perishable_token_valid_for
26
+
27
+ # Authlogic tries to expire and change the perishable token as much as possible, without comprising
28
+ # it's purpose. This is for security reasons. If you want to manage it yourself, you can stop
29
+ # Authlogic from getting your in way by setting this to true.
30
+ #
31
+ # * <tt>Default:</tt> false
32
+ # * <tt>Accepts:</tt> Boolean
33
+ def disable_perishable_token_maintenance(value = nil)
34
+ config(:disable_perishable_token_maintenance, value, false)
35
+ end
36
+ alias_method :disable_perishable_token_maintenance=, :disable_perishable_token_maintenance
37
+ end
38
+
39
+ # All methods relating to the perishable token.
40
+ module Methods
41
+ def self.included(klass)
42
+ return if !klass.column_names.include?("perishable_token")
43
+
44
+ klass.class_eval do
45
+ extend ClassMethods
46
+ include InstanceMethods
47
+
48
+ validates_uniqueness_of :perishable_token, :if => :perishable_token_changed?
49
+ before_save :reset_perishable_token, :unless => :disable_perishable_token_maintenance?
50
+ end
51
+ end
52
+
53
+ # Class level methods for the perishable token
54
+ module ClassMethods
55
+ # Use this methdo to find a record with a perishable token. This method does 2 things for you:
56
+ #
57
+ # 1. It ignores blank tokens
58
+ # 2. It enforces the perishable_token_valid_for configuration option.
59
+ #
60
+ # If you want to use a different timeout value, just pass it as the second parameter:
61
+ #
62
+ # User.find_using_perishable_token(token, 1.hour)
63
+ def find_using_perishable_token(token, age = perishable_token_valid_for)
64
+ return if token.blank?
65
+ age = age.to_i
66
+
67
+ conditions_sql = "perishable_token = ?"
68
+ conditions_subs = [token]
69
+
70
+ if column_names.include?("updated_at") && age > 0
71
+ conditions_sql += " and updated_at > ?"
72
+ conditions_subs << age.seconds.ago
73
+ end
74
+
75
+ find(:first, :conditions => [conditions_sql, *conditions_subs])
76
+ end
77
+ end
78
+
79
+ # Instance level methods for the perishable token.
80
+ module InstanceMethods
81
+ # Resets the perishable token to a random friendly token.
82
+ def reset_perishable_token
83
+ self.perishable_token = Random.friendly_token
84
+ end
85
+
86
+ # Same as reset_perishable_token, but then saves the record afterwards.
87
+ def reset_perishable_token!
88
+ reset_perishable_token
89
+ save_without_session_maintenance(false)
90
+ end
91
+
92
+ # A convenience method based on the disable_perishable_token_maintenance configuration option.
93
+ def disable_perishable_token_maintenance?
94
+ self.class.disable_perishable_token_maintenance == true
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,66 @@
1
+ module Authlogic
2
+ module ActsAsAuthentic
3
+ # Maintains the persistence token, the token responsible for persisting sessions. This token
4
+ # gets stores in the session and the cookie.
5
+ module PersistenceToken
6
+ def self.included(klass)
7
+ klass.class_eval do
8
+ add_acts_as_authentic_module(Methods)
9
+ end
10
+ end
11
+
12
+ # Methods for the persistence token.
13
+ module Methods
14
+ def self.included(klass)
15
+ klass.class_eval do
16
+ extend ClassMethods
17
+ include InstanceMethods
18
+
19
+ after_password_set :reset_persistence_token
20
+ after_password_verification :reset_persistence_token!, :if => :reset_persistence_token?
21
+
22
+ validates_presence_of :persistence_token
23
+ validates_uniqueness_of :persistence_token, :if => :persistence_token_changed?
24
+
25
+ before_validation :reset_persistence_token, :if => :reset_persistence_token?
26
+ end
27
+ end
28
+
29
+ # Class level methods for the persistence token.
30
+ module ClassMethods
31
+ # Resets ALL persistence tokens in the database, which will require all users to reauthenticate.
32
+ def forget_all
33
+ # Paginate these to save on memory
34
+ records = nil
35
+ i = 0
36
+ begin
37
+ records = find(:all, :limit => 50, :offset => i)
38
+ records.each { |record| record.forget! }
39
+ i += 50
40
+ end while !records.blank?
41
+ end
42
+ end
43
+
44
+ # Instance level methods for the persistence token.
45
+ module InstanceMethods
46
+ # Resets the persistence_token field to a random hex value.
47
+ def reset_persistence_token
48
+ self.persistence_token = Authlogic::Random.hex_token
49
+ end
50
+
51
+ # Same as reset_persistence_token, but then saves the record.
52
+ def reset_persistence_token!
53
+ reset_persistence_token
54
+ save_without_session_maintenance(false)
55
+ end
56
+ alias_method :forget!, :reset_persistence_token!
57
+
58
+ private
59
+ def reset_persistence_token?
60
+ persistence_token.blank?
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,60 @@
1
+ module Authlogic
2
+ module ActsAsAuthentic
3
+ # This module is responsible for transitioning existing applications from the restful_authentication plugin.
4
+ module RestfulAuthentication
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ extend Config
8
+ include InstanceMethods
9
+ end
10
+ end
11
+
12
+ module Config
13
+ # Switching an existing app to Authlogic from restful_authentication? No problem, just set this true and your users won't know
14
+ # anything changed. From your database perspective nothing will change at all. Authlogic will continue to encrypt passwords
15
+ # just like restful_authentication, so your app won't skip a beat. Although, might consider transitioning your users to a newer
16
+ # and stronger algorithm. Checkout the transition_from_restful_authentication option.
17
+ #
18
+ # * <tt>Default:</tt> false
19
+ # * <tt>Accepts:</tt> Boolean
20
+ def act_like_restful_authentication(value = nil)
21
+ r = config(:act_like_restful_authentication, value, false)
22
+ set_restful_authentication_config if value
23
+ r
24
+ end
25
+ alias_method :act_like_restful_authentication=, :act_like_restful_authentication
26
+
27
+ # This works just like act_like_restful_authentication except that it will start transitioning your users to the algorithm you
28
+ # specify with the crypto provider option. The next time they log in it will resave their password with the new algorithm
29
+ # and any new record will use the new algorithm as well.
30
+ def transition_from_restful_authentication(value = nil)
31
+ r = config(:transition_from_restful_authentication, value, false)
32
+ set_restful_authentication_config if value
33
+ r
34
+ end
35
+ alias_method :transition_from_restful_authentication=, :transition_from_restful_authentication
36
+
37
+ private
38
+ def set_restful_authentication_config
39
+ crypto_provider_key = act_like_restful_authentication ? :crypto_provider : :transition_from_crypto_providers
40
+ self.send("#{crypto_provider_key}=", CryptoProviders::Sha1)
41
+ if !defined?(::REST_AUTH_SITE_KEY) || ::REST_AUTH_SITE_KEY.nil?
42
+ class_eval("::REST_AUTH_SITE_KEY = nil") if !defined?(::REST_AUTH_SITE_KEY)
43
+ CryptoProviders::Sha1.stretches = 1
44
+ end
45
+ end
46
+ end
47
+
48
+ module InstanceMethods
49
+ private
50
+ def act_like_restful_authentication?
51
+ self.class.act_like_restful_authentication == true
52
+ end
53
+
54
+ def transition_from_restful_authentication?
55
+ self.class.transition_from_restful_authentication == true
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,127 @@
1
+ module Authlogic
2
+ module ActsAsAuthentic
3
+ # This is one of my favorite features that I think is pretty cool. It's things like this that make a library great
4
+ # and let you know you are on the right track.
5
+ #
6
+ # Just to clear up any confusion, Authlogic stores both the record id and the persistence token in the session.
7
+ # Why? So stale sessions can not be persisted. It stores the id so it can quickly find the record, and the
8
+ # persistence token to ensure no sessions are stale. So if the persistence token changes, the user muct log
9
+ # back in.
10
+ #
11
+ # Well, the persistence token changes with the password. What happens if the user changes his own password?
12
+ # He shouldn't have to log back in, he's the one that made the change.
13
+ #
14
+ # That being said, wouldn't it be nice if their session and cookie information was automatically updated?
15
+ # Instead of cluttering up your controller with redundant session code. The same thing goes for new
16
+ # registrations.
17
+ #
18
+ # That's what this module is all about. This will automatically maintain the cookie and session values as
19
+ # records are saved.
20
+ module SessionMaintenance
21
+ def self.included(klass)
22
+ klass.class_eval do
23
+ extend Config
24
+ add_acts_as_authentic_module(Methods)
25
+ end
26
+ end
27
+
28
+ module Config
29
+ # As you may know, authlogic sessions can be separate by id (See Authlogic::Session::Base#id). You can
30
+ # specify here what session ids you want auto maintained. By default it is the main session, which has
31
+ # an id of nil.
32
+ #
33
+ # * <tt>Default:</tt> [nil]
34
+ # * <tt>Accepts:</tt> Array
35
+ def session_ids(value = nil)
36
+ config(:session_ids, value, [nil])
37
+ end
38
+ alias_method :session_ids=, :session_ids
39
+
40
+ # The name of the associated session class. This is inferred by the name of the model.
41
+ #
42
+ # * <tt>Default:</tt> "#{klass.name}Session".constantize
43
+ # * <tt>Accepts:</tt> Class
44
+ def session_class(value = nil)
45
+ config(:session_class, value, "#{name}Session".constantize)
46
+ end
47
+ alias_method :session_class=, :session_class
48
+ end
49
+
50
+ module Methods
51
+ def self.included(klass)
52
+ klass.class_eval do
53
+ before_save :get_session_information, :if => :update_sessions?
54
+ before_save :maintain_sessions, :if => :update_sessions?
55
+ end
56
+ end
57
+
58
+ # Save the record and skip session maintenance all together.
59
+ def save_without_session_maintenance(*args)
60
+ self.skip_session_maintenance = true
61
+ result = save(*args)
62
+ self.skip_session_maintenance = false
63
+ result
64
+ end
65
+
66
+ private
67
+ def skip_session_maintenance=(value)
68
+ @skip_session_maintenance = value
69
+ end
70
+
71
+ def skip_session_maintenance
72
+ @skip_session_maintenance ||= false
73
+ end
74
+
75
+ def update_sessions?
76
+ !skip_session_maintenance && session_class.activated? && !session_ids.blank? && persistence_token_changed?
77
+ end
78
+
79
+ def get_session_information
80
+ # Need to determine if we are completely logged out, or logged in as another user
81
+ @_sessions = []
82
+
83
+ session_ids.each do |session_id|
84
+ session = session_class.find(session_id, self)
85
+ @_sessions << session if session && session.record
86
+ end
87
+ end
88
+
89
+ def maintain_sessions
90
+ if @_sessions.empty?
91
+ create_session
92
+ else
93
+ update_sessions
94
+ end
95
+ end
96
+
97
+ def create_session
98
+ # We only want to automatically login into the first session, since this is the main session. The other sessions are sessions
99
+ # that need to be created after logging into the main session.
100
+ session_id = session_ids.first
101
+ session_class.create!(*[self, self, session_id].compact)
102
+
103
+ return true
104
+ end
105
+
106
+ def update_sessions
107
+ # We found sessions above, let's update them with the new info
108
+ @_sessions.each do |stale_session|
109
+ next if stale_session.record != self
110
+ stale_session.unauthorized_record = self
111
+ stale_session.save
112
+ end
113
+
114
+ return true
115
+ end
116
+
117
+ def session_ids
118
+ self.class.session_ids
119
+ end
120
+
121
+ def session_class
122
+ self.class.session_class
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,58 @@
1
+ module Authlogic
2
+ module ActsAsAuthentic
3
+ # This module is responsible for maintaining the single_access token. For more information the single access token and how to use it,
4
+ # see the Authlogic::Session::Params module.
5
+ module SingleAccessToken
6
+ def self.included(klass)
7
+ klass.class_eval do
8
+ extend Config
9
+ add_acts_as_authentic_module(Methods)
10
+ end
11
+ end
12
+
13
+ # All configuration for the single_access token aspect of acts_as_authentic.
14
+ module Config
15
+ def change_single_access_token_with_password(value = nil)
16
+ config(:change_single_access_token_with_password, value, false)
17
+ end
18
+ alias_method :change_single_access_token_with_password=, :change_single_access_token_with_password
19
+ end
20
+
21
+ # All method, for the single_access token aspect of acts_as_authentic.
22
+ module Methods
23
+ def self.included(klass)
24
+ return if !klass.column_names.include?("single_access_token")
25
+
26
+ klass.class_eval do
27
+ include InstanceMethods
28
+ validates_uniqueness_of :single_access_token, :if => :single_access_token_changed?
29
+ before_validation :reset_single_access_token, :if => :reset_single_access_token?
30
+ after_password_set :reset_single_access_token, :if => :change_single_access_token_with_password?
31
+ end
32
+ end
33
+
34
+ module InstanceMethods
35
+ # Resets the single_access_token to a random friendly token.
36
+ def reset_single_access_token
37
+ self.single_access_token = Authlogic::Random.friendly_token
38
+ end
39
+
40
+ # same as reset_single_access_token, but then saves the record.
41
+ def reset_single_access_token!
42
+ reset_single_access_token
43
+ save_without_session_maintenance
44
+ end
45
+
46
+ protected
47
+ def reset_single_access_token?
48
+ single_access_token.blank?
49
+ end
50
+
51
+ def change_single_access_token_with_password?
52
+ self.class.change_single_access_token_with_password == true
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+ module Authlogic
2
+ module ActsAsAuthentic
3
+ # Allows you to scope everything to specific fields.
4
+ # See the Config submodule for more info.
5
+ # For information on how to scope off of a parent object see Authlogic::AuthenticatesMany
6
+ module ValidationsScope
7
+ def self.included(klass)
8
+ klass.class_eval do
9
+ extend Config
10
+ end
11
+ end
12
+
13
+ # All configuration for the scope feature.
14
+ module Config
15
+ # Allows you to scope everything to specific field(s). Works just like validates_uniqueness_of.
16
+ # For example, let's say a user belongs to a company, and you want to scope everything to the
17
+ # company:
18
+ #
19
+ # acts_as_authentic do |c|
20
+ # c.validation_scope = :company_id
21
+ # end
22
+ #
23
+ # * <tt>Default:</tt> nil
24
+ # * <tt>Accepts:</tt> Symbol or Array of symbols
25
+ def validations_scope(value = nil)
26
+ config(:validations_scope, value)
27
+ end
28
+ alias_method :validations_scope=, :validations_scope
29
+ end
30
+ end
31
+ end
32
+ end