gestioCOF/gestioncof/shared.py

25 lines
855 B
Python
Raw Normal View History

2012-06-27 23:28:35 +02:00
from django.contrib.sites.models import Site
from django.conf import settings
from django_cas.backends import CASBackend
class COFCASBackend(CASBackend):
def authenticate(self, ticket, service):
"""Authenticates CAS ticket and retrieves user data"""
user = super(COFCASBackend, self).authenticate(ticket, service)
profile = user.get_profile()
if not profile.login_clipper:
profile.login_clipper = user.username
profile.save()
if not user.email:
user.email = settings.CAS_EMAIL_FORMAT % profile.login_clipper
user.save()
return user
def context_processor (request):
'''Append extra data to the context of the given request'''
data = {
"user": request.user,
"site": Site.objects.get_current(),
}
return data