Additional documentation and cleaned up imports in views.py
authorChris Williams <chris@nitron.org>
Wed, 18 Mar 2009 05:07:21 +0000 (01:07 -0400)
committerChris Williams <chris@nitron.org>
Wed, 18 Mar 2009 05:07:21 +0000 (01:07 -0400)
.gitignore [new file with mode: 0644]
README.rst [new file with mode: 0644]
cas_provider/templates/cas/login.html [new file with mode: 0644]
cas_provider/templates/cas/logout.html [new file with mode: 0644]
cas_provider/utils.py
cas_provider/views.py

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..0d20b64
--- /dev/null
@@ -0,0 +1 @@
+*.pyc
diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..0677574
--- /dev/null
@@ -0,0 +1,38 @@
+===================
+django-cas-provider
+===================
+
+---------------------------------
+Chris Williams <chris@nitron.org>
+---------------------------------
+
+OVERVIEW
+=========
+
+django-cas-provider is a provider for the `Central Authentication 
+Service <http://jasig.org/cas>`_. It supports CAS version 1.0. It allows 
+remote services to authenticate users for the purposes of 
+Single Sign-On (SSO). For example, a user logs into a CAS server 
+(provided by django-cas-provider) and can then access other services 
+(such as email, calendar, etc) without re-entering her password for
+each service. For more details, see the `CAS wiki <http://www.ja-sig.org/wiki/display/CAS/Home>`_
+and `Single Sign-On on Wikipedia <http://en.wikipedia.org/wiki/Single_Sign_On>`_.
+
+INSTALLATION
+=============
+
+To install, run the following command from this directory:
+
+               ``python setup.py install``
+
+Or, put cas_provider somewhere on your Python path.
+       
+USAGE
+======
+
+#. Add ``'cas_provider'`` to your ``INSTALLED_APPS`` tuple in *settings.py*.
+#. In *settings.py*, set ``LOGIN_URL`` to ``'/cas/login/'`` and ``LOGOUT_URL`` to ``'/cas/logout/'``
+       before they expire. Default: 5 minutes
+#. In *urls.py*, put the following line:
+    ``(r'^cas/', include('cas_provider.urls')),``
+#. Create login/logout templates (or modify the samples)
diff --git a/cas_provider/templates/cas/login.html b/cas_provider/templates/cas/login.html
new file mode 100644 (file)
index 0000000..d61974a
--- /dev/null
@@ -0,0 +1,24 @@
+{% extends "base.html" %}
+
+{% block title %}
+Login
+{% endblock %}
+
+{% block content %}
+  <form action='.' method='post'>
+    <fieldset>
+      <legend>Log in to your account</legend>
+      {% if errors %}
+        <ul>
+            {% for error in errors %}
+                <li>{{ error|escape }}</li>
+            {% endfor %}
+        </ul>
+      {% endif %}
+      <table style="border: none;">
+        {{ form.as_table }}
+      </table>
+      <p><input type="submit" value="Login"/></p>
+    </fieldset>
+  </form>
+{% endblock %}
diff --git a/cas_provider/templates/cas/logout.html b/cas_provider/templates/cas/logout.html
new file mode 100644 (file)
index 0000000..e5e435f
--- /dev/null
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+
+{% block title %}
+Logged out
+{% endblock %}
+
+{% block content %}
+    <h3>Logged out</h3>
+
+    <p>You have successfully logged out. To ensure that you are logged out of all services, please close your browser.</p>
+    {% if url %}<p><a href="{{ url }}">Click here</a> to return to {{ url }}</p>{% endif %}
+{% endblock %}
index 501f63a..3d64c16 100644 (file)
@@ -4,15 +4,20 @@ import string
 from models import ServiceTicket, LoginTicket
 
 def _generate_string(length=8, chars=string.letters + string.digits):
 from models import ServiceTicket, LoginTicket
 
 def _generate_string(length=8, chars=string.letters + string.digits):
+    """ Generates a random string of the requested length. Used for creation of tickets. """
     return ''.join(Random().sample(string.letters+string.digits, length))
 
 def create_service_ticket(user, service):
     return ''.join(Random().sample(string.letters+string.digits, length))
 
 def create_service_ticket(user, service):
+    """ Creates a new service ticket for the specified user and service.
+        Uses _generate_string.
+    """
     ticket_string = 'ST-' + _generate_string(29) # Total ticket length = 29 + 3 = 32
     ticket = ServiceTicket(service=service, user=user, ticket=ticket_string)
     ticket.save()
     return ticket
 
 def create_login_ticket():
     ticket_string = 'ST-' + _generate_string(29) # Total ticket length = 29 + 3 = 32
     ticket = ServiceTicket(service=service, user=user, ticket=ticket_string)
     ticket.save()
     return ticket
 
 def create_login_ticket():
+    """ Creates a new login ticket for the login form. Uses _generate_string. """
     ticket_string = 'LT-' + _generate_string(29)
     ticket = LoginTicket(ticket=ticket_string)
     ticket.save()
     ticket_string = 'LT-' + _generate_string(29)
     ticket = LoginTicket(ticket=ticket_string)
     ticket.save()
index 6fc19f6..27c7f7a 100644 (file)
@@ -1,7 +1,5 @@
 from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
 from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
-from django.shortcuts import get_object_or_404, render_to_response, get_list_or_404
-from django.core.urlresolvers import reverse
-from django.core.exceptions import SuspiciousOperation
+from django.shortcuts import render_to_response
 from django.template import RequestContext
 from django.contrib.auth.models import User
 from django.contrib.auth import authenticate
 from django.template import RequestContext
 from django.contrib.auth.models import User
 from django.contrib.auth import authenticate