Sha256: bbdd7e14f04006fd96cc1be8b7cc8d07ad3c5480ba826651077718d112f653c8

Contents?: true

Size: 799 Bytes

Versions: 1

Compression:

Stored size: 799 Bytes

Contents

module Frikandel
  module BindSessionToIpAddress
    extend ActiveSupport::Concern

    included do
      append_before_filter :validate_session_ip_address
    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

1 entries across 1 versions & 1 rubygems

Version Path
frikandel-2.1.0 lib/frikandel/bind_session_to_ip_address.rb