1
0
forked from ScoDoc/ScoDoc

Merge pull request 'traduction/adaptation messages par défaut ; strip email' (#170) from jmplace/ScoDoc-Lille:change_password_retouches into master

Reviewed-on: https://scodoc.org/git/viennet/ScoDoc/pulls/170
This commit is contained in:
Emmanuel Viennet 2021-10-17 22:04:30 +02:00
commit 63d73c9ecd
2 changed files with 14 additions and 16 deletions

View File

@ -39,14 +39,4 @@
<input type="submit" value="Valider">
<input type="submit" name="cancel" value="Annuler" style="margin-left: 1em;>
</form>
{#<div class="row" style="margin-top: 30px;">#}
{#<div class="col-md-4">Votre identifiant: <b>{{user.user_name}}</b></div>#}
{#</div>#}
{##}
{#<div class="row" style="margin-top: 30px;">#}
{# <div class="col-md-4">#}
{# {{ wtf.quick_form(form) }}#}
{# </div>#}
{#</div>#}
{% endblock %}

View File

@ -79,7 +79,7 @@ _l = _
class ChangePasswordForm(FlaskForm):
user_name = HiddenField()
old_password = PasswordField(_l("Ancien mot de passe"))
old_password = PasswordField(_l("Identifiez-vous"))
new_password = PasswordField(_l("Nouveau mot de passe"))
bis_password = PasswordField(
_l("Répéter"),
@ -90,14 +90,22 @@ class ChangePasswordForm(FlaskForm):
),
],
)
email = StringField(_l("Email"), validators=[DataRequired(), Email()])
email = StringField(
_l("Email"),
validators=[
DataRequired(),
Email(message="adresse email invalide, recommencez"),
],
)
submit = SubmitField()
cancel = SubmitField("Annuler")
def validate_email(self, email):
user = User.query.filter_by(email=email.data).first()
user = User.query.filter_by(email=email.data.strip()).first()
if user is not None and self.user_name.data != user.user_name:
raise ValidationError(_("Adresse e-mail invalide"))
raise ValidationError(
_("Cette adresse e-mail est déjà attribuée à un autre compte")
)
def validate_new_password(self, new_password):
if new_password.data != "" and not is_valid_password(new_password.data):
@ -771,8 +779,8 @@ def form_change_password(user_name=None):
if form.new_password.data != "": # change password
user.set_password(form.new_password.data)
messages.append("Mot de passe modifié")
if form.email.data != user.email: # change email
user.email = form.email.data
if form.email.data.strip() != user.email: # change email
user.email = form.email.data.strip()
messages.append("Adresse email modifiée")
db.session.commit()
flash("\n".join(messages))