1.7
[auf_django_saml.git] / auf / django / saml / views.py
index d899022..7c46548 100644 (file)
@@ -1,6 +1,5 @@
 # -*- coding: utf-8 -*-
 
-from django.http import HttpResponse
 from django.core.urlresolvers import reverse
 from django.contrib.auth import login as auth_login
 from django.contrib.auth import logout as auth_logout
@@ -11,13 +10,18 @@ from settings import SAML_REDIRECT_FIELD_NAME,\
         SAML_MELLON_LOGIN_URL,\
         SAML_MELLON_LOGOUT_URL,\
         SAML_CHANGE_PASSWORD_URL,\
-        SAML_LOGOUT_REDIRECT_URL
+        SAML_LOGOUT_REDIRECT_URL, \
+        SAML_AUTH
 
 
 def redirect_to_login(request, redirect_to=None, do_redirect=True):
     if redirect_to is None:
         redirect_to = request.get_full_path()
-    url = "%s?%s=%s" % (SAML_MELLON_LOGIN_URL,
+    if SAML_AUTH:
+        base_url = SAML_MELLON_LOGIN_URL
+    else:
+        base_url = reverse('sandbox_login')
+    url = "%s?%s=%s" % (base_url,
             SAML_REDIRECT_FIELD_NAME,
             redirect_to,
             )
@@ -66,10 +70,12 @@ def local_logout(request, ):
     """
     query_string = request.META['QUERY_STRING']
     auth_logout(request)
-    logout_url = "%s?%s" % (SAML_MELLON_LOGOUT_URL, query_string)
-    response = HttpResponse(content="", status=303)
-    response["Location"] = logout_url
-    return response
+    if SAML_AUTH:
+        base_url = SAML_MELLON_LOGOUT_URL
+    else:
+        base_url = reverse('sandbox_logout')
+    logout_url = "%s?%s" % (base_url, query_string)
+    return redirect(logout_url)
 
 
 def mellon_logout(request, ):