Get project from its branch head.
[fnpdjango.git] / fnpdjango / auth_backends.py
1 from django.conf import settings
2 from django_cas.backends import CASBackend
3
4 attr_map = getattr(settings, 'CAS_USER_ATTRS_MAP', {
5     'email': 'email',
6     'firstname': 'first_name',
7     'lastname': 'last_name',
8 })
9
10 class AttrCASBackend(CASBackend):
11     def authenticate(self, ticket, service, request):
12         user = super(AttrCASBackend, self).authenticate(ticket, service, request)
13         for attr, value in request.session.get('attributes', {}).items():
14             try:
15                 local_attr = attr_map[attr]
16             except KeyError:
17                 pass
18             else:
19                 setattr(user, local_attr, value)
20         user.save()
21         return user
22