forked from ScoDoc/DocScoDoc
Merge pull request 'ameliore_create_change_user' (#177) from jmplace/ScoDoc-Lille:ameliore_create_change_user into master
Reviewed-on: https://scodoc.org/git/viennet/ScoDoc/pulls/177
This commit is contained in:
commit
e46c6a410f
@ -1,9 +1,13 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% import 'bootstrap/wtf.html' as wtf %}
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% macro render_field(field) %}
|
{% macro render_field(field, auth_name=None) %}
|
||||||
<tr style="">
|
<tr style="">
|
||||||
<td class="wtf-field">{{ field.label }}</td>
|
{% if auth_name %}
|
||||||
|
<td class="wtf-field"> {{ field.label }}<span style="font-weight:700;"> ({{ auth_name }}):</span></td>
|
||||||
|
{% else %}
|
||||||
|
<td class="wtf-field">{{ field.label }}</td>
|
||||||
|
{% endif %}
|
||||||
<td class="wtf-field">{{ field(**kwargs)|safe }}
|
<td class="wtf-field">{{ field(**kwargs)|safe }}
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
<ul class=errors>
|
<ul class=errors>
|
||||||
@ -20,16 +24,20 @@
|
|||||||
<h1>Modification du compte ScoDoc <tt>{{form.user_name.data}}</tt></h1>
|
<h1>Modification du compte ScoDoc <tt>{{form.user_name.data}}</tt></h1>
|
||||||
<div class="help">
|
<div class="help">
|
||||||
<p>Identifiez-vous avez votre mot de passe actuel</p>
|
<p>Identifiez-vous avez votre mot de passe actuel</p>
|
||||||
<p>Vous pouvez changer le mot de passe et/ou l'adresse email.</p>
|
|
||||||
<p>Les champs vides ne seront pas changés.</p>
|
|
||||||
</div>
|
</div>
|
||||||
<form method=post>
|
<form method=post>
|
||||||
{{ form.user_name }}
|
{{ form.user_name }}
|
||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
<table class="tf"><tbody>
|
<table class="tf"><tbody>
|
||||||
{{ 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;") }}
|
style="padding:1px; margin-left: 1em; margin-top: 4px;") }}
|
||||||
{{ render_field(form.new_password, size=14,
|
<tr>
|
||||||
|
<td colspan=""2">
|
||||||
|
<p>Vous pouvez changer le mot de passe et/ou l'adresse email.</p>
|
||||||
|
<p>Les champs laissés vides ne seront pas modifiés.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{ render_field(form.new_password, size=14,
|
||||||
style="padding:1px; margin-left: 1em; margin-top: 12px;") }}
|
style="padding:1px; margin-left: 1em; margin-top: 12px;") }}
|
||||||
{{ render_field(form.bis_password, size=14,
|
{{ render_field(form.bis_password, size=14,
|
||||||
style="padding:1px; margin-left: 1em; margin-top: 4px;") }}
|
style="padding:1px; margin-left: 1em; margin-top: 4px;") }}
|
||||||
|
@ -15,4 +15,6 @@
|
|||||||
<p>{{ url_for('auth.reset_password', token=token, _external=True) }}</p>
|
<p>{{ url_for('auth.reset_password', token=token, _external=True) }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p>A bientôt !</p>
|
<p>A bientôt !</p>
|
||||||
|
|
||||||
|
<p>Ce message a été généré automatiquement par le serveur ScoDoc.</p>
|
@ -8,4 +8,6 @@ Votre identifiant de connexion est: {{ user.user_name }}
|
|||||||
{{ url_for('auth.reset_password', token=token, _external=True) }}
|
{{ url_for('auth.reset_password', token=token, _external=True) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p>A bientôt !</p>
|
A bientôt !
|
||||||
|
|
||||||
|
Ce message a été généré automatiquement par le serveur ScoDoc.
|
@ -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
|
||||||
@ -145,6 +152,8 @@ def user_info(user_name, format="json"):
|
|||||||
def create_user_form(user_name=None, edit=0, all_roles=1):
|
def create_user_form(user_name=None, edit=0, all_roles=1):
|
||||||
"form. création ou edition utilisateur"
|
"form. création ou edition utilisateur"
|
||||||
auth_dept = current_user.dept
|
auth_dept = current_user.dept
|
||||||
|
auth_username = current_user.user_name
|
||||||
|
from_mail = current_user.email
|
||||||
initvalues = {}
|
initvalues = {}
|
||||||
edit = int(edit)
|
edit = int(edit)
|
||||||
all_roles = int(all_roles)
|
all_roles = int(all_roles)
|
||||||
@ -529,19 +538,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,14 +577,14 @@ 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
|
||||||
send_email(
|
send_email(
|
||||||
"[ScoDoc] Création de votre compte",
|
"[ScoDoc] Création de votre compte",
|
||||||
sender=current_app.config["ADMINS"][0],
|
sender=from_mail, # 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(
|
html_body=render_template(
|
||||||
@ -787,7 +797,10 @@ def form_change_password(user_name=None):
|
|||||||
return redirect(destination)
|
return redirect(destination)
|
||||||
|
|
||||||
return render_template(
|
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user