authlogic 1.1.0 → 1.1.1
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.
- data/CHANGELOG.rdoc +11 -2
- data/Manifest +9 -3
- data/README.rdoc +32 -7
- data/Rakefile +1 -1
- data/authlogic.gemspec +4 -7
- data/lib/authlogic.rb +2 -4
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +4 -0
- data/lib/authlogic/controller_adapters/rails_adapter.rb +4 -0
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb +2 -76
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb +132 -0
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb +77 -116
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb +35 -24
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb +51 -44
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb +64 -54
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb +61 -0
- data/lib/authlogic/session/base.rb +20 -9
- data/lib/authlogic/session/config.rb +54 -63
- data/lib/authlogic/session/cookies.rb +2 -2
- data/lib/authlogic/session/params.rb +9 -6
- data/lib/authlogic/session/session.rb +3 -3
- data/lib/authlogic/version.rb +1 -1
- data/shoulda_macros/authlogic.rb +13 -0
- data/test/fixtures/employees.yml +2 -2
- data/test/fixtures/users.yml +2 -0
- data/test/libs/mock_controller.rb +5 -0
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb +36 -0
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb +129 -0
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb +24 -0
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb +45 -0
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb +62 -0
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb +41 -0
- data/test/session_tests/base_test.rb +15 -0
- data/test/session_tests/config_test.rb +31 -14
- data/test/session_tests/params_test.rb +17 -1
- data/test/test_helper.rb +10 -2
- metadata +18 -17
- data/lib/authlogic/session/openid.rb +0 -106
- data/lib/authlogic/testing/shoulda_macros.rb +0 -17
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_test.rb +0 -217
@@ -0,0 +1,61 @@
|
|
1
|
+
module Authlogic
|
2
|
+
module ORMAdapters
|
3
|
+
module ActiveRecordAdapter
|
4
|
+
module ActsAsAuthentic
|
5
|
+
# = Single Access
|
6
|
+
#
|
7
|
+
# Instead of repeating myself here, checkout the README. There is a "Single Access" section in there that goes over this. Keep in mind none of this will be applied if there
|
8
|
+
# is not a single_access_token field supplied in the database.
|
9
|
+
#
|
10
|
+
# === Instance Methods
|
11
|
+
#
|
12
|
+
# * <tt>reset_{options[:single_access_token_field]}</tt> - resets the single access token with the friendly_unique_token
|
13
|
+
# * <tt>reset_{options[:single_access_token_field]}!</tt> - same as above, but saves the record afterwards
|
14
|
+
#
|
15
|
+
# === Alias Method Chains
|
16
|
+
#
|
17
|
+
# * <tt>{options[:password_field]}</tt> - if the :change_single_access_token_with_password is set to true, reset_{options[:single_access_token_field]} will be called when the password changes
|
18
|
+
module SingleAccess
|
19
|
+
def acts_as_authentic_with_single_access(options = {})
|
20
|
+
acts_as_authentic_without_single_access(options)
|
21
|
+
|
22
|
+
if options[:single_access_token_field]
|
23
|
+
class_eval <<-"end_eval", __FILE__, __LINE__
|
24
|
+
validates_uniqueness_of :#{options[:single_access_token_field]}
|
25
|
+
|
26
|
+
before_validation :set_#{options[:single_access_token_field]}_field
|
27
|
+
|
28
|
+
def password_with_single_access=(value)
|
29
|
+
reset_#{options[:single_access_token_field]} if #{options[:change_single_access_token_with_password].inspect}
|
30
|
+
self.password_without_single_access = value
|
31
|
+
end
|
32
|
+
alias_method_chain :password=, :single_access
|
33
|
+
|
34
|
+
def reset_#{options[:single_access_token_field]}
|
35
|
+
self.#{options[:single_access_token_field]} = self.class.friendly_unique_token
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset_#{options[:single_access_token_field]}!
|
39
|
+
reset_#{options[:single_access_token_field]}
|
40
|
+
save_without_session_maintenance
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
def set_#{options[:single_access_token_field]}_field
|
45
|
+
reset_#{options[:single_access_token_field]} if #{options[:single_access_token_field]}.blank?
|
46
|
+
end
|
47
|
+
end_eval
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
ActiveRecord::Base.class_eval do
|
57
|
+
class << self
|
58
|
+
include Authlogic::ORMAdapters::ActiveRecordAdapter::ActsAsAuthentic::SingleAccess
|
59
|
+
alias_method_chain :acts_as_authentic, :single_access
|
60
|
+
end
|
61
|
+
end
|
@@ -82,20 +82,18 @@ module Authlogic
|
|
82
82
|
|
83
83
|
attr_accessor :new_session
|
84
84
|
attr_reader :record, :unauthorized_record
|
85
|
-
attr_writer :authenticating_with, :id
|
85
|
+
attr_writer :authenticating_with, :id, :persisting
|
86
86
|
|
87
87
|
# You can initialize a session by doing any of the following:
|
88
88
|
#
|
89
89
|
# UserSession.new
|
90
90
|
# UserSession.new(:login => "login", :password => "password", :remember_me => true)
|
91
|
-
# UserSession.new(:openid => "identity url", :remember_me => true)
|
92
91
|
# UserSession.new(User.first, true)
|
93
92
|
#
|
94
93
|
# If a user has more than one session you need to pass an id so that Authlogic knows how to differentiate the sessions. The id MUST be a Symbol.
|
95
94
|
#
|
96
95
|
# UserSession.new(:my_id)
|
97
96
|
# UserSession.new({:login => "login", :password => "password", :remember_me => true}, :my_id)
|
98
|
-
# UserSession.new({:openid => "identity url", :remember_me => true}, :my_id)
|
99
97
|
# UserSession.new(User.first, true, :my_id)
|
100
98
|
#
|
101
99
|
# Ids are rarely used, but they can be useful. For example, what if users allow other users to login into their account via proxy? Now that user can "technically" be logged into 2 accounts at once.
|
@@ -121,7 +119,6 @@ module Authlogic
|
|
121
119
|
#
|
122
120
|
# * :password - username and password
|
123
121
|
# * :unauthorized_record - an actual ActiveRecord object
|
124
|
-
# * :openid - OpenID
|
125
122
|
#
|
126
123
|
# By default this is :password
|
127
124
|
def authenticating_with
|
@@ -234,14 +231,24 @@ module Authlogic
|
|
234
231
|
new_session != false
|
235
232
|
end
|
236
233
|
|
234
|
+
def persisting # :nodoc:
|
235
|
+
return @persisting if defined?(@persisting)
|
236
|
+
@persisting = true
|
237
|
+
end
|
238
|
+
|
239
|
+
# Returns true if the session is being persisted. This is set to false if the session was found by the single_access_token, since logging in via a single access token should not remember the user in the
|
240
|
+
# session or the cookie.
|
241
|
+
def persisting?
|
242
|
+
persisting == true
|
243
|
+
end
|
244
|
+
|
237
245
|
def remember_me # :nodoc:
|
238
|
-
return @remember_me if @
|
239
|
-
@remember_me
|
246
|
+
return @remember_me if defined?(@remember_me)
|
247
|
+
@remember_me = self.class.remember_me
|
240
248
|
end
|
241
249
|
|
242
250
|
# Accepts a boolean as a flag to remember the session or not. Basically to expire the cookie at the end of the session or keep it for "remember_me_until".
|
243
251
|
def remember_me=(value)
|
244
|
-
@set_remember_me = true
|
245
252
|
@remember_me = value
|
246
253
|
end
|
247
254
|
|
@@ -290,8 +297,12 @@ module Authlogic
|
|
290
297
|
result
|
291
298
|
end
|
292
299
|
|
293
|
-
#
|
294
|
-
#
|
300
|
+
# This lets you create a session by passing a single object of whatever you are authenticating. Let's say User. By passing a user object you are vouching for this user and saying you can guarantee
|
301
|
+
# this user is who he says he is, create a session for him.
|
302
|
+
#
|
303
|
+
# This is how persistence works in Authlogic. Authlogic grabs your cookie credentials, finds a user by those credentials, and then vouches for that user and creates a session. You can do this for just about
|
304
|
+
# anything, which comes in handy for those unique authentication methods. Do what you need to do to authenticate the user, guarantee he is who he says he is, then pass the object here. Authlogic will do its
|
305
|
+
# magic: create a session and cookie. Now when the user refreshes their session will be persisted by their session and cookie.
|
295
306
|
def unauthorized_record=(value)
|
296
307
|
self.authenticating_with = :unauthorized_record
|
297
308
|
@unauthorized_record = value
|
@@ -8,7 +8,7 @@ module Authlogic
|
|
8
8
|
|
9
9
|
# = Session Config
|
10
10
|
#
|
11
|
-
# This deals with configuration for your session. If you are wanting to configure your model please look at Authlogic::ORMAdapters::
|
11
|
+
# This deals with configuration for your session. If you are wanting to configure your model please look at Authlogic::ORMAdapters::ActiveRecordAdapter::ActsAsAuthentic::Config
|
12
12
|
#
|
13
13
|
# Configuration for your session is simple. The configuration options are just class methods. Just put this in your config/initializers directory
|
14
14
|
#
|
@@ -89,20 +89,6 @@ module Authlogic
|
|
89
89
|
end
|
90
90
|
alias_method :find_by_login_method=, :find_by_login_method
|
91
91
|
|
92
|
-
# Once the user confirms their openid Authlogic tries to find the record with that openod. This is the method it called on the record's
|
93
|
-
# class to find the record by the openid.
|
94
|
-
#
|
95
|
-
# * <tt>Default:</tt> "find_by_#{openid_field}"
|
96
|
-
# * <tt>Accepts:</tt> Symbol or String
|
97
|
-
def find_by_openid_method(value = nil)
|
98
|
-
if value.nil?
|
99
|
-
read_inheritable_attribute(:find_by_openid_method) || find_by_openid_method("find_by_#{openid_field}")
|
100
|
-
else
|
101
|
-
write_inheritable_attribute(:find_by_openid_method, value)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
alias_method :find_by_openid_method=, :find_by_openid_method
|
105
|
-
|
106
92
|
# Calling UserSession.find tries to find the user session by session, then cookie, then params, and finally by basic http auth.
|
107
93
|
# This option allows you to change the order or remove any of these.
|
108
94
|
#
|
@@ -110,7 +96,7 @@ module Authlogic
|
|
110
96
|
# * <tt>Accepts:</tt> Array, and can only use any of the 3 options above
|
111
97
|
def find_with(*values)
|
112
98
|
if values.blank?
|
113
|
-
read_inheritable_attribute(:find_with) || find_with(:
|
99
|
+
read_inheritable_attribute(:find_with) || find_with(:params, :session, :cookie, :http_auth)
|
114
100
|
else
|
115
101
|
values.flatten!
|
116
102
|
write_inheritable_attribute(:find_with, values)
|
@@ -138,55 +124,23 @@ module Authlogic
|
|
138
124
|
# login with a field called "login" and then find users by email this is compeltely doable. See the find_by_login_method configuration
|
139
125
|
# option for more details.
|
140
126
|
#
|
141
|
-
# * <tt>Default:</tt>
|
127
|
+
# * <tt>Default:</tt> Uses the configuration option in your model: User.acts_as_authentic_config[:login_field]
|
142
128
|
# * <tt>Accepts:</tt> Symbol or String
|
143
129
|
def login_field(value = nil)
|
144
130
|
if value.nil?
|
145
|
-
read_inheritable_attribute(:login_field) || login_field(klass.login_field)
|
131
|
+
read_inheritable_attribute(:login_field) || login_field(klass.acts_as_authentic_config[:login_field])
|
146
132
|
else
|
147
133
|
write_inheritable_attribute(:login_field, value)
|
148
134
|
end
|
149
135
|
end
|
150
136
|
alias_method :login_field=, :login_field
|
151
137
|
|
152
|
-
#
|
153
|
-
# if you want it can be something completely different than the field in your model. So if you wanted people to login with a field called
|
154
|
-
# "openid_url" and then find users by openid this is compeltely doable. See the find_by_openid_method configuration option for
|
155
|
-
# more details.
|
156
|
-
#
|
157
|
-
# * <tt>Default:</tt> Guesses based on the model columns, tries openid, openid_url, identity_url.
|
158
|
-
# * <tt>Accepts:</tt> Symbol or String
|
159
|
-
def openid_field(value = nil)
|
160
|
-
if value.nil?
|
161
|
-
read_inheritable_attribute(:openid_field) || openid_field((klass.column_names.include?("openid") && :openid) || (klass.column_names.include?("openid_url") && :openid_url) || (klass.column_names.include?("identity_url") && :identity_url))
|
162
|
-
else
|
163
|
-
write_inheritable_attribute(:openid_field, value)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
alias_method :openid_field=, :openid_field
|
167
|
-
|
168
|
-
# The name of the method you want Authlogic to create for storing the openid url. Keep in mind this is just for your Authlogic::Session,
|
169
|
-
# if you want it can be something completely different than the field in your model. So if you wanted people to login with a field called
|
170
|
-
# "openid_url" and then find users by openid this is compeltely doable. See the find_by_openid_method configuration option for
|
171
|
-
# more details.
|
138
|
+
# 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:
|
172
139
|
#
|
173
|
-
#
|
174
|
-
# * <tt>Accepts:</tt> Symbol or String
|
175
|
-
def openid_file_store_path(value = nil)
|
176
|
-
if value.nil?
|
177
|
-
read_inheritable_attribute(:openid_file_store_path) || openid_file_store_path((defined?(RAILS_ROOT) && RAILS_ROOT + "/tmp/openids") || (defined?(Merb) && Merb.root + "/tmp/openids"))
|
178
|
-
else
|
179
|
-
write_inheritable_attribute(:openid_file_store_path, value)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
alias_method :openid_file_store_path=, :openid_file_store_path
|
183
|
-
|
184
|
-
# Works exactly like cookie_key, but for params. So a user can login via params just like a cookie or a session. Your URK would look like:
|
185
|
-
#
|
186
|
-
# http://www.domain.com?user_credentials=fdsfdfd32jfksdjfdksl
|
140
|
+
# http://www.domain.com?user_credentials=my_single_access_key
|
187
141
|
#
|
188
142
|
# You can change the "user_credentials" key above with this configuration option. Keep in mind, just like cookie_key, if you supply an id
|
189
|
-
# the id will be appended to the front.
|
143
|
+
# 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.
|
190
144
|
#
|
191
145
|
# * <tt>Default:</tt> cookie_key
|
192
146
|
# * <tt>Accepts:</tt> String
|
@@ -199,13 +153,14 @@ module Authlogic
|
|
199
153
|
end
|
200
154
|
alias_method :params_key=, :params_key
|
201
155
|
|
156
|
+
|
202
157
|
# Works exactly like login_field, but for the password instead.
|
203
158
|
#
|
204
|
-
# * <tt>Default:</tt>
|
159
|
+
# * <tt>Default:</tt> :password
|
205
160
|
# * <tt>Accepts:</tt> Symbol or String
|
206
161
|
def password_field(value = nil)
|
207
162
|
if value.nil?
|
208
|
-
read_inheritable_attribute(:password_field) || password_field(
|
163
|
+
read_inheritable_attribute(:password_field) || password_field(:password)
|
209
164
|
else
|
210
165
|
write_inheritable_attribute(:password_field, value)
|
211
166
|
end
|
@@ -242,11 +197,11 @@ module Authlogic
|
|
242
197
|
# long. Well they already have a cookie set to expire in 6 months. Without a token you would have to reset their password, which obviously isn't feasible. So instead of messing with their password
|
243
198
|
# just reset their remember token. Next time they access the site and try to login via a cookie it will be rejected and they will have to relogin.
|
244
199
|
#
|
245
|
-
# * <tt>Default:</tt>
|
200
|
+
# * <tt>Default:</tt> Uses the configuration option in your model: User.acts_as_authentic_config[:remember_token_field]
|
246
201
|
# * <tt>Accepts:</tt> Symbol or String
|
247
202
|
def remember_token_field(value = nil)
|
248
203
|
if value.nil?
|
249
|
-
read_inheritable_attribute(:remember_token_field) || remember_token_field(klass.remember_token_field)
|
204
|
+
read_inheritable_attribute(:remember_token_field) || remember_token_field(klass.acts_as_authentic_config[:remember_token_field])
|
250
205
|
else
|
251
206
|
write_inheritable_attribute(:remember_token_field, value)
|
252
207
|
end
|
@@ -266,6 +221,34 @@ module Authlogic
|
|
266
221
|
end
|
267
222
|
alias_method :session_key=, :session_key
|
268
223
|
|
224
|
+
# 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 something you only want for specific request types.
|
225
|
+
# Specify a list of allowed request types and single access authentication will only be allowed for the ones you specify. Checkout the "Single Access / Private Feeds Access" section in the README.
|
226
|
+
#
|
227
|
+
# * <tt>Default:</tt> "application/rss+xml", "application/atom+xml"
|
228
|
+
# * <tt>Accepts:</tt> String, or :all to allow single access authentication for any and all request types
|
229
|
+
def single_access_allowed_request_types(*values)
|
230
|
+
if values.blank?
|
231
|
+
read_inheritable_attribute(:single_access_allowed_request_types) || single_access_allowed_request_types("application/rss+xml", "application/atom+xml")
|
232
|
+
else
|
233
|
+
write_inheritable_attribute(:single_access_allowed_request_types, values)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
alias_method :single_access_allowed_request_types=, :single_access_allowed_request_types
|
237
|
+
|
238
|
+
# This is a separate token for logging with single access. It works just the the remember_token but it does NOT persist. Meaning if a record is found with the single_access_token it will not set
|
239
|
+
# the session or the cookie and "remember" the user. Checkout the "Single Access / Private Feeds Access" section in the README.
|
240
|
+
#
|
241
|
+
# * <tt>Default:</tt> Uses the configuration option in your model: User.acts_as_authentic_config[:single_access_token]
|
242
|
+
# * <tt>Accepts:</tt> Symbol or String
|
243
|
+
def single_access_token_field(value = nil)
|
244
|
+
if value.nil?
|
245
|
+
read_inheritable_attribute(:single_access_token_field) || single_access_token_field(klass.acts_as_authentic_config[:single_access_token_field])
|
246
|
+
else
|
247
|
+
write_inheritable_attribute(:single_access_token_field, value)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
alias_method :single_access_token_field=, :single_access_token_field
|
251
|
+
|
269
252
|
# The name of the method in your model used to verify the password. This should be an instance method. It should also be prepared to accept a raw password and a crytped password.
|
270
253
|
#
|
271
254
|
# * <tt>Default:</tt> "valid_#{password_field}?"
|
@@ -281,6 +264,10 @@ module Authlogic
|
|
281
264
|
end
|
282
265
|
|
283
266
|
module InstanceMethods # :nodoc:
|
267
|
+
def change_single_access_token_with_password?
|
268
|
+
self.class.change_single_access_token_with_password == true
|
269
|
+
end
|
270
|
+
|
284
271
|
def cookie_key
|
285
272
|
build_key(self.class.cookie_key)
|
286
273
|
end
|
@@ -289,10 +276,6 @@ module Authlogic
|
|
289
276
|
self.class.find_by_login_method
|
290
277
|
end
|
291
278
|
|
292
|
-
def find_by_openid_method
|
293
|
-
self.class.find_by_openid_method
|
294
|
-
end
|
295
|
-
|
296
279
|
def find_with
|
297
280
|
self.class.find_with
|
298
281
|
end
|
@@ -305,8 +288,8 @@ module Authlogic
|
|
305
288
|
self.class.login_field
|
306
289
|
end
|
307
290
|
|
308
|
-
def
|
309
|
-
self.class.
|
291
|
+
def params_allowed_request_types
|
292
|
+
build_key(self.class.params_allowed_request_types)
|
310
293
|
end
|
311
294
|
|
312
295
|
def params_key
|
@@ -329,6 +312,14 @@ module Authlogic
|
|
329
312
|
def session_key
|
330
313
|
build_key(self.class.session_key)
|
331
314
|
end
|
315
|
+
|
316
|
+
def single_access_token_field
|
317
|
+
self.class.single_access_token_field
|
318
|
+
end
|
319
|
+
|
320
|
+
def single_access_allowed_request_types
|
321
|
+
self.class.single_access_allowed_request_types
|
322
|
+
end
|
332
323
|
|
333
324
|
def verify_password_method
|
334
325
|
self.class.verify_password_method
|
@@ -5,8 +5,8 @@ module Authlogic
|
|
5
5
|
# Handles all authentication that deals with cookies, such as persisting a session and saving / destroying a session.
|
6
6
|
module Cookies
|
7
7
|
def self.included(klass)
|
8
|
-
klass.after_save :save_cookie
|
9
|
-
klass.after_destroy :destroy_cookie
|
8
|
+
klass.after_save :save_cookie, :if => :persisting?
|
9
|
+
klass.after_destroy :destroy_cookie, :if => :persisting?
|
10
10
|
end
|
11
11
|
|
12
12
|
# Tries to validate the session from information in the cookie
|
@@ -3,17 +3,20 @@ module Authlogic
|
|
3
3
|
# = Params
|
4
4
|
#
|
5
5
|
# Tries to log the user in via params. Think about cookies and sessions. They are just hashes in your controller, so are params. People never
|
6
|
-
# look at params as an authentication option, but it can be useful for logging into private feeds. Logging in a user is as simple as:
|
6
|
+
# look at params as an authentication option, but it can be useful for logging into private feeds, etc. Logging in a user is as simple as:
|
7
7
|
#
|
8
|
-
#
|
8
|
+
# https://www.domain.com?user_credentials=[insert single access token here]
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# Wait, what is a single access token? It is all explained in the README. Checkout the "Single Access" section in the README. For security reasons, this type of authentication
|
11
|
+
# is ONLY available via single access tokens, you can NOT pass your remember token.
|
11
12
|
module Params
|
12
13
|
# Tries to validate the session from information in the params token
|
13
14
|
def valid_params?
|
14
|
-
if params_credentials
|
15
|
-
self.unauthorized_record = search_for_record("find_by_#{
|
16
|
-
|
15
|
+
if params_credentials && single_access_token_field && single_access_allowed_request_types.include?(controller.request_content_type)
|
16
|
+
self.unauthorized_record = search_for_record("find_by_#{single_access_token_field}", params_credentials)
|
17
|
+
self.persisting = false
|
18
|
+
return true if valid?
|
19
|
+
self.persisting = true
|
17
20
|
end
|
18
21
|
|
19
22
|
false
|
@@ -5,9 +5,9 @@ module Authlogic
|
|
5
5
|
# Handles all parts of authentication that deal with sessions. Such as persisting a session and saving / destroy a session.
|
6
6
|
module Session
|
7
7
|
def self.included(klass)
|
8
|
-
klass.after_save :update_session
|
9
|
-
klass.after_destroy :update_session
|
10
|
-
klass.after_find :update_session
|
8
|
+
klass.after_save :update_session!, :if => :persisting?
|
9
|
+
klass.after_destroy :update_session!, :if => :persisting?
|
10
|
+
klass.after_find :update_session!, :if => :persisting?
|
11
11
|
end
|
12
12
|
|
13
13
|
# Tries to validate the session from information in the session
|
data/lib/authlogic/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
module Authlogic
|
4
|
+
module ShouldaMacros
|
5
|
+
def should_be_authentic(model)
|
6
|
+
should "acts as authentic" do
|
7
|
+
assert model.respond_to?(:acts_as_authentic_config)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Test::Unit::TestCase.extend Authlogic::ShouldaMacros
|
data/test/fixtures/employees.yml
CHANGED
@@ -2,7 +2,7 @@ drew:
|
|
2
2
|
company: binary_logic
|
3
3
|
email: dgainor@binarylogic.com
|
4
4
|
password_salt: <%= salt = Employee.unique_token %>
|
5
|
-
crypted_password: "<%= Employee.crypto_provider.encrypt("drewrocks" + salt) %>"
|
5
|
+
crypted_password: "<%= Employee.acts_as_authentic_config[:crypto_provider].encrypt("drewrocks" + salt) %>"
|
6
6
|
remember_token: 5273d85ed156e9dbd6a7c1438d319ef8c8d41dd24368db6c222de11346c7b11e53ee08d45ecf619b1c1dc91233d22b372482b751b066d0a6f6f9bac42eacaabf
|
7
7
|
first_name: Drew
|
8
8
|
last_name: Gainor
|
@@ -11,7 +11,7 @@ jennifer:
|
|
11
11
|
company: logic_over_data
|
12
12
|
email: jjohnson@logicoverdata.com
|
13
13
|
password_salt: <%= salt = Employee.unique_token %>
|
14
|
-
crypted_password: "<%= Employee.crypto_provider.encrypt("jenniferocks" + salt) %>"
|
14
|
+
crypted_password: "<%= Employee.acts_as_authentic_config[:crypto_provider].encrypt("jenniferocks" + salt) %>"
|
15
15
|
remember_token: 2be52a8f741ad00056e6f94eb6844d5316527206da7a3a5e3d0e14d19499ef9fe4c47c89b87febb59a2b41a69edfb4733b6b79302040f3de83f297c6991c75a2
|
16
16
|
first_name: Jennifer
|
17
17
|
last_name: Johnson
|
data/test/fixtures/users.yml
CHANGED
@@ -5,6 +5,7 @@ ben:
|
|
5
5
|
password_salt: <%= salt = User.unique_token %>
|
6
6
|
crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("benrocks" + salt) %>
|
7
7
|
remember_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317
|
8
|
+
single_access_token: <%= User.friendly_unique_token %>
|
8
9
|
first_name: Ben
|
9
10
|
last_name: Johnson
|
10
11
|
|
@@ -15,5 +16,6 @@ zack:
|
|
15
16
|
password_salt: <%= salt = User.unique_token %>
|
16
17
|
crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("zackrocks" + salt) %>
|
17
18
|
remember_token: fd3c2d5ce09ab98e7547d21f1b3dcf9158a9a19b5d3022c0402f32ae197019fce3fdbc6614d7ee57d719bae53bb089e30edc9e5d6153e5bc3afca0ac1d320342
|
19
|
+
single_access_token: <%= User.friendly_unique_token %>
|
18
20
|
first_name: Zack
|
19
21
|
last_name: Ham
|