Add launch page

This commit is contained in:
augustin64 2024-01-29 18:37:30 +01:00
parent 3f888c39d2
commit ebc454f7a2
10 changed files with 314 additions and 52 deletions

View File

@ -29,4 +29,7 @@ INSTANCE_PATH="instance"
ENABLED_LOGS=["NEW_GROUPE", "NEW_ALBUM", "NEW_PARTITION", "NEW_USER", "SERVER_RESTART", "FAILED_LOGIN"]
# Available languages
LANGUAGES=['en', 'fr']
LANGUAGES=['en', 'fr']
# Show Launch page
LAUNCH_PAGE=True

View File

@ -8,11 +8,11 @@ import datetime
import subprocess
import importlib.util
from flask import Flask, g, redirect, render_template, request, send_file, flash, session, abort
from flask import Flask, g, redirect, render_template, request, send_file, flash, session, abort, url_for
from werkzeug.security import generate_password_hash
from flask_babel import Babel, _
from .modules.utils import User, Album, get_all_albums
from .modules.utils import User, Album, get_all_albums, user_count, partition_count
from .modules import albums, auth, partition, admin, groupe, thumbnails, logging
from .modules.auth import admin_required, login_required
from .modules.db import get_db
@ -101,8 +101,20 @@ logging.log([], logging.LogEntry.SERVER_RESTART)
@app.route("/")
def home():
"""Redirect to home"""
return redirect("/albums/")
"""Show launch page if enabled"""
if g.user is None:
if app.config["LAUNCH_PAGE"]:
return redirect(url_for("launch_page"))
return redirect(url_for("auth.login"))
return redirect(url_for("albums.index"))
@app.route("/launch")
def launch_page():
"""Show launch page if enabled"""
if not app.config["LAUNCH_PAGE"]:
return home()
return render_template("launch.html", user_count=user_count(), partition_count=partition_count())
@app.route("/add-user", methods=["GET", "POST"])
@ -133,10 +145,10 @@ def add_user():
if album_uuid != "":
user.join_album(album_uuid)
flash(_("Created user %(username)s", username=username))
return redirect("/albums")
return redirect(url_for("albums.index"))
except LookupError:
flash(_("This album does not exists, but user %(username)s has been created", username=username))
return redirect("/albums")
return redirect(url_for("albums.index"))
flash(error)
return render_template("auth/register.html", albums=get_all_albums(), user=current_user)

View File

@ -130,6 +130,7 @@ def register():
[user.username, user.id, False],
logging.LogEntry.NEW_USER
)
return redirect(url_for("auth.login"))
return render_template("auth/register.html")
@ -169,4 +170,4 @@ def login():
def logout():
"""Clear the current session, including the stored user id."""
session.clear()
return redirect(url_for("auth.login"))
return redirect("/")

View File

@ -72,3 +72,25 @@ def get_all_albums():
"uuid": a["uuid"]
} for a in albums
]
def user_count():
db = get_db()
count = db.execute(
"""
SELECT COUNT(*) as count FROM user
"""
).fetchone()
return count[0]
def partition_count():
db = get_db()
count = db.execute(
"""
SELECT COUNT(*) FROM partition
"""
).fetchone()
return count[0]

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

View File

