From da1c7507710cc77a60029ff101b40bcea4fb28e4 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 15 Jun 2025 11:02:35 +0200 Subject: [PATCH] Add password change and reset functionality with corresponding views and templates --- .../registration/password_change_form.html | 8 +++++++ .../registration/password_reset_confirm.html | 8 +++++++ .../registration/password_reset_form.html | 8 +++++++ base/urls.py | 21 +++++++++++++++++-- base/views.py | 18 ++++++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 base/templates/registration/password_change_form.html create mode 100644 base/templates/registration/password_reset_confirm.html create mode 100644 base/templates/registration/password_reset_form.html diff --git a/base/templates/registration/password_change_form.html b/base/templates/registration/password_change_form.html new file mode 100644 index 0000000..25304fe --- /dev/null +++ b/base/templates/registration/password_change_form.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% load form %} +{% block content %} +

+ Changer mon mot de passe +

+ {% form form submit="Changer mon mot de passe" %} + {% endblock content %} diff --git a/base/templates/registration/password_reset_confirm.html b/base/templates/registration/password_reset_confirm.html new file mode 100644 index 0000000..2f7f317 --- /dev/null +++ b/base/templates/registration/password_reset_confirm.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% load form %} +{% block content %} +

+ Réinitialiser mon mot de passe +

+ {% form form submit="Réinitialiser mon mot de passe" %} + {% endblock content %} diff --git a/base/templates/registration/password_reset_form.html b/base/templates/registration/password_reset_form.html new file mode 100644 index 0000000..2f7f317 --- /dev/null +++ b/base/templates/registration/password_reset_form.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% load form %} +{% block content %} +

+ Réinitialiser mon mot de passe +

+ {% form form submit="Réinitialiser mon mot de passe" %} + {% endblock content %} diff --git a/base/urls.py b/base/urls.py index ea1f6ba..6723389 100644 --- a/base/urls.py +++ b/base/urls.py @@ -1,4 +1,5 @@ -from django.urls import include, path +from django.contrib.auth import views as auth_views +from django.urls import path from django.views.generic import TemplateView from . import views @@ -6,6 +7,22 @@ from . import views urlpatterns = [ path("", views.HomePageView.as_view(), name="index"), path("accounts/signup/", views.SignupView.as_view(), name="signup"), - path("accounts/", include("django.contrib.auth.urls")), + path("accounts/login/", auth_views.LoginView.as_view(), name="login"), + path("accounts/logout/", auth_views.LogoutView.as_view(), name="logout"), + path( + "accounts/password_change/", + views.PasswordChangeView.as_view(), + name="password_change", + ), + path( + "accounts/password_reset/", + views.PasswordResetView.as_view(), + name="password_reset", + ), + path( + "accounts/reset///", + views.PasswordResetConfirmView.as_view(), + name="password_reset_confirm", + ), path("legal/", TemplateView.as_view(template_name="privacy.html"), name="legal"), ] diff --git a/base/views.py b/base/views.py index 32dd5bb..26f9163 100644 --- a/base/views.py +++ b/base/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth import views as auth_views from django.contrib.auth.models import User from django.contrib.messages.views import SuccessMessageMixin from django.shortcuts import redirect @@ -22,3 +23,20 @@ class SignupView(SuccessMessageMixin, CreateView): form_class = forms.UserSignupForm success_url = reverse_lazy("login") success_message = "Le compte %(username)s a été créé avec succès." + + +class PasswordChangeView(SuccessMessageMixin, auth_views.PasswordChangeView): + success_message = "Le mot de passe a été changé avec succès." + success_url = reverse_lazy("index") + + +class PasswordResetView(SuccessMessageMixin, auth_views.PasswordResetView): + success_message = "Un courriel a été envoyé avec les instructions pour réinitialiser votre mot de passe." + success_url = reverse_lazy("login") + + +class PasswordResetConfirmView( + SuccessMessageMixin, auth_views.PasswordResetConfirmView +): + success_message = "Le mot de passe a été réinitialisé avec succès." + success_url = reverse_lazy("login")