heartcombo--devise/lib/devise/hooks/timeoutable.rb

25 lines
992 B
Ruby
Raw Normal View History

# 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
# 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.
Warden::Manager.after_set_user do |record, warden, options|
scope = options[:scope]
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
last_request_at = warden.session(scope)['last_request_at']
2010-01-14 14:47:14 +00:00
if record.timedout?(last_request_at)
path_checker = Devise::PathChecker.new(warden.env, scope)
unless path_checker.signing_out?
warden.logout(scope)
throw :warden, :scope => scope, :message => :timeout
end
end
2010-01-14 14:47:14 +00:00
unless warden.request.env['devise.skip_trackable']
warden.session(scope)['last_request_at'] = Time.now.utc
end
end
end