Sha256: 292b548de0203fc3063f9b429c049b6bcebbaba06c41df97ec7922b2269fb229

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

require "frikandel/version"
require "frikandel/configuration"

module Frikandel
  module LimitSessionLifetime
    extend ActiveSupport::Concern

    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_expired_session
      end
    end

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

    def on_expired_session
      reset_session
      redirect_to root_path
    end
    alias original_on_expired_session on_expired_session
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frikandel-1.0.0 lib/frikandel.rb