+ try:
+ ticket = ServiceTicket.objects.get(ticket=ticket_string)
+ username = ticket.user.username
+ ticket.delete()
+ return HttpResponse('''<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
+ <cas:authenticationSuccess>
+ <cas:user>%(username)s</cas:user>
+ </cas:authenticationSuccess>
+ </cas:serviceResponse>''' % {'username': username}, mimetype='text/xml')
+ except ServiceTicket.DoesNotExist:
+ return HttpResponse(''''<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
+ <cas:authenticationFailure code="INVALID_TICKET">
+ The provided ticket is invalid.
+ </cas:authenticationFailure>
+ </cas:serviceResponse>''', mimetype='text/xml')
+