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")