From 1cf12421f09e4a6be5639c1791a516ca0d09b50f Mon Sep 17 00:00:00 2001 From: Ju Luiselli Date: Wed, 12 Feb 2020 23:21:24 +0100 Subject: [PATCH] added CAS authentification --- annuaire/settings.py | 11 +++++++++++ annuaire/urls.py | 5 ++++- fiches/forms.py | 2 +- fiches/migrations/0004_auto_20200212_2130.py | 20 ++++++++++++++++++++ fiches/templates/fiches/base.html | 5 +++++ requirements.txt | 3 ++- 6 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 fiches/migrations/0004_auto_20200212_2130.py diff --git a/annuaire/settings.py b/annuaire/settings.py index 657cae3..0501811 100644 --- a/annuaire/settings.py +++ b/annuaire/settings.py @@ -36,6 +36,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django_cas_ng', 'fiches' ] @@ -67,6 +68,11 @@ TEMPLATES = [ }, ] +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'django_cas_ng.backends.CASBackend', +) + WSGI_APPLICATION = 'annuaire.wsgi.application' @@ -123,3 +129,8 @@ STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' + +CAS_SERVER_URL = 'https://cas.eleves.ens.fr/' + +CAS_VERSION = "2" + diff --git a/annuaire/urls.py b/annuaire/urls.py index b8febf5..85e272c 100644 --- a/annuaire/urls.py +++ b/annuaire/urls.py @@ -18,12 +18,15 @@ from django.contrib import admin from django.urls import path, include from django.conf.urls.static import static from fiches.views import home, birthday +import django_cas_ng.views as cas_views urlpatterns = [ path('admin/', admin.site.urls), path('fiche/', include('fiches.urls')), path('', home, name='home'), - path('birthday', birthday, name='birthday') + path('birthday', birthday, name='birthday'), + path('login', cas_views.LoginView.as_view(), name='cas_ng_login'), + path('logout', cas_views.LogoutView.as_view(), name='cas_ng_logout'), ] if settings.DEBUG: diff --git a/fiches/forms.py b/fiches/forms.py index d978399..89ab3c4 100644 --- a/fiches/forms.py +++ b/fiches/forms.py @@ -24,7 +24,7 @@ class SearchForm(forms.Form): year = forms.IntegerField(label='Promotion', required=False) department = forms.ModelMultipleChoiceField( queryset=Department.objects.all(), required=False - ) + ) def clean(self): cleaned_data = super().clean() diff --git a/fiches/migrations/0004_auto_20200212_2130.py b/fiches/migrations/0004_auto_20200212_2130.py new file mode 100644 index 0000000..672d23f --- /dev/null +++ b/fiches/migrations/0004_auto_20200212_2130.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.9 on 2020-02-12 21:30 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('fiches', '0003_auto_20200108_2306'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL, verbose_name='utilisateur'), + ), + ] diff --git a/fiches/templates/fiches/base.html b/fiches/templates/fiches/base.html index 0e4fa7b..dd66119 100644 --- a/fiches/templates/fiches/base.html +++ b/fiches/templates/fiches/base.html @@ -29,6 +29,11 @@ Modifier sa fiche d'annuaire Consulter sa fiche d'annuaire Anniversaires à venir + {% if user.is_authenticated %} + Se déconnecter + {% else %} + Se connecter + {% endif %} diff --git a/requirements.txt b/requirements.txt index 1b3a0c4..4e4fcaf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ django==2.2.* -Pillow \ No newline at end of file +Pillow +django_cas_ng