Add account settings page with YouTube connection management and user update functionality
This commit is contained in:
parent
da1c750771
commit
cd0ca2f5ea
7 changed files with 62 additions and 8 deletions
37
base/templates/auth/user_settings.html
Normal file
37
base/templates/auth/user_settings.html
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load form %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>
|
||||||
|
<i class="ri-user-settings-fill"></i> Mon compte
|
||||||
|
</h1>
|
||||||
|
{% for error in form.non_field_errors %}<article class="message error">{{ error }}</article>{% endfor %}
|
||||||
|
<form method="post" {% if action %}action="{% url action %}"{% endif %}>
|
||||||
|
{% csrf_token %}
|
||||||
|
<fieldset>
|
||||||
|
{% if not user.youtubecredentials.credentials %}
|
||||||
|
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
||||||
|
{% else %}
|
||||||
|
<button type="submit"
|
||||||
|
formaction="{% url "youtube_logout" %}"
|
||||||
|
class="secondary">
|
||||||
|
<i class="ri-youtube-fill"></i> Déconnecter le compte Youtube <strong>{{ user.youtubecredentials.title }}</strong>
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
{% for field in form %}
|
||||||
|
<label for="{{ field.id_for_label }}">
|
||||||
|
{{ field.label }}
|
||||||
|
{{ field }}
|
||||||
|
{% if field.errors %}
|
||||||
|
<small id="{{ field.errors.field_id }}_error" class="form-error">{{ field.errors|join:", " }}</small>
|
||||||
|
{% endif %}
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
<button type="submit">Mettre à jour mon compte</button>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<a href="{% url "password_change" %}" role="button" class="secondary">Changer mon mot de passe</a>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
|
@ -47,7 +47,9 @@
|
||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li>{{ user.username }}</li>
|
<li>
|
||||||
|
<a href="{% url "account_settings" %}">{{ user.username }}</a>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<form action="{% url 'logout' %}" method="post">
|
<form action="{% url 'logout' %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -24,5 +24,6 @@ urlpatterns = [
|
||||||
views.PasswordResetConfirmView.as_view(),
|
views.PasswordResetConfirmView.as_view(),
|
||||||
name="password_reset_confirm",
|
name="password_reset_confirm",
|
||||||
),
|
),
|
||||||
|
path("accounts/settings/", views.AccountView.as_view(), name="account_settings"),
|
||||||
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
|
from django.views.generic.edit import CreateView, UpdateView
|
||||||
|
|
||||||
from . import forms
|
from . import forms
|
||||||
|
|
||||||
|
@ -40,3 +40,15 @@ class PasswordResetConfirmView(
|
||||||
):
|
):
|
||||||
success_message = "Le mot de passe a été réinitialisé avec succès."
|
success_message = "Le mot de passe a été réinitialisé avec succès."
|
||||||
success_url = reverse_lazy("login")
|
success_url = reverse_lazy("login")
|
||||||
|
|
||||||
|
|
||||||
|
class AccountView(UpdateView):
|
||||||
|
model = User
|
||||||
|
fields = ["username", "email"]
|
||||||
|
success_url = reverse_lazy("index")
|
||||||
|
template_name = "auth/user_settings.html"
|
||||||
|
|
||||||
|
def get_object(self, queryset=None):
|
||||||
|
if queryset is None:
|
||||||
|
queryset = self.get_queryset()
|
||||||
|
return queryset.get(pk=self.request.user.pk)
|
||||||
|
|
|
@ -4,13 +4,8 @@
|
||||||
<h1>
|
<h1>
|
||||||
<i class="ri-music-ai-fill"></i> Musik
|
<i class="ri-music-ai-fill"></i> Musik
|
||||||
</h1>
|
</h1>
|
||||||
<p>Bienvenue {{ user.username }} !</p>
|
|
||||||
<p>
|
<p>
|
||||||
{% if not user.youtubecredentials.credentials %}
|
Bienvenue <strong>{{ user.username }}</strong> !
|
||||||
<a href="{% url "youtube_login" %}" role="button"><i class="ri-youtube-fill"></i> Me connecter au compte Youtube</a>
|
|
||||||
{% else %}
|
|
||||||
<i class="ri-youtube-fill"></i> Connecté au compte Youtube <strong>{{ user.youtubecredentials.title }}</strong>.
|
|
||||||
{% endif %}
|
|
||||||
</p>
|
</p>
|
||||||
<h2>
|
<h2>
|
||||||
<i class="ri-group-2-fill"></i> Mes groupes
|
<i class="ri-group-2-fill"></i> Mes groupes
|
||||||
|
|
|
@ -52,6 +52,7 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
path("group/game/<int:pk>/", views.GameDetailView.as_view(), name="game_detail"),
|
path("group/game/<int:pk>/", views.GameDetailView.as_view(), name="game_detail"),
|
||||||
path("youtube_login/", views.YoutubeLoginView.as_view(), name="youtube_login"),
|
path("youtube_login/", views.YoutubeLoginView.as_view(), name="youtube_login"),
|
||||||
|
path("youtube_logout/", views.YoutubeLogoutView.as_view(), name="youtube_logout"),
|
||||||
path(
|
path(
|
||||||
"youtube_callback/",
|
"youtube_callback/",
|
||||||
views.YoutubeCallbackView.as_view(),
|
views.YoutubeCallbackView.as_view(),
|
||||||
|
|
|
@ -405,6 +405,12 @@ class YoutubeLoginView(LoginRequiredMixin, View):
|
||||||
return redirect(auth_url)
|
return redirect(auth_url)
|
||||||
|
|
||||||
|
|
||||||
|
class YoutubeLogoutView(LoginRequiredMixin, View):
|
||||||
|
def post(self, request):
|
||||||
|
request.user.youtubecredentials.delete()
|
||||||
|
return redirect("account_settings")
|
||||||
|
|
||||||
|
|
||||||
class GroupClearBlacklistView(MemberFilterMixin, SingleObjectMixin, View):
|
class GroupClearBlacklistView(MemberFilterMixin, SingleObjectMixin, View):
|
||||||
model = models.Group
|
model = models.Group
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue