2017-12-21 17:36:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-11-23 00:19:29 +00:00
|
|
|
require 'devise/hooks/timeoutable'
|
|
|
|
|
|
|
|
module Devise
|
|
|
|
module Models
|
2014-01-09 16:00:27 +00:00
|
|
|
# Timeoutable takes care of verifying whether a user session has already
|
2009-11-23 01:29:03 +00:00
|
|
|
# expired or not. When a session expires after the configured time, the user
|
2013-12-05 08:03:28 +00:00
|
|
|
# will be asked for credentials again, it means, they will be redirected
|
2009-11-23 01:29:03 +00:00
|
|
|
# to the sign in page.
|
|
|
|
#
|
2010-07-15 11:01:31 +00: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-23 01:29:03 +00:00
|
|
|
#
|
2009-11-23 00:19:29 +00:00
|
|
|
module Timeoutable
|
2010-02-17 11:35:38 +00:00
|
|
|
extend ActiveSupport::Concern
|
2009-11-23 00:33:19 +00:00
|
|
|
|
2012-02-24 22:56:04 +00:00
|
|
|
def self.required_fields(klass)
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2009-11-23 00:33:19 +00:00
|
|
|
# Checks whether the user session has expired based on configured time.
|
2010-01-14 14:47:14 +00:00
|
|
|
def timedout?(last_access)
|
2011-11-24 18:42:58 +00:00
|
|
|
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
2011-11-24 18:42:58 +00:00
|
|
|
|
2011-11-25 07:57:36 +00:00
|
|
|
def timeout_in
|
|
|
|
self.class.timeout_in
|
|
|
|
end
|
|
|
|
|
2010-09-29 04:21:07 +00:00
|
|
|
private
|
2011-11-24 18:42:58 +00:00
|
|
|
|
2009-11-23 00:19:29 +00:00
|
|
|
module ClassMethods
|
2009-11-25 02:11:49 +00:00
|
|
|
Devise::Models.config(self, :timeout_in)
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|