From 0d838cafeed62769b2cc97ee6a2e5e31d5ff03b9 Mon Sep 17 00:00:00 2001 From: Guillaume Bertholon Date: Sun, 20 Dec 2020 01:10:02 +0100 Subject: [PATCH] Add public name customization and small style adjustments --- gestiojeux/settings_base.py | 2 + gestiojeux_auth/forms.py | 24 +++++++ .../registration/account_settings.html | 20 ++++++ .../registration/change_password.html | 12 ++++ .../templates/registration/login.html | 2 +- gestiojeux_auth/urls.py | 4 +- gestiojeux_auth/views.py | 28 ++++++++ inventory/templates/inventory/category.html | 10 ++- .../templates/inventory/category_list.html | 10 ++- inventory/templates/inventory/game.html | 32 +++++---- inventory/templates/inventory/game_list.html | 10 ++- inventory/templates/inventory/inventory.html | 1 - inventory/templates/inventory/search.html | 6 +- inventory/templates/inventory/tag.html | 10 ++- inventory/templates/inventory/tag_list.html | 10 ++- mainsite/scss/forms.scss | 20 +++++- mainsite/scss/style.scss | 64 ++--------------- mainsite/static/css/style.css | 70 ++++++------------- mainsite/templates/partials/header.html | 2 +- mainsite/templates/partials/user.html | 1 + 20 files changed, 176 insertions(+), 162 deletions(-) create mode 100644 gestiojeux_auth/forms.py create mode 100644 gestiojeux_auth/templates/registration/account_settings.html create mode 100644 gestiojeux_auth/templates/registration/change_password.html create mode 100644 mainsite/templates/partials/user.html diff --git a/gestiojeux/settings_base.py b/gestiojeux/settings_base.py index b9b2420..df8a4ea 100644 --- a/gestiojeux/settings_base.py +++ b/gestiojeux/settings_base.py @@ -81,6 +81,8 @@ AUTH_PASSWORD_VALIDATORS = [ {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"}, ] +LOGIN_URL = "gestiojeux_auth:login" + # Use markdown extensions MARKDOWNX_MARKDOWN_EXTENSIONS = [ "markdown.extensions.extra", diff --git a/gestiojeux_auth/forms.py b/gestiojeux_auth/forms.py new file mode 100644 index 0000000..7736cf8 --- /dev/null +++ b/gestiojeux_auth/forms.py @@ -0,0 +1,24 @@ +from django.forms import ModelForm, ValidationError +from django.contrib.auth.models import User + + +class AccountSettingsForm(ModelForm): + class Meta: + model = User + fields = ["first_name"] + labels = {"first_name": "Nom ou pseudo"} + help_texts = { + "first_name": "Ce nom sera utilisé pour toutes vos interactions publiques sur GestioJeux. Si laissé vide, votre login sera utilisé à la place." + } + + def clean_first_name(self): + """ Check there is no conflict that could lead to imprersonation """ + public_name = self.cleaned_data["first_name"] + public_name = public_name.strip() + if public_name == self.instance.first_name or public_name == "": + return public_name + if User.objects.filter(first_name=public_name).count() > 0: + raise ValidationError("Un autre compte utilise déjà ce nom ou ce pseudo.") + if User.objects.filter(username=public_name).count() > 0: + raise ValidationError("Ce nom est déjà le login de quelqu'un.") + return public_name diff --git a/gestiojeux_auth/templates/registration/account_settings.html b/gestiojeux_auth/templates/registration/account_settings.html new file mode 100644 index 0000000..26fd23f --- /dev/null +++ b/gestiojeux_auth/templates/registration/account_settings.html @@ -0,0 +1,20 @@ +{% extends "small_page.html" %} + +{% block "content" %} +

Paramètres du compte

+ +

Vous êtes connecté en tant que {{ request.user.username }}

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% if request.user.password and request.user.has_usable_password %} +
+ +Changer mon mot de passe +{% endif %} +{% endblock %} + diff --git a/gestiojeux_auth/templates/registration/change_password.html b/gestiojeux_auth/templates/registration/change_password.html new file mode 100644 index 0000000..1639e8d --- /dev/null +++ b/gestiojeux_auth/templates/registration/change_password.html @@ -0,0 +1,12 @@ +{% extends "small_page.html" %} + +{% block "content" %} +

Changement de mot de passe

+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} + diff --git a/gestiojeux_auth/templates/registration/login.html b/gestiojeux_auth/templates/registration/login.html index 3028df1..b55ff9e 100644 --- a/gestiojeux_auth/templates/registration/login.html +++ b/gestiojeux_auth/templates/registration/login.html @@ -3,7 +3,7 @@ {% block "content" %}

Connexion par mot de passe

-
+ {% csrf_token %} {{ form.as_p }} diff --git a/gestiojeux_auth/urls.py b/gestiojeux_auth/urls.py index eeb00a6..9e61b88 100644 --- a/gestiojeux_auth/urls.py +++ b/gestiojeux_auth/urls.py @@ -1,6 +1,6 @@ from django.urls import include, path import django.contrib.auth.views as dj_auth_views -from .views import LoginView, LogoutView +from .views import LoginView, LogoutView, PasswordChangeView, AccountSettingsView import django_cas_ng.views app_name = "gestiojeux_auth" @@ -20,6 +20,8 @@ accounts_patterns = [ path("login/", LoginView.as_view(), name="login"), path("logout/", LogoutView.as_view(), name="logout"), path("password_login/", dj_auth_views.LoginView.as_view(), name="password_login"), + path("change_password/", PasswordChangeView.as_view(), name="change_password"), + path("account_settings/", AccountSettingsView.as_view(), name="account_settings"), ] urlpatterns = [ diff --git a/gestiojeux_auth/views.py b/gestiojeux_auth/views.py index 6d8869d..a74102b 100644 --- a/gestiojeux_auth/views.py +++ b/gestiojeux_auth/views.py @@ -1,13 +1,18 @@ from django.views.generic import TemplateView, RedirectView +from django.views.generic.edit import UpdateView from django.shortcuts import redirect from django.urls import reverse from django.dispatch import receiver from django.contrib.auth import logout as auth_logout from django.contrib.auth import user_logged_in, user_logged_out, user_login_failed +from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth.views import PasswordChangeView from django.contrib import messages from urllib.parse import quote as urlquote +from .forms import AccountSettingsForm + class LoginView(TemplateView): template_name = "registration/login_switch.html" @@ -81,3 +86,26 @@ def on_logout(request, **kwargs): @receiver(user_login_failed) def on_login_failed(request, **kwargs): messages.error(request, "Connexion échouée.") + + +class PasswordChangeView(PasswordChangeView): + template_name = "registration/change_password.html" + + def get_success_url(self): + messages.info(self.request, "Mot de passe mis à jour") + return reverse("gestiojeux_auth:account_settings") + + +class AccountSettingsView(LoginRequiredMixin, UpdateView): + template_name = "registration/account_settings.html" + form_class = AccountSettingsForm + + def get_object(self): + return self.request.user + + def get_success_url(self): + return self.request.get_full_path() + + def form_valid(self, form): + messages.success(self.request, "Paramètres du compte mis à jour") + return super().form_valid(form) diff --git a/inventory/templates/inventory/category.html b/inventory/templates/inventory/category.html index c03e254..30301c0 100644 --- a/inventory/templates/inventory/category.html +++ b/inventory/templates/inventory/category.html @@ -4,11 +4,9 @@

{{ category.name }}

{% with game_list=category.game_set.all %} - Il y a {{ game_list|length }} jeu{{ game_list|pluralize:"x" }} dans cette catégorie : - +

Il y a {{ game_list|length }} jeu{{ game_list|pluralize:"x" }} dans cette catégorie :

+ {% for game in game_list %} + {% include "./partials/game_item.html" %} + {% endfor %} {% endwith %} {% endblock %} diff --git a/inventory/templates/inventory/category_list.html b/inventory/templates/inventory/category_list.html index 1af544f..427ba04 100644 --- a/inventory/templates/inventory/category_list.html +++ b/inventory/templates/inventory/category_list.html @@ -3,10 +3,8 @@ {% block "content" %}

Liste des catégories

- Il y a {{ category_list|length }} catégorie{{ category_list|pluralize }} de jeux : - +

Il y a {{ category_list|length }} catégorie{{ category_list|pluralize }} de jeux :

+ {% for category in category_list %} + {% include "./partials/category_item.html" %} + {% endfor %} {% endblock %} diff --git a/inventory/templates/inventory/game.html b/inventory/templates/inventory/game.html index 8ec94b4..e65502e 100644 --- a/inventory/templates/inventory/game.html +++ b/inventory/templates/inventory/game.html @@ -38,32 +38,34 @@ {% endif %}

Commentaires et propositions de variantes

-
{% if not edited_comment %} {% if request.user.is_authenticated %}
diff --git a/inventory/templates/inventory/game_list.html b/inventory/templates/inventory/game_list.html index cd18633..7f2e2ca 100644 --- a/inventory/templates/inventory/game_list.html +++ b/inventory/templates/inventory/game_list.html @@ -3,10 +3,8 @@ {% block "content" %}

Liste des jeux

- Il y a {{ game_list|length }} jeu{{ game_list|pluralize:"x" }} en salle jeux : - +

Il y a {{ game_list|length }} jeu{{ game_list|pluralize:"x" }} en salle jeux :

+ {% for game in game_list %} + {% include "./partials/game_item.html" %} + {% endfor %} {% endblock %} diff --git a/inventory/templates/inventory/inventory.html b/inventory/templates/inventory/inventory.html index c69e1a0..02e2e9a 100644 --- a/inventory/templates/inventory/inventory.html +++ b/inventory/templates/inventory/inventory.html @@ -12,7 +12,6 @@
- Liste des catégories

diff --git a/inventory/templates/inventory/search.html b/inventory/templates/inventory/search.html index 5c6d96d..5ef8d3d 100644 --- a/inventory/templates/inventory/search.html +++ b/inventory/templates/inventory/search.html @@ -10,9 +10,7 @@ {% if query %}


-
    {% for result in page_obj.object_list %} -
  • {% if result.model_name == "game" %} {% include "./partials/game_item.html" with game=result.object %} {% elif result.model_name == "category" %} @@ -20,11 +18,9 @@ {% elif result.model_name == "tag" %} {% include "./partials/tag_item.html" with tag=result.object %} {% endif %} -
  • {% empty %} -
  • Aucun résultat trouvé
  • + Aucun résultat trouvé {% endfor %} -
{% include "./partials/pagination.html" %} {% endif %} diff --git a/inventory/templates/inventory/tag.html b/inventory/templates/inventory/tag.html index 62d492c..449f149 100644 --- a/inventory/templates/inventory/tag.html +++ b/inventory/templates/inventory/tag.html @@ -4,11 +4,9 @@

{{ tag.name }}

{% with game_list=tag.game_set.all %} - Il y a {{ game_list|length }} jeu{{ game_list|pluralize:"x" }} marqué{{ game_list|pluralize }} avec ce tag : -
    - {% for game in game_list %} -
  • {% include "./partials/game_item.html" %}
  • - {% endfor %} -
+

Il y a {{ game_list|length }} jeu{{ game_list|pluralize:"x" }} marqué{{ game_list|pluralize }} avec ce tag :

+ {% for game in game_list %} + {% include "./partials/game_item.html" %} + {% endfor %} {% endwith %} {% endblock %} diff --git a/inventory/templates/inventory/tag_list.html b/inventory/templates/inventory/tag_list.html index e7646f5..df0c05a 100644 --- a/inventory/templates/inventory/tag_list.html +++ b/inventory/templates/inventory/tag_list.html @@ -3,10 +3,8 @@ {% block "content" %}

Liste des tags

- Il y a {{ tag_list|length }} tag{{ tag_list|pluralize }} dans la ludothèque : -
    - {% for tag in tag_list %} -
  • {% include "./partials/tag_item.html" %}
  • - {% endfor %} -
+

Il y a {{ tag_list|length }} tag{{ tag_list|pluralize }} dans la ludothèque :

+ {% for tag in tag_list %} + {% include "./partials/tag_item.html" %} + {% endfor %} {% endblock %} diff --git a/mainsite/scss/forms.scss b/mainsite/scss/forms.scss index 67093db..642bfa0 100644 --- a/mainsite/scss/forms.scss +++ b/mainsite/scss/forms.scss @@ -22,6 +22,7 @@ form { } .helptext { + display: block; font-size: 0.7em; color: $help_text_color; } @@ -120,7 +121,9 @@ form.search { } form.comment { - font-size: 0.7em; + padding: 0; + border: none; + textarea { border-radius: 10px 10px 0 0; border-bottom: none; @@ -130,4 +133,19 @@ form.comment { border-radius: 0 0 10px 10px; margin: 0; } + +} + +form#edited_comment { + .meta { + padding: 10px; + padding-bottom: 5px; + border-radius: 10px 10px 0 0; + border: 1px solid $indexbar_bg_color_1; + border-bottom: none; + } + + textarea { + border-radius: 0; + } } diff --git a/mainsite/scss/style.scss b/mainsite/scss/style.scss index 88d265e..e49d915 100644 --- a/mainsite/scss/style.scss +++ b/mainsite/scss/style.scss @@ -55,15 +55,6 @@ footer { padding: 10px; } -.help_bubble { - @media (min-width: 700px) { - font-size: 0.7em; - position: relative; - bottom: 0.3ex; - left: 0.2ex; - } -} - h1 { font-size: 1.5em; font-weight: bold; @@ -107,6 +98,11 @@ hr { margin: 30px 60px; } +ul, ol { + padding: 0; + list-style-position: inside; +} + .btn_row { display: flex; align-items: stretch; @@ -139,49 +135,6 @@ button, .btn_row a { .warning { @include warning_box; } .success { @include success_box; } -.tooltip { - position: relative; - display: inline-block; - opacity: 0.75; - border-radius: 3px; - - .tooltiptext { - visibility: hidden; - display: block; - background-color: black; - color: rgba(white, 0.80); - text-align: justify; - padding: 10px; - border-radius: 6px; - font-size: 0.8em; - width: 250px; - - @media (max-width: 400px) { - width: 150px; - position: absolute; - left: -75px; - } - - /* Position the tooltip text - see examples below! */ - position: absolute; - left: -75px; - z-index: 1; - - ul { - margin: 0; - padding-left: 15px; - color: inherit; - } - } - - &:hover, &:focus { - opacity: 1; - .tooltiptext { - visibility: visible; - } - } -} - .antispam { unicode-bidi: bidi-override; direction: rtl; @@ -286,11 +239,6 @@ iframe { } } -ul { - padding: 0; - list-style-type: none; -} - a.inventory_item { display: block; padding: 15px; @@ -326,7 +274,7 @@ a.inventory_item { } } -li.comment { +.comment { @include box(white, $indexbar_bg_color_1); margin: 1em 0; font-size: 0.7em; diff --git a/mainsite/static/css/style.css b/mainsite/static/css/style.css index cc2606c..52bd2c0 100644 --- a/mainsite/static/css/style.css +++ b/mainsite/static/css/style.css @@ -57,6 +57,7 @@ form { width: 100%; } .helptext { + display: block; font-size: 0.7em; color: rgba(37, 15, 45, 0.65); } @@ -173,7 +174,8 @@ form.search { border-radius: 0 10px 10px 0; } form.comment { - font-size: 0.7em; } + padding: 0; + border: none; } form.comment textarea { border-radius: 10px 10px 0 0; border-bottom: none; @@ -182,6 +184,16 @@ form.comment { border-radius: 0 0 10px 10px; margin: 0; } +form#edited_comment .meta { + padding: 10px; + padding-bottom: 5px; + border-radius: 10px 10px 0 0; + border: 1px solid rgba(107, 184, 196, 0.75); + border-bottom: none; } + +form#edited_comment textarea { + border-radius: 0; } + html { box-sizing: border-box; } @@ -221,13 +233,6 @@ footer { text-align: center; padding: 10px; } -@media (min-width: 700px) { - .help_bubble { - font-size: 0.7em; - position: relative; - bottom: 0.3ex; - left: 0.2ex; } } - h1 { font-size: 1.5em; font-weight: bold; } @@ -262,6 +267,10 @@ hr { border: 1px solid #c9dbe0; margin: 30px 60px; } +ul, ol { + padding: 0; + list-style-position: inside; } + .btn_row { display: flex; align-items: stretch; @@ -319,39 +328,6 @@ button, .btn_row a { border: 1px solid #84ff72; background-color: #ddffd8; } -.tooltip { - position: relative; - display: inline-block; - opacity: 0.75; - border-radius: 3px; } - .tooltip .tooltiptext { - visibility: hidden; - display: block; - background-color: black; - color: rgba(255, 255, 255, 0.8); - text-align: justify; - padding: 10px; - border-radius: 6px; - font-size: 0.8em; - width: 250px; - /* Position the tooltip text - see examples below! */ - position: absolute; - left: -75px; - z-index: 1; } - @media (max-width: 400px) { - .tooltip .tooltiptext { - width: 150px; - position: absolute; - left: -75px; } } - .tooltip .tooltiptext ul { - margin: 0; - padding-left: 15px; - color: inherit; } - .tooltip:hover, .tooltip:focus { - opacity: 1; } - .tooltip:hover .tooltiptext, .tooltip:focus .tooltiptext { - visibility: visible; } - .antispam { unicode-bidi: bidi-override; direction: rtl; } @@ -436,10 +412,6 @@ iframe { #game_infos #details hr { margin: 1ex; } -ul { - padding: 0; - list-style-type: none; } - a.inventory_item { display: block; padding: 15px; @@ -465,16 +437,16 @@ a.inventory_item { background-color: white; box-shadow: 0 0 1.5px 1px #6bb8c4; } -li.comment { +.comment { border-radius: 10px; padding: 10px; border: 1px solid rgba(107, 184, 196, 0.75); background-color: white; margin: 1em 0; font-size: 0.7em; } - li.comment .author { + .comment .author { font-weight: bold; } - li.comment .date { + .comment .date { font-size: 0.7em; } - li.comment p { + .comment p { margin: 0.5em; } diff --git a/mainsite/templates/partials/header.html b/mainsite/templates/partials/header.html index 842b564..2b8fa92 100644 --- a/mainsite/templates/partials/header.html +++ b/mainsite/templates/partials/header.html @@ -11,7 +11,7 @@ {% endif %} {% if request.user.is_authenticated %} -
{{ request.user.username }}
+
{% include "./user.html" with user=request.user %} {% else %} Connexion diff --git a/mainsite/templates/partials/user.html b/mainsite/templates/partials/user.html new file mode 100644 index 0000000..9fa0ae6 --- /dev/null +++ b/mainsite/templates/partials/user.html @@ -0,0 +1 @@ +{% if user.first_name %}{{ user.first_name }}{% else %}{{ user.username }}{% endif %}