Add specific login and logout pages for chat

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-04-28 11:57:25 +02:00
parent 7bb0f78f34
commit e77cc558de
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
8 changed files with 116 additions and 58 deletions

View File

@ -190,7 +190,7 @@ function redrawMessages() {
} }
let fetchMoreButton = document.getElementById('fetch-previous-messages') 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') fetchMoreButton.classList.add('d-none')
else else
fetchMoreButton.classList.remove('d-none') fetchMoreButton.classList.remove('d-none')

View File

@ -21,6 +21,11 @@
style="height: 95vh" id="chat-container"> style="height: 95vh" id="chat-container">
<div class="card-header"> <div class="card-header">
<h3> <h3>
{% if fullscreen %}
{# Logout button must be present in a form. The form must includes the whole line. #}
<form action="{% url 'chat:logout' %}" method="post">
{% csrf_token %}
{% endif %}
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#channelSelector" <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#channelSelector"
aria-controls="channelSelector" aria-expanded="false" aria-label="Toggle channel selector"> aria-controls="channelSelector" aria-expanded="false" aria-label="Toggle channel selector">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
@ -30,10 +35,17 @@
<button class="btn float-end" type="button" onclick="toggleFullscreen()" title="{% trans "Toggle fullscreen mode" %}"> <button class="btn float-end" type="button" onclick="toggleFullscreen()" title="{% trans "Toggle fullscreen mode" %}">
<i class="fas fa-expand"></i> <i class="fas fa-expand"></i>
</button> </button>
{% else %}
<button class="btn float-end" title="{% trans "Log out" %}">
<i class="fas fa-sign-out-alt"></i>
</button>
{% endif %} {% endif %}
<button class="btn float-end d-none" type="button" id="install-app-home-screen" title="{% trans "Install app on home screen" %}"> <button class="btn float-end d-none" type="button" id="install-app-home-screen" title="{% trans "Install app on home screen" %}">
<i class="fas fa-download"></i> <i class="fas fa-download"></i>
</button> </button>
{% if fullscreen %}
</form>
{% endif %}
</h3> </h3>
</div> </div>
<div class="card-body d-flex flex-column-reverse flex-grow-0 overflow-y-scroll" id="chat-messages"> <div class="card-body d-flex flex-column-reverse flex-grow-0 overflow-y-scroll" id="chat-messages">

View File

@ -0,0 +1,36 @@
{% load i18n static %}
<!DOCTYPE html>
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
<html lang="{{ LANGUAGE_CODE|default:"fr" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>
Chat du TFJM² - {% trans "Log in" %}
</title>
<meta name="description" content="Chat du TFJM²">
{# Favicon #}
<link rel="shortcut icon" href="{% static "favicon.ico" %}">
<meta name="theme-color" content="#ffffff">
{# Bootstrap CSS #}
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'fontawesome/css/all.css' %}">
<link rel="stylesheet" href="{% static 'fontawesome/css/v4-shims.css' %}">
{# Bootstrap JavaScript #}
<script src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<link rel="manifest" href="{% static "chat.webmanifest" %}">
</head>
<body class="d-flex w-100 h-100 flex-column">
<div class="container">
<h1>{% trans "Log in" %}</h1>
{% include "registration/includes/login.html" %}
</div>
<script src="{% static 'theme.js' %}"></script>
</body>
</html>

View File

@ -1,6 +1,7 @@
# Copyright (C) 2024 by Animath # Copyright (C) 2024 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import path from django.urls import path
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from tfjm.views import LoginRequiredTemplateView from tfjm.views import LoginRequiredTemplateView
@ -10,5 +11,8 @@ app_name = 'chat'
urlpatterns = [ urlpatterns = [
path('', LoginRequiredTemplateView.as_view(template_name="chat/chat.html", path('', LoginRequiredTemplateView.as_view(template_name="chat/chat.html",
extra_context={'title': _("Chat")}), name='chat'), 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'),
] ]

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: TFJM\n" "Project-Id-Version: TFJM\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Emmy D'Anello <emmy.danello@animath.fr>\n" "Last-Translator: Emmy D'Anello <emmy.danello@animath.fr>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -143,15 +143,15 @@ msgstr "message"
msgid "messages" msgid "messages"
msgstr "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." msgid "JavaScript must be enabled on your browser to access chat."
msgstr "JavaScript doit être activé sur votre navigateur pour accéder au 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" msgid "Chat channels"
msgstr "Canaux de chat" msgstr "Canaux de chat"
#: chat/templates/chat/chat.html:27 #: chat/templates/chat/content.html:17
msgid "" msgid ""
"You can install a shortcut to the chat on your home screen using the " "You can install a shortcut to the chat on your home screen using the "
"download button on the header." "download button on the header."
@ -159,23 +159,37 @@ msgstr ""
"Vous pouvez installer un raccourci vers le chat sur votre écran d'accueil en " "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." "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" msgid "Toggle fullscreen mode"
msgstr "Inverse le mode plein écran" 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" msgid "Install app on home screen"
msgstr "Installer l'application sur l'écran d'accueil" 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…" msgid "Fetch previous messages…"
msgstr "Récupérer les messages précédents…" msgstr "Récupérer les messages précédents…"
#: chat/templates/chat/chat.html:64 #: chat/templates/chat/content.html:66
msgid "Send message…" msgid "Send message…"
msgstr "Envoyer un 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" msgid "Chat"
msgstr "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." 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." 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 #: registration/templates/registration/password_reset_confirm.html:9
msgid "" msgid ""
"Please enter your new password twice so we can verify you typed it in " "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" msgid "Admin users"
msgstr "Administrateur⋅rices" msgstr "Administrateur⋅rices"
#: tfjm/settings.py:168 #: tfjm/settings.py:169
msgid "English" msgid "English"
msgstr "Anglais" msgstr "Anglais"
#: tfjm/settings.py:169 #: tfjm/settings.py:170
msgid "French" msgid "French"
msgstr "Français" msgstr "Français"
@ -3760,19 +3766,7 @@ msgstr "S'inscrire"
msgid "My account" msgid "My account"
msgstr "Mon compte" msgstr "Mon compte"
#: tfjm/templates/navbar.html:117 #: tfjm/templates/registration/includes/login.html:5
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
#, python-format #, python-format
msgid "" msgid ""
"You are authenticated as %(user)s, but are not authorized to access this " "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 à " "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 ?" "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." msgid "Your username is your e-mail address."
msgstr "Votre identifiant est votre adresse e-mail." 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?" msgid "Forgotten your password?"
msgstr "Mot de passe oublié ?" 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 #: tfjm/templates/search/search.html:6 tfjm/templates/search/search.html:10
msgid "Search" msgid "Search"
msgstr "Chercher" msgstr "Chercher"

View File

@ -102,6 +102,7 @@ MIDDLEWARE = [
ROOT_URLCONF = 'tfjm.urls' ROOT_URLCONF = 'tfjm.urls'
LOGIN_REDIRECT_URL = "index" LOGIN_REDIRECT_URL = "index"
LOGOUT_REDIRECT_URL = "login"
TEMPLATES = [ TEMPLATES = [
{ {

View File

@ -0,0 +1,23 @@
{% load i18n crispy_forms_filters %}
{% if user.is_authenticated %}
<p class="errornote">
{% 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 %}
</p>
{% endif %}
<form method="post" id="login-form">
<div id="form-content">
{{ form|as_crispy_errors }}
{% csrf_token %}
{{ form.username|as_crispy_field }}
<div class="form-text mb-3">
<i class="fas fa-info-circle"></i> {% trans "Your username is your e-mail address." %}
</div>
{{ form.password|as_crispy_field }}
<a href="{% url 'password_reset' %}" class="badge text-bg-warning">{% trans 'Forgotten your password?' %}</a>
</div>
<input type="submit" value="{% trans 'Log in' %}" class="btn btn-primary">
</form>

View File

@ -2,31 +2,11 @@
{% comment %} {% comment %}
SPDX-License-Identifier: GPL-2.0-or-later SPDX-License-Identifier: GPL-2.0-or-later
{% endcomment %} {% endcomment %}
{% load i18n crispy_forms_filters %} {% load i18n %}
{% block title %}{% trans "Log in" %}{% endblock %} {% block title %}{% trans "Log in" %}{% endblock %}
{% block content-title %}<h1>{% trans "Log in" %}</h1>{% endblock %} {% block content-title %}<h1>{% trans "Log in" %}</h1>{% endblock %}
{% block content %} {% block content %}
{% if user.is_authenticated %} {% include "registration/includes/login.html" %}
<p class="errornote">
{% 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 %}
</p>
{% endif %}
<form method="post" id="login-form">
<div id="form-content">
{{ form|as_crispy_errors }}
{% csrf_token %}
{{ form.username|as_crispy_field }}
<div class="form-text mb-3">
<i class="fas fa-info-circle"></i> {% trans "Your username is your e-mail address." %}
</div>
{{ form.password|as_crispy_field }}
<a href="{% url 'password_reset' %}" class="badge text-bg-warning">{% trans 'Forgotten your password?' %}</a>
</div>
<input type="submit" value="{% trans 'Log in' %}" class="btn btn-primary">
</form>
{% endblock %} {% endblock %}