Sha256: 5ef4946a8686ecc8fee2d45109916bfc4690dba409944878d96459d7807fd2a6

Contents?: true

Size: 1.05 KB

Versions: 34

Compression:

Stored size: 1.05 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
    last_request_at = warden.session(scope)['last_request_at']

    if record.timedout?(last_request_at) && !env['devise.skip_timeout']
      warden.logout(scope)
      if record.respond_to?(:expire_auth_token_on_timeout) && record.expire_auth_token_on_timeout
        record.reset_authentication_token!
      end
      throw :warden, :scope => scope, :message => :timeout
    end

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

Version data entries

34 entries across 34 versions & 5 rubygems

Version Path
devise-3.1.2 lib/devise/hooks/timeoutable.rb
devise-3.0.4 lib/devise/hooks/timeoutable.rb
devise-2.2.8 lib/devise/hooks/timeoutable.rb
loyal_devise-2.2.6 lib/devise/hooks/timeoutable.rb
devise-3.1.1 lib/devise/hooks/timeoutable.rb
devise-3.1.0 lib/devise/hooks/timeoutable.rb
devise-2.1.4 lib/devise/hooks/timeoutable.rb
devise-2.2.7 lib/devise/hooks/timeoutable.rb
devise-3.0.3 lib/devise/hooks/timeoutable.rb
devise-3.1.0.rc2 lib/devise/hooks/timeoutable.rb
loyal_devise-2.2.5 lib/devise/hooks/timeoutable.rb
devise-2.2.6 lib/devise/hooks/timeoutable.rb
devise-3.0.2 lib/devise/hooks/timeoutable.rb
devise-3.0.1 lib/devise/hooks/timeoutable.rb
devise-2.2.5 lib/devise/hooks/timeoutable.rb
loyal_devise-2.1.10 lib/devise/hooks/timeoutable.rb
loyal_devise-2.1.7 lib/devise/hooks/timeoutable.rb
loyal_devise-2.1.6 lib/devise/hooks/timeoutable.rb
devise-3.0.0 lib/devise/hooks/timeoutable.rb
loyal_devise-2.1.5 lib/devise/hooks/timeoutable.rb