Module: IPWhitelist::Controller

Defined in:
lib/ip_whitelist/controller.rb

Instance Method Summary collapse

Instance Method Details

#check_ip_whitelistObject



3
4
5
6
7
8
9
10
# File 'lib/ip_whitelist/controller.rb', line 3

def check_ip_whitelist
  if current_user && current_user.respond_to?(:ip_whitelist) && current_user.ip_whitelist.present?
    # Since requests can come through cloudflare, try that IP first.
    ip = request.headers["CF-Connecting-IP"] || request.headers["REMOTE_ADDR"]
    return if current_user.ip_whitelist.map(&:to_s).include?(ip)
    render text: "Not Authorized", status: 401
  end
end