localhost check needs to use portless-HTTP_HOST
authorAlex Dehnert <adehnert@mit.edu>
Sun, 30 May 2010 02:34:45 +0000 (22:34 -0400)
committerAlex Dehnert <adehnert@mit.edu>
Mon, 6 Jun 2011 06:04:39 +0000 (02:04 -0400)
As a bonus, this gets around the problem that the Django dev server doesn't
set REQUEST_URI.

django/mit/__init__.py

index 8858248fc0c3371583d5561d200f66555826e140..8f785ae9b8b6331debfaacc5edf9ea92b115bc5e 100644 (file)
@@ -46,7 +46,8 @@ class ScriptsRemoteUserBackend(RemoteUserBackend):
         return user
 
 def scripts_login(request, **kwargs):
-    if request.META['HTTP_HOST'] == 'localhost':
+    host = request.META['HTTP_HOST'].split(':')[0]
+    if host == 'localhost':
         return login(request, **kwargs)
     elif request.META['SERVER_PORT'] == '444':
         if request.user.is_authenticated():
@@ -64,6 +65,5 @@ def scripts_login(request, **kwargs):
             return login(request, **kwargs)
     else:
         # Move to port 444
-        host = request.META['HTTP_HOST'].split(':')[0]
         redirect_to = "https://%s:444%s" % (host, request.META['REQUEST_URI'], )
         return HttpResponseRedirect(redirect_to)