Commit e1dbe343 authored by Raphaël Hertzog's avatar Raphaël Hertzog

django_email_accounts: harden the register form

Also refuse to proceed when the submitted email is already associated
to a User through the main_email field.
parent 23ac2083
......@@ -58,10 +58,13 @@ class UserCreationForm(forms.ModelForm):
# email address.
try:
user_email = UserEmail.objects.get(email=main_email)
if user_email.user is not None:
raise forms.ValidationError(
'The email address is already in use')
except UserEmail.DoesNotExist:
return main_email
pass
if user_email.user is not None:
if User.objects.filter(main_email__iexact=main_email).exists():
raise forms.ValidationError('The email address is already in use')
return main_email
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment