From fb06e2005c8af515ba32047f4ba6b1bdd4078e97 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 14:35:21 +0200 Subject: [PATCH 01/12] Message support --- authens/static/authens/css/authens.css | 10 ++++++++++ authens/templates/authens/base.html | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/authens/static/authens/css/authens.css b/authens/static/authens/css/authens.css index 4cedbc5..be95245 100644 --- a/authens/static/authens/css/authens.css +++ b/authens/static/authens/css/authens.css @@ -60,6 +60,16 @@ h2 { text-align: center; } +.success { + background: green; + color: white; + width: 100%; + padding: 0.5em; + margin: 0; + font-size: 1.2em; + text-align: center; +} + ul.errorlist { text-align: left; font-size: 0.8em; diff --git a/authens/templates/authens/base.html b/authens/templates/authens/base.html index 19642fd..d9e5ff3 100644 --- a/authens/templates/authens/base.html +++ b/authens/templates/authens/base.html @@ -16,8 +16,21 @@
{% block container-top %} -

{% if request.site.name %}{{ request.site.name }}{% else %}AuthENS{% endif %} - {% block container-title %}{% endblock %}

+

{% if request.site.name %}{{ request.site.name }}{% else %}AuthENS{% endif %} - {% block container-title %}{% endblock %}

{% endblock %} + + {% if messages %} + {% for message in messages %} +

+ {% if 'safe' in message.tags %} + {{ message|safe }} + {% else %} + {{ message }} + {% endif %} +

+ {% endfor %} + {% endif %} + {% block content %}{% endblock %}
From 5f5edb4935888274c95e2833c5421b923006f6e1 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 14:37:04 +0200 Subject: [PATCH 02/12] Backend for pwd reset views --- authens/urls.py | 6 ++++++ authens/views.py | 30 +++++++++++++++++++++++++-- example_site/example_site/settings.py | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/authens/urls.py b/authens/urls.py index 1fe4eb9..28dcbfa 100644 --- a/authens/urls.py +++ b/authens/urls.py @@ -9,4 +9,10 @@ urlpatterns = [ path("login/pwd", views.PasswordLoginView.as_view(), name="login.pwd"), path("login/oldcas", views.OldCASLoginView.as_view(), name="login.oldcas"), path("logout", views.LogoutView.as_view(), name="logout"), + path("reset/pwd", views.PasswordResetView.as_view(), name="reset.pwd"), + path( + "reset/pwd///", + views.PasswordResetConfirmView.as_view(), + name="reset.pwd.confirm", + ), ] diff --git a/authens/views.py b/authens/views.py index d5641a5..60aaf9a 100644 --- a/authens/views.py +++ b/authens/views.py @@ -3,13 +3,16 @@ from urllib.parse import urlparse, urlunparse from django.conf import settings from django.contrib import auth from django.contrib.auth import views as auth_views +from django.contrib.messages.views import SuccessMessageMixin from django.core.exceptions import PermissionDenied -from django.views.generic import TemplateView, View from django.shortcuts import redirect +from django.utils import timezone from django.utils.translation import gettext_lazy as _ +from django.urls import reverse_lazy +from django.views.generic import TemplateView, View -from authens.utils import get_cas_client from authens.forms import OldCASAuthForm +from authens.utils import get_cas_client class NextPageMixin: @@ -80,10 +83,33 @@ class PasswordLoginView(auth_views.LoginView): template_name = "authens/pwd_login.html" +class PasswordResetView(SuccessMessageMixin, auth_views.PasswordResetView): + template_name = "authens/pwd_reset.html" + email_template_name = "authens/pwd_reset_email.txt" + subject_template_name = "authens/pwd_reset_subject.txt" + success_url = reverse_lazy("authens:login") + + success_message = _( + "Un email de réinitialisation vient d'être envoyé à l'adresse indiquée !" + ) + + +class PasswordResetConfirmView( + SuccessMessageMixin, auth_views.PasswordResetConfirmView +): + template_name = "authens/pwd_reset_confirm.html" + success_url = reverse_lazy("authens:login") + + success_message = _("Mot de passe modifié avec succès !") + + class OldCASLoginView(auth_views.LoginView): template_name = "authens/old_cas_login.html" authentication_form = OldCASAuthForm + def get_initial(self): + return {"entrance_year": timezone.now().year - 5} + class LogoutView(auth_views.LogoutView): """Logout view of AuthENS. diff --git a/example_site/example_site/settings.py b/example_site/example_site/settings.py index a2eb594..fdb8240 100644 --- a/example_site/example_site/settings.py +++ b/example_site/example_site/settings.py @@ -128,6 +128,8 @@ AUTHENTICATION_BACKENDS = [ "authens.backends.OldCASBackend", ] LOGIN_URL = reverse_lazy("authens:login") +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" + # This is cosmetic LOGIN_REDIRECT_URL = reverse_lazy("home") From 5c39b91157faec79c7894a2fcbaf3b3e65300dc2 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 14:37:11 +0200 Subject: [PATCH 03/12] Templates --- authens/templates/authens/pwd_reset.html | 16 ++++++++++++++++ authens/templates/authens/pwd_reset_confirm.html | 16 ++++++++++++++++ authens/templates/authens/pwd_reset_email.txt | 12 ++++++++++++ authens/templates/authens/pwd_reset_subject.txt | 1 + 4 files changed, 45 insertions(+) create mode 100644 authens/templates/authens/pwd_reset.html create mode 100644 authens/templates/authens/pwd_reset_confirm.html create mode 100644 authens/templates/authens/pwd_reset_email.txt create mode 100644 authens/templates/authens/pwd_reset_subject.txt diff --git a/authens/templates/authens/pwd_reset.html b/authens/templates/authens/pwd_reset.html new file mode 100644 index 0000000..f999dda --- /dev/null +++ b/authens/templates/authens/pwd_reset.html @@ -0,0 +1,16 @@ +{% extends "authens/base.html" %} +{% load i18n %} + +{% block container-title %} +{% trans "Réinitialisation du mot de passe" %} +{% endblock %} + +{% block content %} + {% for error in form.non_field_errors %} +

{{ error }}

+ {% endfor %} + +
+ {% include "authens/form_full_snippet.html" with submit_text="Valider" %} +
+{% endblock %} diff --git a/authens/templates/authens/pwd_reset_confirm.html b/authens/templates/authens/pwd_reset_confirm.html new file mode 100644 index 0000000..c80d59e --- /dev/null +++ b/authens/templates/authens/pwd_reset_confirm.html @@ -0,0 +1,16 @@ +{% extends "authens/base.html" %} +{% load i18n %} + +{% block container-title %} +{% trans "Nouveau mot de passe" %} +{% endblock %} + +{% block content %} + {% for error in form.non_field_errors %} +

{{ error }}

+ {% endfor %} + +
+ {% include "authens/form_full_snippet.html" with submit_text="Valider" %} +
+{% endblock %} diff --git a/authens/templates/authens/pwd_reset_email.txt b/authens/templates/authens/pwd_reset_email.txt new file mode 100644 index 0000000..a0ed323 --- /dev/null +++ b/authens/templates/authens/pwd_reset_email.txt @@ -0,0 +1,12 @@ +{% load i18n %}{% autoescape off %} +{% blocktrans %}Quelqu'un (probablement vous) a demandé la réinitialisation du mot de passe associé à cette addresse sur {{ site_name }}.{% endblocktrans %} + +{% blocktrans %}S'il s'agit bien de vous, vous pouvez vous rendre à l'adresse suivante pour en choisir un nouveau : {% endblocktrans %} +{% block reset_link %} +{{ protocol }}://{{ domain }}{% url "authens:reset.pwd.confirm" uidb64=uid token=token %} +{% endblock %} +{% blocktrans with username=user.get_username %}Au cas où, votre nom d'utilisateur est le suivant : {{ username }}{% endblocktrans %} + +{% block signature %}{% blocktrans %}L'équipe {{site_name}}{% endblocktrans %}{% endblock %} + +{% endautoescape %} \ No newline at end of file diff --git a/authens/templates/authens/pwd_reset_subject.txt b/authens/templates/authens/pwd_reset_subject.txt new file mode 100644 index 0000000..8d48712 --- /dev/null +++ b/authens/templates/authens/pwd_reset_subject.txt @@ -0,0 +1 @@ +Réinitialisation de votre mot de passe {{site_name}} \ No newline at end of file From e7b0d71416cd1e2575eb93606f7359fe925b4115 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 16:09:23 +0200 Subject: [PATCH 04/12] Integrate changes --- authens/templates/authens/pwd_reset.html | 8 +------- authens/templates/authens/pwd_reset_confirm.html | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/authens/templates/authens/pwd_reset.html b/authens/templates/authens/pwd_reset.html index f999dda..914f191 100644 --- a/authens/templates/authens/pwd_reset.html +++ b/authens/templates/authens/pwd_reset.html @@ -6,11 +6,5 @@ {% endblock %} {% block content %} - {% for error in form.non_field_errors %} -

{{ error }}

- {% endfor %} - -
- {% include "authens/form_full_snippet.html" with submit_text="Valider" %} -
+ {% include "authens/form_full_snippet.html" with form_class="exte" submit_text="Valider" %} {% endblock %} diff --git a/authens/templates/authens/pwd_reset_confirm.html b/authens/templates/authens/pwd_reset_confirm.html index c80d59e..98903ce 100644 --- a/authens/templates/authens/pwd_reset_confirm.html +++ b/authens/templates/authens/pwd_reset_confirm.html @@ -6,11 +6,5 @@ {% endblock %} {% block content %} - {% for error in form.non_field_errors %} -

{{ error }}

- {% endfor %} - -
- {% include "authens/form_full_snippet.html" with submit_text="Valider" %} -
+ {% include "authens/form_full_snippet.html" with form_class="exte" submit_text="Enregistrer" %} {% endblock %} From c236044ac24525be174290095991fd810c2e8091 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 16:45:59 +0200 Subject: [PATCH 05/12] Fix login switch css --- authens/static/authens/css/authens.css | 27 ++++++++++++--------- authens/templates/authens/base.html | 2 ++ authens/templates/authens/login_switch.html | 20 ++++++--------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/authens/static/authens/css/authens.css b/authens/static/authens/css/authens.css index be95245..1b2a180 100644 --- a/authens/static/authens/css/authens.css +++ b/authens/static/authens/css/authens.css @@ -7,22 +7,30 @@ html, body { } #container { - display: flex; - flex-flow: row wrap; padding: 10% 1em; min-width: 300px; max-width: 900px; margin: auto; } -h2 { - margin: 0; - padding: 15px; +#container-title { width: 100%; background: #505160; color: white; +} + +#container-title h2 { + padding: 15px; font-weight: initial; font-size: 2em; + margin: 0; +} + +#container-content { + text-align: center; + width: 100%; + display: flex; + flex-flow: row wrap; } .cas { @@ -40,10 +48,7 @@ h2 { color: white; } -#container-content { - text-align: center; - width: 100%; -} + .auth_form { padding: 0.5em; @@ -121,7 +126,7 @@ select { text-align: end; } -a { +.big-button { flex: 1; height: 200px; min-width: 300px; @@ -132,6 +137,6 @@ a { text-decoration: none; } -a:hover { +.big-button :hover { text-decoration: underline; } diff --git a/authens/templates/authens/base.html b/authens/templates/authens/base.html index d9e5ff3..e79bd67 100644 --- a/authens/templates/authens/base.html +++ b/authens/templates/authens/base.html @@ -16,7 +16,9 @@
{% block container-top %} +

{% if request.site.name %}{{ request.site.name }}{% else %}AuthENS{% endif %} - {% block container-title %}{% endblock %}

+
{% endblock %} {% if messages %} diff --git a/authens/templates/authens/login_switch.html b/authens/templates/authens/login_switch.html index a01b8fd..50d38e3 100644 --- a/authens/templates/authens/login_switch.html +++ b/authens/templates/authens/login_switch.html @@ -6,19 +6,15 @@ {% endblock %} {% block content %} - -
- {% trans "Clipper" %} -
+
{% endblock %} From 8b50092ff001e7af6fe9eb3a2abc0cf467d171ca Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 17:46:05 +0200 Subject: [PATCH 06/12] New adaptations --- authens/templates/authens/pwd_reset.html | 4 +++- authens/templates/authens/pwd_reset_confirm.html | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/authens/templates/authens/pwd_reset.html b/authens/templates/authens/pwd_reset.html index 914f191..393611c 100644 --- a/authens/templates/authens/pwd_reset.html +++ b/authens/templates/authens/pwd_reset.html @@ -6,5 +6,7 @@ {% endblock %} {% block content %} - {% include "authens/form_full_snippet.html" with form_class="exte" submit_text="Valider" %} +
+ {% include "authens/form_full_snippet.html" with submit_text="Se connecter" %} +
{% endblock %} diff --git a/authens/templates/authens/pwd_reset_confirm.html b/authens/templates/authens/pwd_reset_confirm.html index 98903ce..3e79bd9 100644 --- a/authens/templates/authens/pwd_reset_confirm.html +++ b/authens/templates/authens/pwd_reset_confirm.html @@ -6,5 +6,7 @@ {% endblock %} {% block content %} - {% include "authens/form_full_snippet.html" with form_class="exte" submit_text="Enregistrer" %} +
+ {% include "authens/form_full_snippet.html" with submit_text="Enregistrer" %} +
{% endblock %} From e1199cae2020502325c38b58508d16ff09c44de7 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 17:46:15 +0200 Subject: [PATCH 07/12] Pwd reset link --- authens/static/authens/css/authens.css | 6 ++++++ authens/templates/authens/pwd_login.html | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/authens/static/authens/css/authens.css b/authens/static/authens/css/authens.css index 1b2a180..f8036c1 100644 --- a/authens/static/authens/css/authens.css +++ b/authens/static/authens/css/authens.css @@ -51,10 +51,16 @@ html, body { .auth_form { + width: 100%; padding: 0.5em; font-size: 1.5em; } +.forgot-pwd { + width:100%; + padding: 0.5em 0px 1em; +} + .error { background: red; color: white; diff --git a/authens/templates/authens/pwd_login.html b/authens/templates/authens/pwd_login.html index 41e582f..5f48f78 100644 --- a/authens/templates/authens/pwd_login.html +++ b/authens/templates/authens/pwd_login.html @@ -8,5 +8,9 @@ {% block content %}
{% include "authens/form_full_snippet.html" with submit_text="Se connecter" %} + +
{% endblock %} From d0e16ec9b4f1ee5857e3f7d292b74feea462e9c7 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 17:57:51 +0200 Subject: [PATCH 08/12] CSS file rework --- authens/static/authens/css/authens.css | 72 +++++++++++++++++--------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/authens/static/authens/css/authens.css b/authens/static/authens/css/authens.css index f8036c1..762f487 100644 --- a/authens/static/authens/css/authens.css +++ b/authens/static/authens/css/authens.css @@ -1,3 +1,7 @@ +/* + Generic page layout +*/ + html, body { width: 100%; background: #eee; @@ -33,6 +37,10 @@ html, body { flex-flow: row wrap; } +/* + Background color definitions +*/ + .cas { background: #4D85BD; color: white; @@ -48,19 +56,29 @@ html, body { color: white; } +/* + Login switch layout +*/ - -.auth_form { - width: 100%; - padding: 0.5em; - font-size: 1.5em; +.big-button { + flex: 1; + height: 200px; + min-width: 300px; + text-align: center; + font-size: 2.5em; + color: white; + line-height: 200px; + text-decoration: none; } -.forgot-pwd { - width:100%; - padding: 0.5em 0px 1em; +.big-button :hover { + text-decoration: underline; } +/* + Message styling +*/ + .error { background: red; color: white; @@ -81,10 +99,14 @@ html, body { text-align: center; } -ul.errorlist { - text-align: left; - font-size: 0.8em; - padding-left: 20px; +/* + Form styling +*/ + +.auth_form { + width: 100%; + padding: 0.5em; + font-size: 1.5em; } .auth_form table { @@ -92,12 +114,18 @@ ul.errorlist { border-spacing: 0.3em; } -th { +.auth_form th { padding: 5px 0; vertical-align: text-top; text-align: right; } +ul.errorlist { + text-align: left; + font-size: 0.8em; + padding-left: 20px; +} + input { font-size: 1em; } @@ -132,17 +160,11 @@ select { text-align: end; } -.big-button { - flex: 1; - height: 200px; - min-width: 300px; - text-align: center; - font-size: 2.5em; - color: white; - line-height: 200px; - text-decoration: none; -} +/* + Misc +*/ -.big-button :hover { - text-decoration: underline; +.forgot-pwd { + width:100%; + padding: 0.5em 0px 1em; } From 871c63f2bb003bc30d21f963bc8d892bbbfca4aa Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 26 Jun 2020 17:59:30 +0200 Subject: [PATCH 09/12] Remove useless file --- authens/templates/authens/auth_form_field.html | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 authens/templates/authens/auth_form_field.html diff --git a/authens/templates/authens/auth_form_field.html b/authens/templates/authens/auth_form_field.html deleted file mode 100644 index ff8fdfb..0000000 --- a/authens/templates/authens/auth_form_field.html +++ /dev/null @@ -1,4 +0,0 @@ - - {{ field.label_tag }} - {{ field }} - \ No newline at end of file From 5295431e681d9a61fc44fd606a2781f6b06f76da Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 30 Jun 2020 12:59:29 +0200 Subject: [PATCH 10/12] Fix padding overflow --- authens/static/authens/css/authens.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authens/static/authens/css/authens.css b/authens/static/authens/css/authens.css index 762f487..bfa6bfc 100644 --- a/authens/static/authens/css/authens.css +++ b/authens/static/authens/css/authens.css @@ -83,7 +83,7 @@ html, body { background: red; color: white; width: 100%; - padding: 0.5em; + padding: 0.5em 0; margin: 0; font-size: 1.2em; text-align: center; @@ -93,7 +93,7 @@ html, body { background: green; color: white; width: 100%; - padding: 0.5em; + padding: 0.5em 0; margin: 0; font-size: 1.2em; text-align: center; From 17bcbedf3099b128ae4df8f5ee079215ce29bc6e Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 30 Jun 2020 15:53:48 +0200 Subject: [PATCH 11/12] Better naming convention --- .../templates/authens/{old_cas_login.html => oldcas_login.html} | 0 authens/views.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename authens/templates/authens/{old_cas_login.html => oldcas_login.html} (100%) diff --git a/authens/templates/authens/old_cas_login.html b/authens/templates/authens/oldcas_login.html similarity index 100% rename from authens/templates/authens/old_cas_login.html rename to authens/templates/authens/oldcas_login.html diff --git a/authens/views.py b/authens/views.py index 60aaf9a..c1d4f66 100644 --- a/authens/views.py +++ b/authens/views.py @@ -104,7 +104,7 @@ class PasswordResetConfirmView( class OldCASLoginView(auth_views.LoginView): - template_name = "authens/old_cas_login.html" + template_name = "authens/oldcas_login.html" authentication_form = OldCASAuthForm def get_initial(self): From dd6249d40e448c55e47f0e6430997081d3e941f8 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 4 Jul 2020 18:25:57 +0200 Subject: [PATCH 12/12] CSS tweaks --- authens/static/authens/css/authens.css | 11 ++++++++--- authens/templates/authens/pwd_reset.html | 2 +- authens/templates/authens/pwd_reset_email.txt | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/authens/static/authens/css/authens.css b/authens/static/authens/css/authens.css index bfa6bfc..b2c1d14 100644 --- a/authens/static/authens/css/authens.css +++ b/authens/static/authens/css/authens.css @@ -47,7 +47,7 @@ html, body { } .exte { - background: #749F2A; + background: #598507; color: white; } @@ -115,7 +115,7 @@ html, body { } .auth_form th { - padding: 5px 0; + padding: 10px 0; vertical-align: text-top; text-align: right; } @@ -130,7 +130,7 @@ input { font-size: 1em; } -input[type="text"], input[type="password"] { +input[type="text"], input[type="password"], input[type="email"] { border: 0; padding: 5px; width: 100%; @@ -167,4 +167,9 @@ select { .forgot-pwd { width:100%; padding: 0.5em 0px 1em; + font-size: 1.2em; +} + +.forgot-pwd > a { + color: white; } diff --git a/authens/templates/authens/pwd_reset.html b/authens/templates/authens/pwd_reset.html index 393611c..ebb521e 100644 --- a/authens/templates/authens/pwd_reset.html +++ b/authens/templates/authens/pwd_reset.html @@ -7,6 +7,6 @@ {% block content %}
- {% include "authens/form_full_snippet.html" with submit_text="Se connecter" %} + {% include "authens/form_full_snippet.html" with submit_text="Envoyer un mail" %}
{% endblock %} diff --git a/authens/templates/authens/pwd_reset_email.txt b/authens/templates/authens/pwd_reset_email.txt index a0ed323..9071193 100644 --- a/authens/templates/authens/pwd_reset_email.txt +++ b/authens/templates/authens/pwd_reset_email.txt @@ -5,7 +5,7 @@ {% block reset_link %} {{ protocol }}://{{ domain }}{% url "authens:reset.pwd.confirm" uidb64=uid token=token %} {% endblock %} -{% blocktrans with username=user.get_username %}Au cas où, votre nom d'utilisateur est le suivant : {{ username }}{% endblocktrans %} +{% blocktrans with username=user.get_username %}Pour information, votre nom d'utilisateur est le suivant : {{ username }}{% endblocktrans %} {% block signature %}{% blocktrans %}L'équipe {{site_name}}{% endblocktrans %}{% endblock %}