Add config:DISABLE_REGISTER

This commit is contained in:
augustin64 2023-06-24 16:05:05 +02:00
parent 782da97a1f
commit 3c018bc336
4 changed files with 16 additions and 4 deletions

View File

@ -70,5 +70,5 @@ Modifier le fichier de configuration créé dans `instance/`
- [ ] Modifier son mot de passe - [ ] Modifier son mot de passe
- [ ] Supprimer un utilisateur - [ ] Supprimer un utilisateur
- [ ] Ajouter config:DISABLE_DARK_MODE - [ ] Ajouter config:DISABLE_DARK_MODE
- [ ] Ajouter config:DISABLE_REGISTER - [x] Ajouter config:DISABLE_REGISTER
- [ ] Ajouter config:ONLINE_SEARCH_BASE_QUERY pour la recherche google, actuellement 'filetype:pdf partition' - [ ] Ajouter config:ONLINE_SEARCH_BASE_QUERY pour la recherche google, actuellement 'filetype:pdf partition'

View File

@ -7,4 +7,9 @@ SECRET_KEY="dev"
# Port to run on # Port to run on
PORT="5000" PORT="5000"
# Number of online queries an "normal user" can do
MAX_ONLINE_QUERIES=3 MAX_ONLINE_QUERIES=3
# Disable registration of new users via /auth/register (they can still be added by root)
DISABLE_REGISTER=False

View File

@ -13,7 +13,8 @@ from flask import (
request, request,
session, session,
url_for, url_for,
flash flash,
current_app
) )
from werkzeug.security import check_password_hash, generate_password_hash from werkzeug.security import check_password_hash, generate_password_hash
@ -76,6 +77,10 @@ def register():
Validates that the username is not already taken. Hashes the Validates that the username is not already taken. Hashes the
password for security. password for security.
""" """
if current_app.config["DISABLE_REGISTER"]:
flash("L'enregistrement de nouveaux utilisateurs a été désactivé par l'administrateur.")
return redirect(url_for("auth.login"))
if request.method == "POST": if request.method == "POST":
username = request.form["username"] username = request.form["username"]
password = request.form["password"] password = request.form["password"]

View File

@ -117,7 +117,9 @@
<div class="username">{{ user.username }}</div> <div class="username">{{ user.username }}</div>
</div> </div>
{% else %} {% else %}
{% if not config.DISABLE_REGISTER %}
<a href="{{ url_for('auth.register') }}"><button>Créer un compte</button></a> <a href="{{ url_for('auth.register') }}"><button>Créer un compte</button></a>
{% endif %}
<a href="{{ url_for('auth.login') }}"><button>Se connecter</button></a> <a href="{{ url_for('auth.login') }}"><button>Se connecter</button></a>
{% endif %} {% endif %}
</div> </div>