fix: password and initalization emails were only sent to the preferred user email address

This commit is contained in:
Éloi Rivard 2023-11-28 17:59:50 +01:00
parent 15124f29bb
commit aa07059357
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
5 changed files with 10 additions and 6 deletions

View file

@ -7,6 +7,8 @@ Fixed
*****
- Avoid crashing when LDAP groups references unexisting users.
- Password reset and initialization mails were only sent to the
preferred user email address.
- Password reset and initialization mails were not sent at all the user
addresses if one email address could not be reached.

View file

@ -122,9 +122,8 @@ def firstlogin(user):
form.validate()
success = all(
send_password_initialization_mail(user, email) for email in user.emails
)
statuses = [send_password_initialization_mail(user, email) for email in user.emails]
success = all(statuses)
if success:
flash(
_(
@ -175,7 +174,8 @@ def forgotten():
)
return render_template("forgotten-password.html", form=form)
success = all(send_password_reset_mail(user, email) for email in user.emails)
statuses = [send_password_reset_mail(user, email) for email in user.emails]
success = all(statuses)
if success:
flash(success_message, "success")

View file

@ -70,7 +70,7 @@ def send_password_reset_mail(user, mail):
return send_email(
subject=subject,
recipient=user.preferred_email,
recipient=mail,
text=text_body,
html=html_body,
attachements=[(logo_cid, logo_filename, logo_raw)] if logo_filename else None,
@ -111,7 +111,7 @@ def send_password_initialization_mail(user, email):
return send_email(
subject=subject,
recipient=user.preferred_email,
recipient=email,
text=text_body,
html=html_body,
attachements=[(logo_cid, logo_filename, logo_raw)] if logo_filename else None,

View file

@ -148,6 +148,7 @@ def test_user_without_password_first_login(testclient, backend, smtpd):
"You should receive it within a few minutes.",
) in res.flashes
assert len(smtpd.messages) == 2
assert [message["X-RcptTo"] for message in smtpd.messages] == u.emails
assert "Password initialization" in smtpd.messages[0].get("Subject")
u.delete()

View file

@ -40,6 +40,7 @@ def test_password_forgotten_multiple_mails(smtpd, testclient, user):
res.mustcontain("Send again")
assert len(smtpd.messages) == 3
assert [message["X-RcptTo"] for message in smtpd.messages] == user.emails
def test_password_forgotten_invalid_form(smtpd, testclient, user):