Add account deletion functionality with confirmation dialog and routing
This commit is contained in:
parent
cd0ca2f5ea
commit
8faff47696
6 changed files with 46 additions and 13 deletions
25
base/templates/auth/user_confirm_delete.html
Normal file
25
base/templates/auth/user_confirm_delete.html
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<dialog open>
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<p>
|
||||||
|
<i class="ri-user-fill"></i> {{ user.username }}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
<p>
|
||||||
|
Confirmer la supression du compte <strong>{{ user.username }}</strong> ?
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<small>Toute suppression est immédiate et définitive. La suppression du compte entraîne la suppression des groupes dont celui-ci est propriétaire.</small>
|
||||||
|
</p>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit">
|
||||||
|
<i class="ri-delete-bin-fill"></i> Confirmer
|
||||||
|
</button>
|
||||||
|
<a href="{% url "account_settings" %}" role="button" class="secondary"><i class="ri-close-line"></i> Annuler</a>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
</dialog>
|
||||||
|
{% endblock content %}
|
|
@ -7,6 +7,11 @@
|
||||||
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
||||||
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
<fieldset>
|
||||||
|
<button type="submit" formaction="{% url "logout" %}" class="secondary">
|
||||||
|
<i class="ri-logout-box-r-fill"></i> Me déconnecter
|
||||||
|
</button>
|
||||||
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
{% if not user.youtubecredentials.credentials %}
|
{% if not user.youtubecredentials.credentials %}
|
||||||
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
||||||
|
@ -33,5 +38,8 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<a href="{% url "password_change" %}" role="button" class="secondary">Changer mon mot de passe</a>
|
<a href="{% url "password_change" %}" role="button" class="secondary">Changer mon mot de passe</a>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<a href="{% url "account_delete" %}" role="button" class="contrast">Supprimer mon compte</a>
|
||||||
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
|
@ -48,17 +48,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url "account_settings" %}">{{ user.username }}</a>
|
<a href="{% url "account_settings" %}"><i class="ri-user-fill" alt="Compte"></i> {{ user.username }}</a>
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<form action="{% url 'logout' %}" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="submit" value="Se déconnecter" class="logout">
|
|
||||||
</form>
|
|
||||||
</li>
|
|
||||||
{% else %}
|
|
||||||
<li>
|
|
||||||
<a href="{% url 'login' %}" role="button">Se connecter <i class="ri-login-box-fill"></i></a>
|
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -25,5 +25,6 @@ urlpatterns = [
|
||||||
name="password_reset_confirm",
|
name="password_reset_confirm",
|
||||||
),
|
),
|
||||||
path("accounts/settings/", views.AccountView.as_view(), name="account_settings"),
|
path("accounts/settings/", views.AccountView.as_view(), name="account_settings"),
|
||||||
|
path("accounts/delete/", views.AccountDeleteView.as_view(), name="account_delete"),
|
||||||
path("legal/", TemplateView.as_view(template_name="privacy.html"), name="legal"),
|
path("legal/", TemplateView.as_view(template_name="privacy.html"), name="legal"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,7 +4,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from django.views.generic.edit import CreateView, UpdateView
|
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||||
|
|
||||||
from . import forms
|
from . import forms
|
||||||
|
|
||||||
|
@ -52,3 +52,13 @@ class AccountView(UpdateView):
|
||||||
if queryset is None:
|
if queryset is None:
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
return queryset.get(pk=self.request.user.pk)
|
return queryset.get(pk=self.request.user.pk)
|
||||||
|
|
||||||
|
|
||||||
|
class AccountDeleteView(DeleteView):
|
||||||
|
model = User
|
||||||
|
success_url = reverse_lazy("index")
|
||||||
|
|
||||||
|
def get_object(self, queryset=None):
|
||||||
|
if queryset is None:
|
||||||
|
queryset = self.get_queryset()
|
||||||
|
return queryset.get(pk=self.request.user.pk)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load form %}
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<dialog open>
|
<dialog open>
|
||||||
<article>
|
<article>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue