X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/cc61c5969227c2d49544997ebbf074541029400b..6e54c3e5eb1ee4a53886b3ca0238603d522eb4d3:/cas_provider/models.py?ds=sidebyside diff --git a/cas_provider/models.py b/cas_provider/models.py index 94023b7..5d09912 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.etree 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')