2010-03-31 19:43:19 +00:00
|
|
|
# Each time a record is set we check whether its session has already timed out
|
2009-11-23 01:29:03 +00:00
|
|
|
# or not, based on last request time. If so, the record is logged out and
|
|
|
|
# redirected to the sign in page. Also, each time the request comes and the
|
2011-08-16 20:06:13 +00:00
|
|
|
# record is set, we set the last request time inside its scoped session to
|
2009-11-23 01:29:03 +00:00
|
|
|
# verify timeout in the following request.
|
2009-11-23 00:19:29 +00:00
|
|
|
Warden::Manager.after_set_user do |record, warden, options|
|
2009-11-24 17:18:42 +00:00
|
|
|
scope = options[:scope]
|
2010-06-13 10:39:20 +00:00
|
|
|
|
2011-02-14 15:45:00 +00:00
|
|
|
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
|
2009-11-24 17:18:42 +00:00
|
|
|
last_request_at = warden.session(scope)['last_request_at']
|
2010-01-14 14:47:14 +00:00
|
|
|
|
|
|
|
if record.timedout?(last_request_at)
|
2010-06-13 10:39:20 +00:00
|
|
|
path_checker = Devise::PathChecker.new(warden.env, scope)
|
|
|
|
unless path_checker.signing_out?
|
|
|
|
warden.logout(scope)
|
2011-01-03 15:24:07 +00:00
|
|
|
throw :warden, :scope => scope, :message => :timeout
|
2010-06-13 10:39:20 +00:00
|
|
|
end
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
2010-01-14 14:47:14 +00:00
|
|
|
|
2011-10-25 16:43:34 +00:00
|
|
|
unless warden.request.env['devise.skip_trackable']
|
|
|
|
warden.session(scope)['last_request_at'] = Time.now.utc
|
|
|
|
end
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
|
|
|
end
|