Compare commits

...

2 Commits

Author SHA1 Message Date
Emmy D'Anello af9dcebca9
Open channels list by swiping
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 12:55:25 +02:00
Emmy D'Anello 9c118c7142
Add specific login and logout pages for chat
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 11:57:25 +02:00
8 changed files with 167 additions and 79 deletions

View File

@ -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')
@ -260,26 +260,56 @@ document.addEventListener('DOMContentLoaded', () => {
})
}
setupSocket()
function setupSwipeOffscreen() {
const offcanvas = new bootstrap.Offcanvas(document.getElementById('channelSelector'))
let deferredPrompt = null
window.addEventListener("beforeinstallprompt", (e) => {
e.preventDefault()
deferredPrompt = e
let btn = document.getElementById('install-app-home-screen')
let alert = document.getElementById('alert-download-chat-app')
btn.classList.remove('d-none')
alert.classList.remove('d-none')
btn.onclick = function () {
deferredPrompt.prompt()
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
deferredPrompt = null
btn.classList.add('d-none')
alert.classList.add('d-none')
let lastX = null
document.addEventListener('touchstart', (event) => {
if (event.touches.length === 1)
lastX = event.touches[0].clientX
})
document.addEventListener('touchmove', (event) => {
if (event.touches.length === 1 && lastX !== null) {
const diff = event.touches[0].clientX - lastX
if (diff > window.innerWidth / 10 && lastX < window.innerWidth / 4) {
offcanvas.show()
lastX = null
}
})
}
})
else if (diff < -window.innerWidth / 10) {
offcanvas.hide()
lastX = null
}
}
})
document.addEventListener('touchend', () => {
lastX = null
})
}
function setupPWAPrompt() {
let deferredPrompt = null
window.addEventListener("beforeinstallprompt", (e) => {
e.preventDefault()
deferredPrompt = e
let btn = document.getElementById('install-app-home-screen')
let alert = document.getElementById('alert-download-chat-app')
btn.classList.remove('d-none')
alert.classList.remove('d-none')
btn.onclick = function () {
deferredPrompt.prompt()
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
deferredPrompt = null
btn.classList.add('d-none')
alert.classList.add('d-none')
}
})
}
})
}
setupSocket()
setupSwipeOffscreen()
setupPWAPrompt()
})

View File

@ -21,6 +21,11 @@
style="height: 95vh" id="chat-container">
<div class="card-header">
<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"
aria-controls="channelSelector" aria-expanded="false" aria-label="Toggle channel selector">
<span class="navbar-toggler-icon"></span>
@ -30,20 +35,27 @@
<button class="btn float-end" type="button" onclick="toggleFullscreen()" title="{% trans "Toggle fullscreen mode" %}">
<i class="fas fa-expand"></i>
</button>
{% else %}
<button class="btn float-end" title="{% trans "Log out" %}">
<i class="fas fa-sign-out-alt"></i>
</button>
{% endif %}
<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>
</button>
{% if fullscreen %}
</form>
{% endif %}
</h3>
</div>
<div class="card-body d-flex flex-column-reverse flex-grow-0 overflow-y-scroll" id="chat-messages">
<ul class="list-group list-group-flush" id="message-list"></ul>
<div class="text-center d-none" id="fetch-previous-messages">
<a href="#" class="nav-link" onclick="event.preventDefault(); fetchPreviousMessages()">
{% trans "Fetch previous messages…" %}
</a>
<hr>
</div>
<ul class="list-group list-group-flush" id="message-list"></ul>
</div>
<div class="card-footer mt-auto">
<form onsubmit="event.preventDefault(); sendMessage()">

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
# 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'),
]

View File

@ -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 <emmy.danello@animath.fr>\n"
"Language-Team: LANGUAGE <LL@li.org>\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"

View File

@ -102,6 +102,7 @@ MIDDLEWARE = [
ROOT_URLCONF = 'tfjm.urls'
LOGIN_REDIRECT_URL = "index"
LOGOUT_REDIRECT_URL = "login"
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 %}
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 %}<h1>{% trans "Log in" %}</h1>{% endblock %}
{% block content %}
{% 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>
{% include "registration/includes/login.html" %}
{% endblock %}