8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 06:32:26 +00:00

Send confirmation email if necessary after editing EmailSettingsForm

This commit is contained in:
Jean-Romain Garnier 2020-04-17 18:59:21 +02:00 committed by Jean-Romain Garnier
parent 5feef8ae17
commit 2532f8a142
2 changed files with 9 additions and 0 deletions

View file

@ -857,7 +857,10 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs) super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs)
self.should_send_confirmation_email = False
self.fields["email"].label = _("Main email address") self.fields["email"].label = _("Main email address")
if "local_email_redirect" in self.fields: if "local_email_redirect" in self.fields:
self.fields["local_email_redirect"].label = _("Redirect local emails") self.fields["local_email_redirect"].label = _("Redirect local emails")
if "local_email_enabled" in self.fields: if "local_email_enabled" in self.fields:

View file

@ -546,6 +546,12 @@ def edit_email_settings(request, user_instance, **_kwargs):
if email_settings.changed_data: if email_settings.changed_data:
email_settings.save() email_settings.save()
messages.success(request, _("The email settings were edited.")) 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( return redirect(
reverse("users:profil", kwargs={"userid": str(user_instance.id)}) reverse("users:profil", kwargs={"userid": str(user_instance.id)})
) )