forked from ScoDoc/ScoDoc
refactoring Mode
This commit is contained in:
parent
2b91fd78df
commit
c248def7f2
@ -35,6 +35,7 @@ Emmanuel Viennet, 2021
|
|||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
from enum import auto, IntEnum
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
@ -116,6 +117,12 @@ class ChangePasswordForm(FlaskForm):
|
|||||||
raise ValidationError("Mot de passe actuel incorrect, ré-essayez")
|
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("/")
|
||||||
@bp.route("/index_html")
|
@bp.route("/index_html")
|
||||||
@scodoc
|
@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
|
return "\n".join(H) + msg + "\n" + tf[1] + F
|
||||||
# Traitement initial (mode) : 3 cas
|
# Traitement initial (mode) : 3 cas
|
||||||
|
# cf énumération Mode
|
||||||
# A: envoi de welcome + procedure de reset
|
# A: envoi de welcome + procedure de reset
|
||||||
# B: envoi de welcome seulement (mot de passe saisie dans le formulaire)
|
# B: envoi de welcome seulement (mot de passe saisie dans le formulaire)
|
||||||
# C: Aucun envoi (mot de passe saisi dans le formulaire)
|
# C: Aucun envoi (mot de passe saisi dans le formulaire)
|
||||||
if vals["welcome:list"] == "1":
|
if vals["welcome:list"] == "1":
|
||||||
if vals["reset_password:list"] == "1":
|
if vals["reset_password:list"] == "1":
|
||||||
mode = "A"
|
mode = Mode.WELCOME_AND_CHANGE_PASSWORD
|
||||||
else:
|
else:
|
||||||
mode = "B"
|
mode = Mode.WELCOME_ONLY
|
||||||
else:
|
else:
|
||||||
mode = "C"
|
mode = Mode.SILENT
|
||||||
|
|
||||||
# check passwords
|
# check passwords
|
||||||
if mode == "A":
|
if mode == Mode.WELCOME_AND_CHANGE_PASSWORD:
|
||||||
vals["password"] = generate_password()
|
vals["password"] = generate_password()
|
||||||
else:
|
else:
|
||||||
if vals["password"]:
|
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.add(u)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
# envoi éventuel d'un message
|
# envoi éventuel d'un message
|
||||||
if mode == "A" or mode == "B":
|
if mode == Mode.WELCOME_AND_CHANGE_PASSWORD or mode == Mode.WELCOME_ONLY:
|
||||||
if mode == "A":
|
if mode == Mode.WELCOME_AND_CHANGE_PASSWORD:
|
||||||
token = u.get_reset_password_token()
|
token = u.get_reset_password_token()
|
||||||
else:
|
else:
|
||||||
token = None
|
token = None
|
||||||
|
Loading…
Reference in New Issue
Block a user