Domantas Jackūnas avatar Domantas Jackūnas committed 6f538cf Draft

added better usability; working version of fix

Comments (0)

Files changed (5)

src/iframetoolbox/middleware.py

 #coding: utf-8
 
-import logger
+import logging
 
-from django.http import HttpResponse
+from django.shortcuts import render_to_response
 from django.conf import settings
 
 
+logger = logging.getLogger(__name__)
+
 DEFAULT_P3P_POLICY = 'IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'
 P3P_POLICY = getattr(settings, 'P3P_POLICY', DEFAULT_P3P_POLICY)
 
         browser_is_safari = 'Safari' in user_agent and 'Chrome' not in user_agent
         first_request = 'cookie_fix' not in request.GET and request.COOKIES == {}
 
-        logger.info('================================================')
-        logger.info('Browser is safari: %s' % browser_is_safari)
-        logger.info('First request: %s' % first_request)
-        logger.info('Cookies : %s' % request.COOKIES)
-        logger.info('================================================')
-
         if browser_is_safari and first_request:
-            from django.core import urlresolvers
-
-            url = urlresolvers.reverse('iframetoolbox.views.iframe_fix')
-            html = '''<html><body onload="javascript: poponload()">'''
-            html += '''<a target=_blank href="javascript:popup();">Please Open This</a><br>'''
-            html += '''<a target=_blank href="javascript:refresh();">refresh</a>'''
-            html += '''
-            <script type="text/javascript">
-                var popup = function() {
-                    window.open("%s?cookie_fix=1", "mywindow", "location=1,status=1,scrollbars=0,width=10,height=10");
-                }
-                var refresh = function() {
-                    window.location.replace(window.location.href+"&cookie_fix=1")
-                }
-            </script>
-            ''' % url
-
-            return HttpResponse(html)
+            return render_to_response('iframe/cookie_warning.html')
 
     def process_response(self, request, response):
         """

src/iframetoolbox/templates/iframe/cookie_page.html

+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+   "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+    <head>
+        <title>Creating Cookie</title>
+    </head>
+    <body>
+        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
+        <script type="text/javascript">
+            $(document).ready(function() {
+                window.close ();
+            });
+        </script>
+    </body>
+</html>

src/iframetoolbox/templates/iframe/cookie_warning.html

+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+   "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+    <head>
+        <title>Oops</title>
+    </head>
+    <body>
+
+        <p>
+            Hey, we noticed that you use Safari.
+            Unfortunately Safari has conservative cookie policy so we cannot start your session.
+            So to solve this problem we suggest to use other browser for example
+            <a target="_blank" href="http://www.mozilla.org/firefox/new/">Firefox</a>
+             or
+            <a target="_blank" href="www.google.com/chrome">Chrome</a>.
+            Or you can press following button to create your session and then refresh this page.
+        </p>
+
+        <div id="cookie_link" style="display:block">
+            <a target=_blank href="javascript:popup();">Please Open This</a><br>
+        </div>
+        <div id="refresh_link" style="display:none">
+            <a target=_blank href="javascript:refresh();">Refresh</a>
+        </div>
+
+        <script type="text/javascript">
+            var popup = function() {
+                window.open("{% url iframetoolbox.views.iframe_fix %}?cookie_fix=1", "mywindow", "location=1,status=1,scrollbars=0,width=10,height=10");
+                document.getElementById('cookie_link').style.display = 'none';
+                document.getElementById('refresh_link').style.display = 'block';
+            }
+            var refresh = function() {
+                window.location.replace(window.location.href+"&cookie_fix=1")
+            }
+        </script>
+    </body>
+</html>

src/iframetoolbox/urls.py

 
 urlpatterns = patterns(
     'iframetoolbox.views',
-    url(r'^iframefix/$', 'iframe_fix'),
+    url(r'iframefix/$', 'iframe_fix'),
 )

src/iframetoolbox/views.py

-from django.http import HttpResponse
+from django.shortcuts import render_to_response
 
 
 def iframe_fix(request):
-    html = '<html><body>'
-    html += '</body></html>'
-    return HttpResponse(html)
+    return render_to_response('iframe/cookie_page.html')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.