From 21641c946823d509a12e4ea342df4be71d86b7e8 Mon Sep 17 00:00:00 2001 From: Basile Clement Date: Thu, 26 May 2016 22:20:04 +0200 Subject: [PATCH] Migration vers django_cas_ng MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Précédemment, GestioCOF utilisait django-cas, qui n'est plus maintenu. Ceci le remplace par django-cas-ng, un fork plus récent et maintenu. En particulier, django-cas-ng est compatible avec Python 3, contrairement à django-cas. --- cof/settings_dev.py | 1 + cof/urls.py | 4 ++-- gestioncof/decorators.py | 2 +- gestioncof/shared.py | 10 +++++++--- gestioncof/templates/login_switch.html | 2 +- gestioncof/views.py | 2 +- requirements.txt | 2 +- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cof/settings_dev.py b/cof/settings_dev.py index ad94d649..8b0f423e 100644 --- a/cof/settings_dev.py +++ b/cof/settings_dev.py @@ -46,6 +46,7 @@ INSTALLED_APPS = ( 'autocomplete_light', 'eav', 'captcha', + 'django_cas_ng', 'debug_toolbar', ) diff --git a/cof/urls.py b/cof/urls.py index 991fb72f..3e63ae02 100644 --- a/cof/urls.py +++ b/cof/urls.py @@ -16,8 +16,8 @@ from gestioncof.petits_cours_views import DemandeListView urlpatterns = patterns('', url(r'^$', 'gestioncof.views.home', name = 'home'), url(r'^cof/denied$', TemplateView.as_view(template_name = 'cof-denied.html'), name = "cof-denied"), - url(r'^cas/login$', 'django_cas.views.login', name = "cas_login_view"), - url(r'^cas/logout$', 'django_cas.views.logout'), + url(r'^cas/login$', 'django_cas_ng.views.login', name = "cas_login_view"), + url(r'^cas/logout$', 'django_cas_ng.views.logout'), url(r'^outsider/login$', 'gestioncof.views.login_ext'), url(r'^outsider/logout$', 'django.contrib.auth.views.logout', {'next_page': '/gestion/'}), url(r'^outsider/password-change$', 'django.contrib.auth.views.password_change'), diff --git a/gestioncof/decorators.py b/gestioncof/decorators.py index b276d372..1a3d60c5 100644 --- a/gestioncof/decorators.py +++ b/gestioncof/decorators.py @@ -1,4 +1,4 @@ -from django_cas.decorators import user_passes_test +from django_cas_ng.decorators import user_passes_test def is_cof(user): try: diff --git a/gestioncof/shared.py b/gestioncof/shared.py index f46f7f90..5a6c7775 100644 --- a/gestioncof/shared.py +++ b/gestioncof/shared.py @@ -1,7 +1,8 @@ from django.contrib.sites.models import Site from django.conf import settings -from django_cas.backends import CASBackend, _verify as CASverify -from django_cas.models import User +from django_cas_ng.backends import CASBackend +from django_cas_ng.utils import get_cas_client +from django.contrib.auth import get_user_model from django.contrib.auth.models import User as DjangoUser from django.db import models, connection from django.core.mail import send_mail @@ -9,11 +10,14 @@ from django.template import Template, Context from gestioncof.models import CofProfile, CustomMail +User = get_user_model() + class COFCASBackend(CASBackend): def authenticate_cas(self, ticket, service, request): """Verifies CAS ticket and gets or creates User object""" - username, attributes = CASverify(ticket, service) + client = get_cas_client(service_url=service) + username, attributes, _= client.verify_ticket(ticket) if attributes: request.session['attributes'] = attributes if not username: diff --git a/gestioncof/templates/login_switch.html b/gestioncof/templates/login_switch.html index 84ae1878..fe816a78 100644 --- a/gestioncof/templates/login_switch.html +++ b/gestioncof/templates/login_switch.html @@ -3,7 +3,7 @@ {% block content %}