@ -0,0 +1,110 @@
@import url('/static/style/colors.css');
* {
font-family: var(--font-family);
}
h2 {
color: var(--color-subtext1);
}
a {
text-decoration: none;
color: var(--color-blue);
}
body {
color: var(--color-text);
background-color: var(--color-base);
}
.no-color-link {
color: var(--color-text);
}
button {
padding: 10px 20px;
margin: 5px;
border-radius: 3px;
cursor: pointer;
font-weight: bold;
font-size: 0.95em;
border: var(--color-subtext0);
border-width: 2px;
border-style: solid;
background-color: var(--color-subtext0);
color: var(--color-base);
}
button.blue {
background-color: var(--color-blue);
border-color: var(--color-blue);
}
button:hover {
background-color: var(--color-crust);
border-color: var(--color-blue);
color: var(--color-blue);
}
header {
display: flex;
}
#login {
position: absolute;
right: 15px;
}
#logo-container {
margin: 25px;
}
main {
margin: 5vw;
text-align: center;
}
#instance-stats {
margin: 35px 0px;
color: var(--color-subtext1);
}
img.preview {
max-width: 85vw;
border-style: solid;
border-radius: 5px;
border-color: var(--color-overlay1);
border-width: 3px;
}
img#light-preview {
display: none;
}
img#dark-preview {
display: initial;
}
@media (prefers-color-scheme: light) {
img#light-preview {
display: initial;
}
img#dark-preview {
display: none;
}
}
footer {
color: var(--color-subtext1);
position: fixed;
bottom: 0;
width: 100%;
text-align: center;
margin-bottom: 10px;
}

