From cdc25ad5ec16b330b698d10135f36531d015d5e9 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 17 Apr 2020 18:59:21 +0200 Subject: [PATCH] Send confirmation email if necessary after editing EmailSettingsForm --- users/forms.py | 3 +++ users/views.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/users/forms.py b/users/forms.py index 6fda0847..0e40870e 100644 --- a/users/forms.py +++ b/users/forms.py @@ -857,7 +857,10 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): def __init__(self, *args, **kwargs): prefix = kwargs.pop("prefix", self.Meta.model.__name__) super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs) + + self.should_send_confirmation_email = False self.fields["email"].label = _("Main email address") + if "local_email_redirect" in self.fields: self.fields["local_email_redirect"].label = _("Redirect local emails") if "local_email_enabled" in self.fields: diff --git a/users/views.py b/users/views.py index db41c7d1..027896ed 100644 --- a/users/views.py +++ b/users/views.py @@ -546,6 +546,12 @@ def edit_email_settings(request, user_instance, **_kwargs): if email_settings.changed_data: email_settings.save() messages.success(request, _("The email settings were edited.")) + + # Send confirmation email if necessary + if email_settings.should_send_confirmation_email is True: + user_instance.confirm_email_address_mail(request) + messages.success(request, _("An email to confirm your address was sent.")) + return redirect( reverse("users:profil", kwargs={"userid": str(user_instance.id)}) )