Sha256: 758a1347586d24caed32368bb0d83dac5e2fd5fecd41bdbe85696057a7a20c3c

Contents?: true

Size: 1.27 KB

Versions: 19

Compression:

Stored size: 1.27 KB

Contents

# Each time a record is set we check whether its 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 its scoped session to
# verify timeout in the following request.
Warden::Manager.after_set_user do |record, warden, options|
  scope = options[:scope]
  env   = warden.request.env

  if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) &&
     options[:store] != false && !env['devise.skip_timeoutable']
    last_request_at = warden.session(scope)['last_request_at']

    if last_request_at.is_a? Integer
      last_request_at = Time.at(last_request_at).utc
    elsif last_request_at.is_a? String
      last_request_at = Time.parse(last_request_at)
    end

    proxy = Devise::Hooks::Proxy.new(warden)

    if record.timedout?(last_request_at) &&
        !env['devise.skip_timeout'] &&
        !proxy.remember_me_is_active?(record)
      Devise.sign_out_all_scopes ? proxy.sign_out : proxy.sign_out(scope)
      throw :warden, scope: scope, message: :timeout
    end

    unless env['devise.skip_trackable']
      warden.session(scope)['last_request_at'] = Time.now.utc.to_i
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
devise-4.3.0 lib/devise/hooks/timeoutable.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/devise-4.2.1/lib/devise/hooks/timeoutable.rb
devise-4.2.1 lib/devise/hooks/timeoutable.rb
devise-4.2.0 lib/devise/hooks/timeoutable.rb
devise-3.5.10 lib/devise/hooks/timeoutable.rb
devise-4.0.3 lib/devise/hooks/timeoutable.rb
devise-4.1.1 lib/devise/hooks/timeoutable.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/devise-4.1.0/lib/devise/hooks/timeoutable.rb
devise-4.1.0 lib/devise/hooks/timeoutable.rb
devise-3.5.9 lib/devise/hooks/timeoutable.rb
devise-4.0.2 lib/devise/hooks/timeoutable.rb
devise-4.0.1 lib/devise/hooks/timeoutable.rb
devise-3.5.8 lib/devise/hooks/timeoutable.rb
devise-3.5.7 lib/devise/hooks/timeoutable.rb
devise-4.0.0 lib/devise/hooks/timeoutable.rb
devise-4.0.0.rc2 lib/devise/hooks/timeoutable.rb
devise-4.0.0.rc1 lib/devise/hooks/timeoutable.rb
devise-3.5.6 lib/devise/hooks/timeoutable.rb
devise-3.5.5 lib/devise/hooks/timeoutable.rb