View File

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="{{ lang }}">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="description" content="PartitionCloud launch page" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#eff1f5">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#1e1e2e">
<title>PartitionCloud</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style/launch.css') }}">
<link rel="icon" type="image/png" href="{{ url_for('static', filename='icons/512.png') }}" />
<link rel="apple-touch-icon" href="{{ url_for('static', filename='icons/512.png') }}">
<link rel="manifest" href="{{ url_for('static', filename='manifest.webmanifest') }}" />
</head>
<body>
<header>
<a id="logo-container" href="/">
<img src="/static/icons/icon.png" width="60px" height="auto" alt="Logo">
</a>
<div>
<a href="/auth/login">
<button class="blue" id="login">
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24" class="iconify inline" data-icon="fluent:key-24-filled" style="vertical-align: -0.125em; transform: rotate(360deg);"><path fill="currentColor" d="M8.95 8.6a6.554 6.554 0 0 1 6.55-6.55c3.596 0 6.55 2.819 6.55 6.45a6.554 6.554 0 0 1-6.55 6.55a6.243 6.243 0 0 1-1.552-.204A1.25 1.25 0 0 1 12.7 16.05h-1.75v1.75c0 .69-.56 1.25-1.25 1.25H7.95v1.25a1.75 1.75 0 0 1-1.75 1.75H3.7a1.75 1.75 0 0 1-1.75-1.75v-2.172c0-.73.29-1.429.806-1.944L8.99 9.948a.275.275 0 0 0 .07-.244A6.386 6.386 0 0 1 8.95 8.6Zm9.3-1.6a1.25 1.25 0 1 0-2.5 0a1.25 1.25 0 0 0 2.5 0Z"></path></svg>
&nbsp; {{ _("Log in") }}
</button>
</a>
</div>
</header>
<main>
<h1>{{ _("PartitionCloud is an open-source score library server, to help you in all your musical activities") }}</h1>
<div id="actions">
<a href="/auth/login" class="no-color-link">
<button class="blue">
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 13a8 8 0 0 1 7 7a6 6 0 0 0 3 -5a9 9 0 0 0 6 -8a3 3 0 0 0 -3 -3a9 9 0 0 0 -8 6a6 6 0 0 0 -5 3" /><path d="M7 14a6 6 0 0 0 -3 6a6 6 0 0 0 6 -3" /><path d="M15 9m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /></svg>
&nbsp; {{ _("Let's go !") }}
</button>
</a>
<a href="https://github.com/partitioncloud/partitioncloud-server" class="no-color-link">
<button>
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M16 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /><path d="M12 8m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /><path d="M12 16m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /><path d="M12 15v-6" /><path d="M15 11l-2 -2" /><path d="M11 7l-1.9 -1.9" /><path d="M13.446 2.6l7.955 7.954a2.045 2.045 0 0 1 0 2.892l-7.955 7.955a2.045 2.045 0 0 1 -2.892 0l-7.955 -7.955a2.045 2.045 0 0 1 0 -2.892l7.955 -7.955a2.045 2.045 0 0 1 2.892 0z" /></svg>
&nbsp; {{ _("Check code") }}
</button>
</a>
</div>
<div id="instance-stats">
{% set user_bold %}
<b>{{ user_count }}</b>
{% endset %}
{% set partition_bold %}
<b>{{ partition_count }}</b>
{% endset %}
{{ _("This instance is used by %(users)s users with a total of %(scores)s scores.", users=user_bold, scores=partition_bold) }}
</div>
<img class="preview" id="dark-preview" src="/static/images/dark-preview.png" loading="lazy">
<img class="preview" id="light-preview" src="/static/images/light-preview.png" loading="lazy">
</main>
<footer>{{ version }}</footer>
</body>
</html>

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-01-25 16:19+0100\n"
"POT-Creation-Date: 2024-01-29 18:32+0100\n"
"PO-Revision-Date: 2024-01-22 15:38+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
@ -18,12 +18,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.14.0\n"
#: partitioncloud/__init__.py:135
#: partitioncloud/__init__.py:147
#, python-format
msgid "Created user %(username)s"
msgstr "Created user %(username)s"
#: partitioncloud/__init__.py:138
#: partitioncloud/__init__.py:150
#, python-format
msgid "This album does not exists, but user %(username)s has been created"
msgstr "This album does not exists, but user %(username)s has been created"
@ -141,7 +141,7 @@ msgstr "New users registration is disabled by owner."
msgid "Successfully created new user. You can log in."
msgstr "Successfully created new user. You can log in."
#: partitioncloud/modules/auth.py:152
#: partitioncloud/modules/auth.py:153
msgid "Incorrect username or password"
msgstr "Incorrect username or password"
@ -217,82 +217,108 @@ msgstr "You are not allowed to delete this score."
msgid "Score deleted."
msgstr "Score deleted."
#: partitioncloud/templates/base.html:23
#: partitioncloud/templates/base.html:25
msgid "New Album"
msgstr "New Album"
#: partitioncloud/templates/base.html:25 partitioncloud/templates/base.html:36
#: partitioncloud/templates/base.html:27 partitioncloud/templates/base.html:38
#: partitioncloud/templates/groupe/index.html:10
#: partitioncloud/templates/partition/attachments.html:11
msgid "Name"
msgstr "Name"
#: partitioncloud/templates/base.html:26 partitioncloud/templates/base.html:37
#: partitioncloud/templates/base.html:28 partitioncloud/templates/base.html:39
msgid "Create"
msgstr "Create"
#: partitioncloud/templates/base.html:30
#: partitioncloud/templates/base.html:32
msgid "I want to create a collection of albums."
msgstr "I want to create a collection of albums."
#: partitioncloud/templates/base.html:30
#: partitioncloud/templates/base.html:32
msgid "Create group"
msgstr "Create group"
#: partitioncloud/templates/base.html:34
#: partitioncloud/templates/base.html:36
msgid "Create new group"
msgstr "Create new group"
#: partitioncloud/templates/base.html:61
#: partitioncloud/templates/base.html:63
msgid "Search"
msgstr "Search"
#: partitioncloud/templates/base.html:63
#: partitioncloud/templates/base.html:65
msgid "Number of online searches"
msgstr "Number of online searches"
#: partitioncloud/templates/admin/index.html:23
#: partitioncloud/templates/base.html:71
#: partitioncloud/templates/base.html:73
#: partitioncloud/templates/partition/details.html:41
msgid "Albums"
msgstr "Albums"
#: partitioncloud/templates/base.html:75
#: partitioncloud/templates/base.html:77
msgid "New album"
msgstr "New album"
#: partitioncloud/templates/base.html:92
#: partitioncloud/templates/base.html:94
msgid "No albums"
msgstr "No albums"
#: partitioncloud/templates/base.html:111
#: partitioncloud/templates/base.html:113
msgid "No album available"
msgstr "No album available"
#: partitioncloud/templates/base.html:125
#: partitioncloud/templates/base.html:127
msgid "Log in to see your albums"
msgstr "Log in to see your albums"
#: partitioncloud/templates/base.html:139
#: partitioncloud/templates/base.html:141
msgid "Log out"
msgstr "Log out"
#: partitioncloud/templates/base.html:154
#: partitioncloud/templates/base.html:156
msgid "Admin Panel"
msgstr "Admin Panel"
#: partitioncloud/templates/auth/register.html:5
#: partitioncloud/templates/auth/register.html:20
#: partitioncloud/templates/base.html:166
#: partitioncloud/templates/base.html:168
msgid "Create account"
msgstr "Create account"
#: partitioncloud/templates/auth/login.html:5
#: partitioncloud/templates/auth/login.html:10
#: partitioncloud/templates/base.html:168
#: partitioncloud/templates/base.html:170
#: partitioncloud/templates/launch.html:26
msgid "Log in"
msgstr "Log in"
#: partitioncloud/templates/launch.html:33
msgid ""
"PartitionCloud is an open-source score library server, to help you in all"
" your musical activities"
msgstr ""
"PartitionCloud is an open-source score library server, to help you in all"
" your musical activities"
#: partitioncloud/templates/launch.html:38
msgid "Let's go !"
msgstr "Let's go !"
#: partitioncloud/templates/launch.html:44
msgid "Check code"
msgstr "Check code"
#: partitioncloud/templates/launch.html:55
#, python-format
msgid ""
"This instance is used by %(users)s users with a total of %(scores)s "
"scores."
msgstr ""
"This instance has %(users)s users with a total of %(scores)s "
"scores."
#: partitioncloud/templates/admin/index.html:5
msgid "Administration Panel"
msgstr "Administration Panel"
@ -462,7 +488,7 @@ msgstr "author"
msgid "lyrics"
msgstr "lyrics"
#: partitioncloud/templates/components/add_partition.html:10
#: partitioncloud/templates/components/add_partition.html:12
#: partitioncloud/templates/groupe/index.html:11
#: partitioncloud/templates/partition/attachments.html:13
msgid "Add"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-01-25 16:19+0100\n"
"POT-Creation-Date: 2024-01-29 18:32+0100\n"
"PO-Revision-Date: 2024-01-22 15:24+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: fr\n"
@ -18,12 +18,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.14.0\n"
#: partitioncloud/__init__.py:135
#: partitioncloud/__init__.py:147
#, python-format
msgid "Created user %(username)s"
msgstr "Utilisateur %(username)s créé"
#: partitioncloud/__init__.py:138
#: partitioncloud/__init__.py:150
#, python-format
msgid "This album does not exists, but user %(username)s has been created"
msgstr "Cet album n'existe pas. L'utilisateur %(username)s a été créé"
@ -143,7 +143,7 @@ msgstr ""
msgid "Successfully created new user. You can log in."
msgstr "Utilisateur créé avec succès. Vous pouvez vous connecter."
#: partitioncloud/modules/auth.py:152
#: partitioncloud/modules/auth.py:153
msgid "Incorrect username or password"
msgstr "Nom d'utilisateur ou mot de passe incorrect."
@ -219,84 +219,110 @@ msgstr "Vous n'êtes pas autorisé à supprimer cette partition."
msgid "Score deleted."
msgstr "Partition supprimée."
#: partitioncloud/templates/base.html:23
#: partitioncloud/templates/base.html:25
msgid "New Album"
msgstr "Créer un nouvel album"
#: partitioncloud/templates/base.html:25 partitioncloud/templates/base.html:36
#: partitioncloud/templates/base.html:27 partitioncloud/templates/base.html:38
#: partitioncloud/templates/groupe/index.html:10
#: partitioncloud/templates/partition/attachments.html:11
msgid "Name"
msgstr "Nom"
#: partitioncloud/templates/base.html:26 partitioncloud/templates/base.html:37
#: partitioncloud/templates/base.html:28 partitioncloud/templates/base.html:39
msgid "Create"
msgstr "Créer"
#: partitioncloud/templates/base.html:30
#: partitioncloud/templates/base.html:32
msgid "I want to create a collection of albums."
msgstr ""
"Je souhaite créer plusieurs albums et pouvoir tous les partager avec un "
"seul lien."
#: partitioncloud/templates/base.html:30
#: partitioncloud/templates/base.html:32
msgid "Create group"
msgstr "Créer un groupe"
#: partitioncloud/templates/base.html:34
#: partitioncloud/templates/base.html:36
msgid "Create new group"
msgstr "Créer un nouveau groupe"
#: partitioncloud/templates/base.html:61
#: partitioncloud/templates/base.html:63
msgid "Search"
msgstr "Rechercher"
#: partitioncloud/templates/base.html:63
#: partitioncloud/templates/base.html:65
msgid "Number of online searches"
msgstr "Nombre de recherches en ligne"
#: partitioncloud/templates/admin/index.html:23
#: partitioncloud/templates/base.html:71
#: partitioncloud/templates/base.html:73
#: partitioncloud/templates/partition/details.html:41
msgid "Albums"
msgstr "Albums"
#: partitioncloud/templates/base.html:75
#: partitioncloud/templates/base.html:77
msgid "New album"
msgstr "Créer un album"
#: partitioncloud/templates/base.html:92
#: partitioncloud/templates/base.html:94
msgid "No albums"
msgstr "Aucun album disponible"
#: partitioncloud/templates/base.html:111
#: partitioncloud/templates/base.html:113
msgid "No album available"
msgstr "Aucun album disponible"
#: partitioncloud/templates/base.html:125
#: partitioncloud/templates/base.html:127
msgid "Log in to see your albums"
msgstr "Connectez vous pour avoir accès à vos albums"
#: partitioncloud/templates/base.html:139
#: partitioncloud/templates/base.html:141
msgid "Log out"
msgstr "Déconnexion"
#: partitioncloud/templates/base.html:154
#: partitioncloud/templates/base.html:156
msgid "Admin Panel"
msgstr "Panneau admin"
#: partitioncloud/templates/auth/register.html:5
#: partitioncloud/templates/auth/register.html:20
#: partitioncloud/templates/base.html:166
#: partitioncloud/templates/base.html:168
msgid "Create account"
msgstr "Créer un compte"
#: partitioncloud/templates/auth/login.html:5
#: partitioncloud/templates/auth/login.html:10
#: partitioncloud/templates/base.html:168
#: partitioncloud/templates/base.html:170
#: partitioncloud/templates/launch.html:26
msgid "Log in"
msgstr "Se connecter"
#: partitioncloud/templates/launch.html:33
msgid ""
"PartitionCloud is an open-source score library server, to help you in all"
" your musical activities"
msgstr ""
"PartitionCloud est une bibliothèque de partitions open-source, pour vous "
"aider dans toutes vos activités musicales"
#: partitioncloud/templates/launch.html:38
msgid "Let's go !"
msgstr "C'est parti !"
#: partitioncloud/templates/launch.html:44
msgid "Check code"
msgstr "Voir le code"
#: partitioncloud/templates/launch.html:55
#, python-format
msgid ""
"This instance is used by %(users)s users with a total of %(scores)s "
"scores."
msgstr ""
"Cette instance est utilisée par %(users)s personnes avec un total de "
"%(scores)s partitions."
#: partitioncloud/templates/admin/index.html:5
msgid "Administration Panel"
msgstr "Panneau d'administration"
@ -466,7 +492,7 @@ msgstr "auteur"
msgid "lyrics"
msgstr "paroles"
#: partitioncloud/templates/components/add_partition.html:10
#: partitioncloud/templates/components/add_partition.html:12
#: partitioncloud/templates/groupe/index.html:11
#: partitioncloud/templates/partition/attachments.html:13
msgid "Add"