3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 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?
ip = IPAddr.new(request.["CF-Connecting-IP"] || request.["REMOTE_ADDR"])
return if current_user.ip_whitelist.detect{ |ip_or_range|
(ip_or_range.is_a?(IPAddr) ? ip_or_range : IPAddr.new(ip_or_range)) === ip
}
if redirect = IPWhitelist.configuration.redirect
redirect_to redirect
else
render text: "Not Authorized", status: 401
end
end
end
|