Created
August 31, 2011 20:19
-
-
Save moxie/1184604 to your computer and use it in GitHub Desktop.
This file contains 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
# Apache sets an environment variable called USER_GEO on every request | |
# with a country code for where the IP is from | |
def redirect_for_geo_partners | |
return unless geo_partner = Partner.find_by_country(env['USER_GEO']) | |
# Store the request path | |
desired_path = request.path | |
if logged_in? | |
if on_partner_site? | |
if current_user.partner.nil? | |
# This user has no partner but is on a partner site. Kick them back to app. | |
redirect_to "http://app.#{ROOT_HOST}" + desired_path | |
elsif current_user.partner and current_user.partner != current_partner | |
# This user has a partner, but is on the wrong partner site, redirect them to their partner | |
redirect_to "http://#{current_user.partner.subdomain}.#{ROOT_HOST}" + desired_path | |
end | |
else | |
# This user has a partner, but is not on a partner site, redirect them to their partner | |
redirect_to "http://#{current_user.partner.subdomain}.#{ROOT_HOST}" + desired_path | |
end | |
else | |
# Redirect anonymous users to the geo_partner equivalent page | |
redirect_to "http://#{geo_partner.subdomain}.#{ROOT_HOST}" + desired_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment