From: Chris Williams Date: Wed, 18 Mar 2009 05:07:21 +0000 (-0400) Subject: Additional documentation and cleaned up imports in views.py X-Git-Tag: 22.4~71 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/c4e951ccbda6275dd5134a431af7e0ee8f129feb?hp=788f43bed3a5919a533d7e963f5729633a9c3197 Additional documentation and cleaned up imports in views.py --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..0677574 --- /dev/null +++ b/README.rst @@ -0,0 +1,38 @@ +=================== +django-cas-provider +=================== + +--------------------------------- +Chris Williams +--------------------------------- + +OVERVIEW +========= + +django-cas-provider is a provider for the `Central Authentication +Service `_. 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 `_ +and `Single Sign-On on Wikipedia `_. + +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 index 0000000..d61974a --- /dev/null +++ b/cas_provider/templates/cas/login.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block title %} +Login +{% endblock %} + +{% block content %} +
+
+ Log in to your account + {% if errors %} +
    + {% for error in errors %} +
  • {{ error|escape }}
  • + {% endfor %} +
+ {% endif %} + + {{ form.as_table }} +
+

+
+
+{% endblock %} diff --git a/cas_provider/templates/cas/logout.html b/cas_provider/templates/cas/logout.html new file mode 100644 index 0000000..e5e435f --- /dev/null +++ b/cas_provider/templates/cas/logout.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block title %} +Logged out +{% endblock %} + +{% block content %} +

Logged out

+ +

You have successfully logged out. To ensure that you are logged out of all services, please close your browser.

+ {% if url %}

Click here to return to {{ url }}

{% endif %} +{% endblock %} diff --git a/cas_provider/utils.py b/cas_provider/utils.py index 501f63a..3d64c16 100644 --- a/cas_provider/utils.py +++ b/cas_provider/utils.py @@ -4,15 +4,20 @@ import string 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): + """ 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(): + """ 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() diff --git a/cas_provider/views.py b/cas_provider/views.py index 6fc19f6..27c7f7a 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -1,7 +1,5 @@ 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