Added new signal
[django-cas-provider.git] / cas_provider / views.py
index bd9797c..6632722 100644 (file)
@@ -169,7 +169,7 @@ def validate(request):
             username = ticket.user.username
             ticket.delete()
 
-            results = signals.on_cas_collect_histories.send(sender=validate, for_email=ticket.user.email)
+            results = signals.on_cas_collect_histories.send(sender=validate, for_user=ticket.user)
             histories = '\n'.join('\n'.join(rs) for rc, rs in results)
             logger.info('Validated %s %s', username, "(also %s)" % histories if histories else '')
             return HttpResponse("yes\n%s\n%s" % (username, histories))
@@ -336,12 +336,20 @@ def auth_success_response(user, pgt, proxies):
     username = etree.SubElement(auth_success, CAS + 'user')
     username.text = user.username
 
-    if settings.CAS_CUSTOM_ATTRIBUTES_CALLBACK:
-        callback = get_callable(settings.CAS_CUSTOM_ATTRIBUTES_CALLBACK)
-        attrs = callback(user)
-        if len(attrs) > 0:
-            formater = get_callable(settings.CAS_CUSTOM_ATTRIBUTES_FORMATER)
-            formater(auth_success, attrs)
+    attrs = {}
+    for receiver, custom in signals.cas_collect_custom_attributes.send(sender=auth_success_response, user=user):
+        if custom:
+            attrs.update(custom)
+
+    identifiers = [i for sr, rr in signals.on_cas_collect_histories.send(sender=validate, for_user=user)
+                   for i in rr]
+
+    if identifiers:
+        attrs['identifiers'] = identifiers
+
+    if attrs:
+        formatter = get_callable(settings.CAS_CUSTOM_ATTRIBUTES_FORMATER)
+        formatter(auth_success, attrs)
 
     if pgt:
         pgtElement = etree.SubElement(auth_success, CAS + 'proxyGrantingTicket')