X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/5392ec6f8245dd4ecad27bba8a610dc198e537b6..bf06f0f8cde976e4e579b059fdb0e8a8bc279f01:/cas_provider/models.py?ds=sidebyside diff --git a/cas_provider/models.py b/cas_provider/models.py index 94023b7..eae9cf6 100644 --- a/cas_provider/models.py +++ b/cas_provider/models.py @@ -1,5 +1,9 @@ from django.db import models from django.contrib.auth.models import User +from django.conf import settings +from django.core.urlresolvers import get_callable + +from cas_provider.xml import etree, register_namespace, ElementRoot class ServiceTicket(models.Model): user = models.ForeignKey(User) @@ -15,4 +19,23 @@ class LoginTicket(models.Model): created = models.DateTimeField(auto_now=True) def __unicode__(self): - return "%s - %s" % (self.ticket, self.created) \ No newline at end of file + return "%s - %s" % (self.ticket, self.created) + +CAS_URI = 'http://www.yale.edu/tp/cas' +register_namespace('cas', CAS_URI) +CAS = '{%s}' % CAS_URI + +def auth_success_response(user): + attrs = {} + if settings.CAS_CUSTOM_ATTRIBUTES_CALLBACK: + callback = get_callable(settings.CAS_CUSTOM_ATTRIBUTES_CALLBACK) + attrs = callback(user) + + response = ElementRoot(CAS + 'serviceResponse') + auth_success = etree.SubElement(response, CAS + 'authenticationSuccess') + username = etree.SubElement(auth_success, CAS + 'user') + username.text = user.username + for name, value in attrs.items(): + element = etree.SubElement(auth_success, name) + element.text = value + return unicode(etree.tostring(response, encoding='utf-8'), 'utf-8')