Module: IPWhitelist::Controller
- Defined in:
- lib/ip_whitelist/controller.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/ip_whitelist/controller.rb', line 3 def self.included(base) base.before_action :check_ip_whitelist end |
Instance Method Details
#check_ip_whitelist ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/ip_whitelist/controller.rb', line 7 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 |