Commits

Jay Yu  committed 6d74818

pep8, pyflakes fixes
extra options in login()

  • Participants
  • Parent commits 91e036d

Comments (0)

Files changed (5)

File django_cas/backends.py

 
 __all__ = ['CASBackend']
 
+
 def _verify_cas1(ticket, service):
     """Verifies CAS 1.0 authentication ticket.
 
     params = {'ticket': ticket, 'service': service}
     url = (urljoin(settings.CAS_SERVER_URL, 'validate') + '?' +
            urlencode(params))
+
     page = urlopen(url)
+
     try:
         verified = page.readline().strip()
         if verified == 'yes':
 
 class CASBackend(object):
     """CAS authentication backend"""
-
     def authenticate(self, ticket, service):
         """Verifies CAS ticket and gets or creates User object"""
 

File django_cas/decorators.py

 
 __all__ = ['login_required', 'permission_required', 'user_passes_test']
 
+
 def user_passes_test(test_func, login_url=None,
                      redirect_field_name=REDIRECT_FIELD_NAME):
     """Replacement for django.contrib.auth.decorators.user_passes_test that

File django_cas/middleware.py

 
 __all__ = ['CASMiddleware']
 
+
 class CASMiddleware(object):
     """Middleware that allows CAS authentication on admin pages"""
 

File django_cas/models.py

-from django.db import models
-from django.contrib.auth.models import User

File django_cas/views.py

 
 __all__ = ['login', 'logout']
 
+
 def _service_url(request, redirect_to=None):
     """Generates application service URL for CAS"""
 
 
 
 def _logout_url(request, next_page=None):
-    """Generates CAS logout URL"""
+    """Generates CAS logout URL
+
+    FIXME: next_page should accept URL with or without method and hostname
+    FIXME: Should use URL parse here.
+
+    FIXME: ?? Consider using settings / Sites instead of get_host()
+    """
 
     url = urljoin(settings.CAS_SERVER_URL, 'logout')
     if next_page:
     return url
 
 
-def login(request, next_page=None, required=False):
+def login(request, next_page=None, required=False, login_messages=True):
     """Forwards to CAS login URL or verifies CAS ticket"""
 
     if not next_page:
         next_page = _redirect_url(request)
     if request.user.is_authenticated():
-        message = "You are logged in as %s." % request.user.username
-        request.user.message_set.create(message=message)
+        if login_messages:
+            message = "You are logged in as %s." % request.user.username
+            request.user.message_set.create(message=message)
         return HttpResponseRedirect(next_page)
     ticket = request.GET.get('ticket')
     service = _service_url(request, next_page)
         user = auth.authenticate(ticket=ticket, service=service)
         if user is not None:
             auth.login(request, user)
-            name = user.first_name or user.username
-            message = "Login succeeded. Welcome, %s." % name
-            user.message_set.create(message=message)
+            if login_messages:
+                name = user.first_name or user.username
+                message = "Login succeeded. Welcome, %s." % name
+                user.message_set.create(message=message)
             return HttpResponseRedirect(next_page)
         elif settings.CAS_RETRY_LOGIN or required:
             return HttpResponseRedirect(_login_url(service))