2009-11-22 20:29:03 -05:00
|
|
|
# Each time a record is set we check whether it's session has already timed out
|
|
|
|
# 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 it's scoped session to
|
|
|
|
# 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-23 20:28:04 -05:00
|
|
|
if record && record.respond_to?(:timeout?)
|
2009-11-22 19:19:29 -05:00
|
|
|
scope = options[:scope]
|
2009-11-23 19:56:04 -05:00
|
|
|
# Record may have already been logged out by another hook (ie confirmable).
|
2009-11-22 19:19:29 -05:00
|
|
|
if warden.authenticated?(scope)
|
|
|
|
last_request_at = warden.session(scope)['last_request_at']
|
2009-11-22 19:33:19 -05:00
|
|
|
if record.timeout?(last_request_at)
|
2009-11-22 19:19:29 -05:00
|
|
|
warden.logout(scope)
|
|
|
|
throw :warden, :scope => scope, :message => :timeout
|
|
|
|
end
|
|
|
|
warden.session(scope)['last_request_at'] = Time.now.utc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|