This commit is contained in:
Jean-Marie Place 2021-10-15 15:34:10 +02:00
parent 45d20789dd
commit c68633bf5b

View File

@ -102,10 +102,12 @@ def create_user_form(user_name=None, edit=0, all_roles=1):
initvalues = {}
edit = int(edit)
all_roles = int(all_roles)
H = [html_sco_header.sco_header(
H = [
html_sco_header.sco_header(
bodyOnLoad="init_tf_form('')",
javascripts=["js/user_form.js"],
)]
)
]
F = html_sco_header.sco_footer()
if edit:
if not user_name:
@ -229,7 +231,7 @@ def create_user_form(user_name=None, edit=0, all_roles=1):
{
"title": "Message d'accueil",
"input_type": "checkbox",
"explanation": "Envoie un mail d'accueil à l'utilsateur.",
"explanation": "Envoie un mail d'accueil à l'utilisateur.",
"labels": ("",),
"allowed_values": ("1",),
"default": "1",
@ -417,7 +419,7 @@ def create_user_form(user_name=None, edit=0, all_roles=1):
nom=vals["nom"],
prenom=vals["prenom"],
email=vals["email"],
dept=vals["dept"],
dept=vals.get("dept", auth_dept),
roles=vals["roles"],
)
if not ok:
@ -478,17 +480,17 @@ def create_user_form(user_name=None, edit=0, all_roles=1):
# A: envoi de welcome + procedure de reset
# B: envoi de welcome seulement (mot de passe saisie dans le formulaire)
# C: Aucun envoi (mot de pase saisi dans le formulaire)
if vals['welcome:list'] == '1':
if vals['reset_password:list'] == '1':
mode = 'A'
if vals["welcome:list"] == "1":
if vals["reset_password:list"] == "1":
mode = "A"
else:
mode = 'B'
mode = "B"
else:
mode = 'C'
mode = "C"
# check passwords
if mode == 'A':
vals['password'] = generate_password()
if mode == "A":
vals["password"] = generate_password()
else:
if vals["password"]:
if vals["password"] != vals["password2"]:
@ -513,8 +515,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 == "A" or mode == "B":
if mode == "A":
token = u.get_reset_password_token()
else:
token = None
@ -523,7 +525,9 @@ def create_user_form(user_name=None, edit=0, all_roles=1):
sender=current_app.config["ADMINS"][0],
recipients=[u.email],
text_body=render_template("email/welcome.txt", user=u, token=token),
html_body=render_template("email/welcome.html", user=u, token=token),
html_body=render_template(
"email/welcome.html", user=u, token=token
),
)
return flask.redirect(