Sha256: 737a6a507a5420058aa8aa874d27f7fa1937817ae4e46bb26f7dfb763d7e5d91

Contents?: true

Size: 949 Bytes

Versions: 7

Compression:

Stored size: 949 Bytes

Contents

module Frikandel
  module BindSessionToIpAddress
    extend ActiveSupport::Concern
    include SessionInvalidation

    included do
      if respond_to?(:before_action)
        append_before_action :validate_session_ip_address
      else
        append_before_filter :validate_session_ip_address
      end
    end

  private

    def validate_session_ip_address
      if session.key?(:ip_address) && !ip_address_match_with_current?
        on_invalid_session
      elsif !session.key?(:ip_address)
        reset_session
      else # session ip address is valid
        persist_session_ip_address
      end
    end

    def persist_session_ip_address
      session[:ip_address] = current_ip_address
    end

    def current_ip_address
      request.remote_ip
    end

    def ip_address_match_with_current?
      session[:ip_address] == current_ip_address
    end

    def reset_session
      super
      persist_session_ip_address
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
frikandel-3.0.2 lib/frikandel/bind_session_to_ip_address.rb
frikandel-3.0.1 lib/frikandel/bind_session_to_ip_address.rb
frikandel-3.0.0 lib/frikandel/bind_session_to_ip_address.rb
frikandel-2.3.0 lib/frikandel/bind_session_to_ip_address.rb
frikandel-2.2.2 lib/frikandel/bind_session_to_ip_address.rb
frikandel-2.2.1 lib/frikandel/bind_session_to_ip_address.rb
frikandel-2.2.0 lib/frikandel/bind_session_to_ip_address.rb