From 24abff41064418b02809fb73ebc6ae719a266d6b Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Tue, 21 Apr 2020 18:40:19 +0200 Subject: [PATCH] Fix some email checks being bypassed for legacy users --- users/forms.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/users/forms.py b/users/forms.py index 92d46898..34d5bfa9 100644 --- a/users/forms.py +++ b/users/forms.py @@ -564,11 +564,8 @@ class AdherentEditForm(AdherentForm): original_email = self.user.email new_email = self.cleaned_data.get("email") - # Allow empty emails if the user had an empty email before - if not original_email: - return new_email - - if not new_email: + # Allow empty emails only if the user had an empty email before + if original_email and not new_email: raise forms.ValidationError( _("Email field cannot be empty.") ) @@ -880,11 +877,8 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): original_email = self.user.email new_email = self.cleaned_data.get("email") - # Allow empty emails if the user had an empty email before - if not original_email: - return new_email - - if not new_email: + # Allow empty emails only if the user had an empty email before + if original_email and not new_email: raise forms.ValidationError( _("Email field cannot be empty.") )