refactoring Mode

This commit is contained in:
Jean-Marie Place 2021-10-30 12:03:21 +02:00
parent 2b91fd78df
commit c248def7f2

View File

@ -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