From 2b91fd78df49b957381cdc25cb4202824b304fef Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 30 Oct 2021 12:01:17 +0200 Subject: [PATCH 1/4] ajout mention \'message automatique\' --- app/templates/email/welcome.html | 4 +++- app/templates/email/welcome.txt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/templates/email/welcome.html b/app/templates/email/welcome.html index 41ee5f65..41fb1c61 100644 --- a/app/templates/email/welcome.html +++ b/app/templates/email/welcome.html @@ -15,4 +15,6 @@

{{ url_for('auth.reset_password', token=token, _external=True) }}

{% endif %} -

A bientôt !

\ No newline at end of file +

A bientôt !

+ +

Ce message a été généré automatiquement par le serveur ScoDoc.

\ No newline at end of file diff --git a/app/templates/email/welcome.txt b/app/templates/email/welcome.txt index b15bceae..2630a8bd 100644 --- a/app/templates/email/welcome.txt +++ b/app/templates/email/welcome.txt @@ -8,4 +8,6 @@ Votre identifiant de connexion est: {{ user.user_name }} {{ url_for('auth.reset_password', token=token, _external=True) }} {% endif %} -

A bientôt !

\ No newline at end of file +A bientôt ! + +Ce message a été généré automatiquement par le serveur ScoDoc. \ No newline at end of file From c248def7f27f9363d6a81b37660f4d8d8c644201 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 30 Oct 2021 12:03:21 +0200 Subject: [PATCH 2/4] 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 From 8f1e465280f9b3bf43206856ae0ce744925ca35c Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 30 Oct 2021 12:05:51 +0200 Subject: [PATCH 3/4] show current user name while getting old_password --- app/templates/auth/change_password.html | 20 ++++++++++++++------ app/views/users.py | 6 +++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/templates/auth/change_password.html b/app/templates/auth/change_password.html index 975e8bc9..2bec7762 100644 --- a/app/templates/auth/change_password.html +++ b/app/templates/auth/change_password.html @@ -1,9 +1,13 @@ {% extends "base.html" %} {% import 'bootstrap/wtf.html' as wtf %} -{% macro render_field(field) %} +{% macro render_field(field, auth_name=None) %} - {{ field.label }} + {% if auth_name %} + {{ field.label }} ({{ auth_name }}): + {% else %} + {{ field.label }} + {% endif %} {{ field(**kwargs)|safe }} {% if field.errors %}
    @@ -20,16 +24,20 @@

    Modification du compte ScoDoc {{form.user_name.data}}

    Identifiez-vous avez votre mot de passe actuel

    -

    Vous pouvez changer le mot de passe et/ou l'adresse email.

    -

    Les champs vides ne seront pas changés.

    {{ form.user_name }} {{ form.csrf_token }} - {{ render_field(form.old_password, size=14, + {{ render_field(form.old_password, size=14, auth_name=auth_username, style="padding:1px; margin-left: 1em; margin-top: 4px;") }} - {{ render_field(form.new_password, size=14, + + + + {{ render_field(form.new_password, size=14, style="padding:1px; margin-left: 1em; margin-top: 12px;") }} {{ render_field(form.bis_password, size=14, style="padding:1px; margin-left: 1em; margin-top: 4px;") }} diff --git a/app/views/users.py b/app/views/users.py index 79b5e095..53f60030 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -152,6 +152,7 @@ def user_info(user_name, format="json"): def create_user_form(user_name=None, edit=0, all_roles=1): "form. création ou edition utilisateur" auth_dept = current_user.dept + auth_username = current_user.user_name initvalues = {} edit = int(edit) all_roles = int(all_roles) @@ -795,7 +796,10 @@ def form_change_password(user_name=None): return redirect(destination) return render_template( - "auth/change_password.html", form=form, title="Modification compte ScoDoc" + "auth/change_password.html", + form=form, + title="Modification compte ScoDoc", + auth_username=current_user.user_name, ) From 68ac7c293abd9aabb953c9dd6a9ed6e65c9630dc Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 30 Oct 2021 12:09:35 +0200 Subject: [PATCH 4/4] mail from current user rather than admin --- app/views/users.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/users.py b/app/views/users.py index 53f60030..fed26e52 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -153,6 +153,7 @@ def create_user_form(user_name=None, edit=0, all_roles=1): "form. création ou edition utilisateur" auth_dept = current_user.dept auth_username = current_user.user_name + from_mail = current_user.email initvalues = {} edit = int(edit) all_roles = int(all_roles) @@ -583,7 +584,7 @@ def create_user_form(user_name=None, edit=0, all_roles=1): token = None send_email( "[ScoDoc] Création de votre compte", - sender=current_app.config["ADMINS"][0], + sender=from_mail, # current_app.config["ADMINS"][0], recipients=[u.email], text_body=render_template("email/welcome.txt", user=u, token=token), html_body=render_template(
    +

    Vous pouvez changer le mot de passe et/ou l'adresse email.

    +

    Les champs laissés vides ne seront pas modifiés.

    +