Created
November 8, 2012 10:44
-
-
Save cgallagher/4038089 to your computer and use it in GitHub Desktop.
Geo Restriction Logic using geocode gem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_user_location | |
# need to intro a whitelist for IP addresses | |
user_ip = request.ip | |
unless user_ip.nil? | |
logger.info("User IP Address is: #{user_ip}") | |
user_country = request.location.country | |
logger.info("User Country is: #{user_country}") | |
# if in production mode and the user country doesnt match one on the whitelist | |
# then throw them out to a restricted page. | |
redirect_to restricted_path() unless knock_knock(user_ip, user_country) | |
end | |
end | |
def knock_knock(user_ip, user_country) | |
country_whitelist = ["Brazil"] | |
ip_whitelist = ["127.0.0.1"] | |
country_whitelist.include?(user_country) or ip_whitelist.include?(user_ip) or (["development"]).include?(Rails.env) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment