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>
|
||||
<ul>
|
||||
{% if user.is_authenticated %}
|
||||
<li>{{ user.username }}</li>
|
||||
<li>
|
||||
<a href="{% url "account_settings" %}">{{ user.username }}</a>
|
||||
</li>
|
||||
<li>
|
||||
<form action="{% url 'logout' %}" method="post">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -24,5 +24,6 @@ urlpatterns = [
|
|||
views.PasswordResetConfirmView.as_view(),
|
||||
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"),
|
||||
]
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
|||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
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
|
||||
|
||||
|
@ -40,3 +40,15 @@ class PasswordResetConfirmView(
|
|||
):
|
||||
success_message = "Le mot de passe a été réinitialisé avec succès."
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue