From c248def7f27f9363d6a81b37660f4d8d8c644201 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 30 Oct 2021 12:03:21 +0200 Subject: [PATCH] refactoring Mode --- app/views/users.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/users.py b/app/views/users.py index 7a03a899..79b5e095 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -35,6 +35,7 @@ Emmanuel Viennet, 2021 """ import datetime import re +from enum import auto, IntEnum from xml.etree import ElementTree import flask @@ -116,6 +117,12 @@ class ChangePasswordForm(FlaskForm): raise ValidationError("Mot de passe actuel incorrect, ré-essayez") +class Mode(IntEnum): + WELCOME_AND_CHANGE_PASSWORD = auto() + WELCOME_ONLY = auto() + SILENT = auto() + + @bp.route("/") @bp.route("/index_html") @scodoc @@ -529,19 +536,20 @@ def create_user_form(user_name=None, edit=0, all_roles=1): ) return "\n".join(H) + msg + "\n" + tf[1] + F # Traitement initial (mode) : 3 cas + # cf énumération Mode # A: envoi de welcome + procedure de reset # B: envoi de welcome seulement (mot de passe saisie dans le formulaire) # C: Aucun envoi (mot de passe saisi dans le formulaire) if vals["welcome:list"] == "1": if vals["reset_password:list"] == "1": - mode = "A" + mode = Mode.WELCOME_AND_CHANGE_PASSWORD else: - mode = "B" + mode = Mode.WELCOME_ONLY else: - mode = "C" + mode = Mode.SILENT # check passwords - if mode == "A": + if mode == Mode.WELCOME_AND_CHANGE_PASSWORD: vals["password"] = generate_password() else: if vals["password"]: @@ -567,8 +575,8 @@ def create_user_form(user_name=None, edit=0, all_roles=1): db.session.add(u) db.session.commit() # envoi éventuel d'un message - if mode == "A" or mode == "B": - if mode == "A": + if mode == Mode.WELCOME_AND_CHANGE_PASSWORD or mode == Mode.WELCOME_ONLY: + if mode == Mode.WELCOME_AND_CHANGE_PASSWORD: token = u.get_reset_password_token() else: token = None