diff --git a/chat/static/chat.js b/chat/static/chat.js index c00c369..43dd347 100644 --- a/chat/static/chat.js +++ b/chat/static/chat.js @@ -190,7 +190,7 @@ function redrawMessages() { } let fetchMoreButton = document.getElementById('fetch-previous-messages') - if (!messages[selected_channel_id] || messages[selected_channel_id].size % MAX_MESSAGES !== 0) + if (!messages[selected_channel_id].size || messages[selected_channel_id].size % MAX_MESSAGES !== 0) fetchMoreButton.classList.add('d-none') else fetchMoreButton.classList.remove('d-none') diff --git a/chat/templates/chat/content.html b/chat/templates/chat/content.html index 34c0396..12bf52c 100644 --- a/chat/templates/chat/content.html +++ b/chat/templates/chat/content.html @@ -21,6 +21,11 @@ style="height: 95vh" id="chat-container">

+ {% if fullscreen %} + {# Logout button must be present in a form. The form must includes the whole line. #} +
+ {% csrf_token %} + {% endif %} + {% else %} + {% endif %} + {% if fullscreen %} +
+ {% endif %}

diff --git a/chat/templates/chat/login.html b/chat/templates/chat/login.html new file mode 100644 index 0000000..ee3e45e --- /dev/null +++ b/chat/templates/chat/login.html @@ -0,0 +1,36 @@ +{% load i18n static %} + + +{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} + + + + + + Chat du TFJM² - {% trans "Log in" %} + + + + {# Favicon #} + + + + {# Bootstrap CSS #} + + + + + {# Bootstrap JavaScript #} + + + + + +
+

{% trans "Log in" %}

+ {% include "registration/includes/login.html" %} +
+ + + + diff --git a/chat/urls.py b/chat/urls.py index 09a7fbe..9adf06e 100644 --- a/chat/urls.py +++ b/chat/urls.py @@ -1,6 +1,7 @@ # Copyright (C) 2024 by Animath # SPDX-License-Identifier: GPL-3.0-or-later +from django.contrib.auth.views import LoginView, LogoutView from django.urls import path from django.utils.translation import gettext_lazy as _ from tfjm.views import LoginRequiredTemplateView @@ -10,5 +11,8 @@ app_name = 'chat' urlpatterns = [ path('', LoginRequiredTemplateView.as_view(template_name="chat/chat.html", extra_context={'title': _("Chat")}), name='chat'), - path('fullscreen/', LoginRequiredTemplateView.as_view(template_name="chat/fullscreen.html"), name='fullscreen'), + path('fullscreen/', LoginRequiredTemplateView.as_view(template_name="chat/fullscreen.html", login_url='chat:login'), + name='fullscreen'), + path('login/', LoginView.as_view(template_name="chat/login.html"), name='login'), + path('logout/', LogoutView.as_view(next_page='chat:fullscreen'), name='logout'), ] diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 8e8d78e..187ca3f 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: TFJM\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-27 18:49+0200\n" +"POT-Creation-Date: 2024-04-28 11:56+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Emmy D'Anello \n" "Language-Team: LANGUAGE \n" @@ -143,15 +143,15 @@ msgstr "message" msgid "messages" msgstr "messages" -#: chat/templates/chat/chat.html:14 +#: chat/templates/chat/content.html:4 msgid "JavaScript must be enabled on your browser to access chat." msgstr "JavaScript doit être activé sur votre navigateur pour accéder au chat." -#: chat/templates/chat/chat.html:18 +#: chat/templates/chat/content.html:8 msgid "Chat channels" msgstr "Canaux de chat" -#: chat/templates/chat/chat.html:27 +#: chat/templates/chat/content.html:17 msgid "" "You can install a shortcut to the chat on your home screen using the " "download button on the header." @@ -159,23 +159,37 @@ msgstr "" "Vous pouvez installer un raccourci vers le chat sur votre écran d'accueil en " "utilisant le bouton de téléchargement dans l'en-tête." -#: chat/templates/chat/chat.html:40 +#: chat/templates/chat/content.html:35 msgid "Toggle fullscreen mode" msgstr "Inverse le mode plein écran" -#: chat/templates/chat/chat.html:44 +#: chat/templates/chat/content.html:39 tfjm/templates/navbar.html:117 +msgid "Log out" +msgstr "Déconnexion" + +#: chat/templates/chat/content.html:43 msgid "Install app on home screen" msgstr "Installer l'application sur l'écran d'accueil" -#: chat/templates/chat/chat.html:52 +#: chat/templates/chat/content.html:54 msgid "Fetch previous messages…" msgstr "Récupérer les messages précédents…" -#: chat/templates/chat/chat.html:64 +#: chat/templates/chat/content.html:66 msgid "Send message…" msgstr "Envoyer un message…" -#: chat/views.py:15 tfjm/templates/navbar.html:67 +#: chat/templates/chat/login.html:10 chat/templates/chat/login.html:30 +#: registration/templates/registration/password_reset_complete.html:10 +#: tfjm/templates/base.html:84 tfjm/templates/base.html:85 +#: tfjm/templates/navbar.html:98 +#: tfjm/templates/registration/includes/login.html:22 +#: tfjm/templates/registration/login.html:7 +#: tfjm/templates/registration/login.html:8 +msgid "Log in" +msgstr "Connexion" + +#: chat/urls.py:13 tfjm/templates/navbar.html:66 msgid "Chat" msgstr "Chat" @@ -3018,14 +3032,6 @@ msgstr "Changer mon mot de passe" msgid "Your password has been set. You may go ahead and log in now." msgstr "Votre mot de passe a été changé. Vous pouvez désormais vous connecter." -#: registration/templates/registration/password_reset_complete.html:10 -#: tfjm/templates/base.html:84 tfjm/templates/base.html:85 -#: tfjm/templates/navbar.html:98 tfjm/templates/registration/login.html:7 -#: tfjm/templates/registration/login.html:8 -#: tfjm/templates/registration/login.html:30 -msgid "Log in" -msgstr "Connexion" - #: registration/templates/registration/password_reset_confirm.html:9 msgid "" "Please enter your new password twice so we can verify you typed it in " @@ -3647,11 +3653,11 @@ msgstr "Privé, réservé aux utilisateur⋅rices explicitement autorisé⋅es" msgid "Admin users" msgstr "Administrateur⋅rices" -#: tfjm/settings.py:168 +#: tfjm/settings.py:169 msgid "English" msgstr "Anglais" -#: tfjm/settings.py:169 +#: tfjm/settings.py:170 msgid "French" msgstr "Français" @@ -3760,19 +3766,7 @@ msgstr "S'inscrire" msgid "My account" msgstr "Mon compte" -#: tfjm/templates/navbar.html:117 -msgid "Log out" -msgstr "Déconnexion" - -#: tfjm/templates/registration/logged_out.html:8 -msgid "Thanks for spending some quality time with the Web site today." -msgstr "Merci d'avoir utilisé la plateforme du TFJM²." - -#: tfjm/templates/registration/logged_out.html:9 -msgid "Log in again" -msgstr "Se reconnecter" - -#: tfjm/templates/registration/login.html:13 +#: tfjm/templates/registration/includes/login.html:5 #, python-format msgid "" "You are authenticated as %(user)s, but are not authorized to access this " @@ -3781,14 +3775,22 @@ msgstr "" "Vous êtes connecté⋅e en tant que %(user)s, mais n'êtes pas autorisé⋅e à " "accéder à cette page. Voulez-vous vous reconnecter avec un autre compte ?" -#: tfjm/templates/registration/login.html:25 +#: tfjm/templates/registration/includes/login.html:17 msgid "Your username is your e-mail address." msgstr "Votre identifiant est votre adresse e-mail." -#: tfjm/templates/registration/login.html:28 +#: tfjm/templates/registration/includes/login.html:20 msgid "Forgotten your password?" msgstr "Mot de passe oublié ?" +#: tfjm/templates/registration/logged_out.html:8 +msgid "Thanks for spending some quality time with the Web site today." +msgstr "Merci d'avoir utilisé la plateforme du TFJM²." + +#: tfjm/templates/registration/logged_out.html:9 +msgid "Log in again" +msgstr "Se reconnecter" + #: tfjm/templates/search/search.html:6 tfjm/templates/search/search.html:10 msgid "Search" msgstr "Chercher" diff --git a/tfjm/settings.py b/tfjm/settings.py index eb1c53f..4c6a0e0 100644 --- a/tfjm/settings.py +++ b/tfjm/settings.py @@ -102,6 +102,7 @@ MIDDLEWARE = [ ROOT_URLCONF = 'tfjm.urls' LOGIN_REDIRECT_URL = "index" +LOGOUT_REDIRECT_URL = "login" TEMPLATES = [ { diff --git a/tfjm/templates/registration/includes/login.html b/tfjm/templates/registration/includes/login.html new file mode 100644 index 0000000..1ae3348 --- /dev/null +++ b/tfjm/templates/registration/includes/login.html @@ -0,0 +1,23 @@ +{% load i18n crispy_forms_filters %} + +{% if user.is_authenticated %} +

+ {% blocktrans trimmed %} + You are authenticated as {{ user }}, but are not authorized to + access this page. Would you like to login to a different account? + {% endblocktrans %} +

+{% endif %} +
+
+ {{ form|as_crispy_errors }} + {% csrf_token %} + {{ form.username|as_crispy_field }} +
+ {% trans "Your username is your e-mail address." %} +
+ {{ form.password|as_crispy_field }} + {% trans 'Forgotten your password?' %} +
+ +
\ No newline at end of file diff --git a/tfjm/templates/registration/login.html b/tfjm/templates/registration/login.html index f033a0b..2695aa0 100644 --- a/tfjm/templates/registration/login.html +++ b/tfjm/templates/registration/login.html @@ -2,31 +2,11 @@ {% comment %} SPDX-License-Identifier: GPL-2.0-or-later {% endcomment %} -{% load i18n crispy_forms_filters %} +{% load i18n %} {% block title %}{% trans "Log in" %}{% endblock %} {% block content-title %}

{% trans "Log in" %}

{% endblock %} {% block content %} - {% if user.is_authenticated %} -

- {% blocktrans trimmed %} - You are authenticated as {{ user }}, but are not authorized to - access this page. Would you like to login to a different account? - {% endblocktrans %} -

- {% endif %} -
-
- {{ form|as_crispy_errors }} - {% csrf_token %} - {{ form.username|as_crispy_field }} -
- {% trans "Your username is your e-mail address." %} -
- {{ form.password|as_crispy_field }} - {% trans 'Forgotten your password?' %} -
- -
+ {% include "registration/includes/login.html" %} {% endblock %}