Sha256: 311dd199bd3695137acf1f09659fab758e8ae3e7a044534d9fa274092657cff0

Contents?: true

Size: 713 Bytes

Versions: 1

Compression:

Stored size: 713 Bytes

Contents

module Frikandel
  module LimitSessionLifetime
    extend ActiveSupport::Concern
    include SessionInvalidation

    included do
      append_before_filter :validate_session_timestamp
      append_after_filter :persist_session_timestamp
    end

  private

    def validate_session_timestamp
      if session.key?(:ttl) && session.key?(:max_ttl) && (session[:ttl] < Frikandel::Configuration.ttl.ago || session[:max_ttl] < Time.now)
        on_invalid_session
      elsif !session.key?(:ttl) && !session.key?(:max_ttl)
        reset_session
      end
    end

    def persist_session_timestamp
      session[:ttl] = Time.now
      session[:max_ttl] ||= Frikandel::Configuration.max_ttl.from_now
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frikandel-2.0.0 lib/frikandel/limit_session_lifetime.rb