2012-06-27 23:28:35 +02:00
|
|
|
|
from django.conf import settings
|
2017-05-30 20:44:30 +02:00
|
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
|
|
2016-05-26 22:20:04 +02:00
|
|
|
|
from django_cas_ng.backends import CASBackend
|
2012-07-11 17:39:20 +02:00
|
|
|
|
|
2016-12-22 02:00:10 +01:00
|
|
|
|
from gestioncof.models import CofProfile
|
2012-07-11 17:39:20 +02:00
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
|
class COFCASBackend(CASBackend):
|
2016-11-05 18:31:40 +01:00
|
|
|
|
|
2017-05-30 20:44:30 +02:00
|
|
|
|
def clean_username(self, username):
|
2016-11-05 18:31:40 +01:00
|
|
|
|
# Le CAS de l'ENS accepte les logins avec des espaces au début
|
|
|
|
|
# et à la fin, ainsi qu’avec une casse variable. On normalise pour
|
|
|
|
|
# éviter les doublons.
|
2017-05-30 20:44:30 +02:00
|
|
|
|
return username.strip().lower()
|
|
|
|
|
|
|
|
|
|
def configure_user(self, user):
|
2017-05-31 22:00:51 +02:00
|
|
|
|
clipper = user.username
|
|
|
|
|
user.profile.login_clipper = clipper
|
|
|
|
|
user.profile.save()
|
|
|
|
|
user.email = settings.CAS_EMAIL_FORMAT % clipper
|
2017-05-30 20:44:30 +02:00
|
|
|
|
user.save()
|
2012-06-27 23:28:35 +02:00
|
|
|
|
return user
|
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
|
|
|
|
|
def context_processor(request):
|
2012-06-27 23:28:35 +02:00
|
|
|
|
'''Append extra data to the context of the given request'''
|
|
|
|
|
data = {
|
2016-12-22 12:28:03 +01:00
|
|
|
|
"user": request.user,
|
|
|
|
|
"site": Site.objects.get_current(),
|
|
|
|
|
}
|
2012-06-27 23:28:35 +02:00
|
|
|
|
return data
|