Repository: fossasia/open-event-server

Issue:
Search Function: Location incorrect based on user's IP address
Following up from issue #2714 - the search function does not accurately reflect the country a user is in based on his or her IP address. For instance, I was shown search results for the United States instead of Singapore - although I live in Singapore.

![2a5eb670-ca39-11e6-862d-432549c1184a](https://cloud.githubusercontent.com/assets/9492662/21472359/7ce2cdd2-cb10-11e6-9026-7323e593ba82.PNG)



Discussion:
This bug is on eventyay only as Google app engine does not allow python modules with extensions written in c. (refer https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27 )  while heroku allows it and `geoip2` module uses an extension written in c.

To solve this we could use a pure python module like https://github.com/appliedsec/pygeoip 
or we could check for headers specific to Google App Engine (which work pretty good by the way, check [here](http://mylocationtest.appspot.com/) ) by checking the header keys like `"X-AppEngine-Country"` 

@niranjan94 @SaptakS What are your views on this?
@shubham-padia we're not using app engine for eventyay. It uses Google Container Engine & Compute Engine. And extensions written with C work on eventyay
I believe the problem exists with the Nginx Ingress Controller. It has to be configured such that the client Ip is visible to the final web service in some form.
@niranjan94  Ohh...sorry, I always thought eventyay ran on app engine :smile: 
@shubham-padia Nope. We use [Kubernetes](http://kubernetes.io/) and google container engine ... Do check it out :smile: It's awesome ! 

Our configuration files are at https://github.com/fossasia/open-event-orga-server/tree/development/kubernetes

Resolving patch:
diff --git a/app/__init__.py b/app/__init__.py
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -71,6 +71,7 @@
 
 app = Flask(__name__)
 
+
 class ReverseProxied(object):
     """
     ReverseProxied flask wsgi app wrapper from http://stackoverflow.com/a/37842465/1562480 by aldel
diff --git a/app/views/__init__.py b/app/views/__init__.py
--- a/app/views/__init__.py
+++ b/app/views/__init__.py
@@ -12,6 +12,7 @@
 from app.views.public.ticketing import ticketing
 from app.views.sitemap import sitemaps
 from app.views.super_admin.content import sadmin_content
+from app.views.super_admin.debug import sadmin_debug
 from app.views.super_admin.dep_settings import sadmin_settings
 from app.views.super_admin.events import sadmin_events
 from app.views.super_admin.messages import sadmin_messages
@@ -91,6 +92,7 @@ def register(app):
         app.register_blueprint(sadmin_settings)
         app.register_blueprint(sadmin_modules)
         app.register_blueprint(sadmin_content)
+        app.register_blueprint(sadmin_debug)
 
 
 @event_speakers.before_request
diff --git a/app/views/super_admin/debug.py b/app/views/super_admin/debug.py
new file mode 100644
--- /dev/null
+++ b/app/views/super_admin/debug.py
@@ -0,0 +1,25 @@
+import flask_login
+from flask import Blueprint
+from flask import render_template
+from flask import request
+
+from app.helpers.flask_helpers import get_real_ip
+from app.views.super_admin import check_accessible, list_navbar, BASE
+
+sadmin_debug = Blueprint('sadmin_debug', __name__, url_prefix='/admin/debug')
+
+
+@sadmin_debug.before_request
+def verify_accessible():
+    return check_accessible(BASE)
+
+
+@sadmin_debug.route('/')
+@flask_login.login_required
+def display_debug_info():
+    return render_template('gentelella/admin/super_admin/debug/debug.html',
+                           ip=get_real_ip(),
+                           cookies=request.cookies,
+                           navigation_bar=list_navbar(),
+                           headers=request.headers)
+


Test patch: