Browse Source

Case of non existant email (legacy accounts)

fix_crash_email
Gabriel Detraz 6 years ago
parent
commit
ad2c1e3d26
  1. 7
      users/forms.py

7
users/forms.py

@ -144,13 +144,16 @@ class UserCreationForm(FormRevMixin, forms.ModelForm):
super(UserCreationForm, self).__init__(*args, prefix=prefix, **kwargs) super(UserCreationForm, self).__init__(*args, prefix=prefix, **kwargs)
def clean_email(self): def clean_email(self):
if self.cleaned_data.get("email"):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get( if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get(
"email" "email"
): ):
return self.cleaned_data.get("email").lower() return self.cleaned_data.get("email").lower()
else: else:
raise forms.ValidationError( raise forms.ValidationError(
_("You can't use an internal address as your external address.") _("You can't use a {} address.").format(
OptionalUser.objects.first().local_email_domain
)
) )
class Meta: class Meta:
@ -349,6 +352,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
) )
def clean_email(self): def clean_email(self):
if self.cleaned_data.get("email"):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get( if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get(
"email" "email"
): ):
@ -756,6 +760,7 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields["local_email_enabled"].label = _("Use local emails") self.fields["local_email_enabled"].label = _("Use local emails")
def clean_email(self): def clean_email(self):
if self.cleaned_data.get("email"):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get( if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get(
"email" "email"
): ):

Loading…
Cancel
Save