2010-03-31 15:43:19 -04:00
|
|
|
# Each time a record is set we check whether its session has already timed out
|
2009-11-22 20:29:03 -05: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 16:06:13 -04:00
|
|
|
# record is set, we set the last request time inside its scoped session to
|
2009-11-22 20:29:03 -05:00
|
|
|
# verify timeout in the following request.
|
2009-11-22 19:19:29 -05:00
|
|
|
Warden::Manager.after_set_user do |record, warden, options|
|
2009-11-24 12:18:42 -05:00
|
|
|
scope = options[:scope]
|
2012-06-16 07:24:07 -04:00
|
|
|
env = warden.request.env
|
2010-06-13 06:39:20 -04:00
|
|
|
|
2011-02-14 10:45:00 -05:00
|
|
|
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
|
2009-11-24 12:18:42 -05:00
|
|
|
last_request_at = warden.session(scope)['last_request_at']
|
2010-01-14 09:47:14 -05:00
|
|
|
|
2012-06-16 07:24:07 -04:00
|
|
|
if record.timedout?(last_request_at) && !env['devise.skip_timeout']
|
2012-02-16 11:40:34 -05:00
|
|
|
warden.logout(scope)
|
2012-06-16 08:04:29 -04:00
|
|
|
if record.respond_to?(:expire_auth_token_on_timeout) && record.expire_auth_token_on_timeout
|
|
|
|
record.reset_authentication_token!
|
|
|
|
end
|
2012-02-16 11:40:34 -05:00
|
|
|
throw :warden, :scope => scope, :message => :timeout
|
2009-11-22 19:19:29 -05:00
|
|
|
end
|
2010-01-14 09:47:14 -05:00
|
|
|
|
2012-06-16 07:24:07 -04:00
|
|
|
unless env['devise.skip_trackable']
|
2011-10-25 12:43:34 -04:00
|
|
|
warden.session(scope)['last_request_at'] = Time.now.utc
|
|
|
|
end
|
2009-11-22 19:19:29 -05:00
|
|
|
end
|
|
|
|
end
|