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