From: dwickwire Date: Fri, 20 Jan 2012 19:19:31 +0000 (-0600) Subject: Changed the CAS Protocol! A 'yes' or 'no' first line followed with the user is still... X-Git-Tag: 22.4~51 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/08d3502c8f9a169713122c681d86eb16d9f8c1e6?ds=sidebyside Changed the CAS Protocol! A 'yes' or 'no' first line followed with the user is still consistent. Now, the response has historical identifiers trailing the primary user, each on a new line. Clients should check for each identifier... -- if one is matched, use that username -- if two are matched, merge accounts on client end -- if none are matched, create a new user with primary username Old protocol response: yes foobar123 New protocol response: yes foobar123 barbaz345 barfoo789 --- diff --git a/cas_provider/views.py b/cas_provider/views.py index 235b38f..7204ae2 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -1,4 +1,5 @@ import logging +logger = logging.getLogger('cas_provider.views') import urllib from django.http import HttpResponse, HttpResponseRedirect @@ -13,6 +14,10 @@ from models import ServiceTicket from utils import create_service_ticket from exceptions import SameEmailMismatchedPasswords +#FIXME: Remove this dependency +from accounts.models import IdentifierHistory +from django.contrib.auth.models import User + __all__ = ['login', 'validate', 'logout'] @@ -126,14 +131,23 @@ def socialauth_login(request, template_name='cas/login.html', success_redirect=' def validate(request): service = request.GET.get('service', None) ticket_string = request.GET.get('ticket', None) + logger.debug("service: %s"% service) + logger.debug("ticket_string: %s"% ticket_string) if service is not None and ticket_string is not None: try: ticket = ServiceTicket.objects.get(ticket=ticket_string) username = ticket.user.username ticket.delete() - return HttpResponse("yes\n%s\n" % username) - except: - pass + + histories = IdentifierHistory.objects.filter(user__email__iexact=ticket.user.email) + histories = '\n'.join(histories.values_list('identifier', flat=True)) + histories = '%s\n' % histories if histories else '' + + return HttpResponse("yes\n%s\n%s" % (username, histories)) + + except Exception as e: + logger.exception("Got an exception!: %s"% e) + return HttpResponse("no\n\n")