Tweaked to use emails instead of usernames.
[django-cas-provider.git] / cas_provider / views.py
index 27c7f7a..47f1758 100644 (file)
@@ -1,7 +1,6 @@
-from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
+from django.http import HttpResponse, HttpResponseRedirect
 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.contrib.auth import login as auth_login, logout as auth_logout
 
@@ -24,7 +23,7 @@ def login(request, template_name='cas/login.html', success_redirect='/accounts/'
             return HttpResponseRedirect(success_redirect)
     errors = []
     if request.method == 'POST':
-        username = request.POST.get('username', None)
+        email = request.POST.get('email', None)
         password = request.POST.get('password', None)
         service = request.POST.get('service', None)
         lt = request.POST.get('lt', None)
@@ -35,7 +34,7 @@ def login(request, template_name='cas/login.html', success_redirect='/accounts/'
             errors.append('Login ticket expired. Please try again.')
         else:
             login_ticket.delete()
-            user = authenticate(username=username, password=password)
+            user = authenticate(username=email, password=password)
             if user is not None:
                 if user.is_active:
                     auth_login(request, user)
@@ -57,14 +56,15 @@ def validate(request):
     if service is not None and ticket_string is not None:
         try:
             ticket = ServiceTicket.objects.get(ticket=ticket_string)
-            username = ticket.user.username
+            ### NOTE: We've changed this to return the email address, not the username.
+            email = ticket.user.email
             ticket.delete()
-            return HttpResponse("yes\n\r%s\n\r" % username)
+            return HttpResponse("yes\n%s\n" % email)
         except:
             pass
-    return HttpResponse("no\n\r\n\r")
+    return HttpResponse("no\n\n")
     
 def logout(request, template_name='cas/logout.html'):
     url = request.GET.get('url', None)
     auth_logout(request)
-    return render_to_response(template_name, {'url': url}, context_instance=RequestContext(request))
\ No newline at end of file
+    return render_to_response(template_name, {'url': url}, context_instance=RequestContext(request))