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

44 lines
1.1 KiB
Ruby
Raw Normal View History

require 'devise/hooks/timeoutable'
module Devise
module Models
2014-01-09 11:00:27 -05:00
# Timeoutable takes care of verifying whether a user session has already
2009-11-22 20:29:03 -05:00
# expired or not. When a session expires after the configured time, the user
2013-12-05 03:03:28 -05:00
# will be asked for credentials again, it means, they will be redirected
2009-11-22 20:29:03 -05:00
# to the sign in page.
#
2010-07-15 07:01:31 -04:00
# == Options
#
# Timeoutable adds the following options to devise_for:
#
# * +timeout_in+: the interval to timeout the user session without activity.
#
# == Examples
#
# user.timedout?(30.minutes.ago)
2009-11-22 20:29:03 -05:00
#
module Timeoutable
2010-02-17 06:35:38 -05:00
extend ActiveSupport::Concern
2012-02-24 17:56:04 -05:00
def self.required_fields(klass)
[]
end
# Checks whether the user session has expired based on configured time.
2010-01-14 09:47:14 -05:00
def timedout?(last_access)
2011-11-24 13:42:58 -05:00
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
end
2011-11-24 13:42:58 -05:00
def timeout_in
self.class.timeout_in
end
private
2011-11-24 13:42:58 -05:00
module ClassMethods
Devise::Models.config(self, :timeout_in)
end
end
end
end