Add auth_backends.AttrCASBackend 0.1.17
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 27 Mar 2014 14:21:35 +0000 (15:21 +0100)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 27 Mar 2014 14:21:35 +0000 (15:21 +0100)
fnpdjango/auth_backends.py [new file with mode: 0644]
setup.py

diff --git a/fnpdjango/auth_backends.py b/fnpdjango/auth_backends.py
new file mode 100644 (file)
index 0000000..3cd60a7
--- /dev/null
@@ -0,0 +1,22 @@
+from django.conf import settings
+from django_cas.backends import CASBackend
+
+attr_map = getattr(settings, 'CAS_USER_ATTRS_MAP', {
+    'email': 'email',
+    'firstname': 'first_name',
+    'lastname': 'last_name',
+})
+
+class AttrCASBackend(CASBackend):
+    def authenticate(self, ticket, service, request):
+        user = super(AttrCASBackend, self).authenticate(ticket, service, request)
+        for attr, value in request.session.get('attributes', {}).items():
+            try:
+                local_attr = attr_map[attr]
+            except KeyError:
+                pass
+            else:
+                setattr(user, local_attr, value)
+        user.save()
+        return user
+
index ccc5a59..6444a5c 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_trees(package_dir, paths):
 
 setup(
     name='fnpdjango',
-    version='0.1.16',
+    version='0.1.17',
     author='Radek Czajka',
     author_email='radekczajka@nowoczesnapolska.org.pl',
     url = '',