Commit 0971e371 by Hasnain Committed by hasnain-naveed

Added check for duplication of email

parent 6e861f26
......@@ -243,6 +243,12 @@ class AccountCreationForm(forms.Form):
# reject the registration.
if not CourseEnrollmentAllowed.objects.filter(email=email).exists():
raise ValidationError(_("Unauthorized email address."))
if User.objects.filter(email__iexact=email).exists():
raise ValidationError(
_(
"It looks like {email} belongs to an existing account. Try again with a different email address."
).format(email=email)
)
return email
def clean_year_of_birth(self):
......
......@@ -1899,7 +1899,7 @@ def auto_auth(request):
# the new user object.
try:
user, profile, reg = _do_create_account(form)
except AccountValidationError:
except (AccountValidationError, ValidationError):
# Attempt to retrieve the existing user.
user = User.objects.get(username=username)
user.email = email
......
......@@ -374,7 +374,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase):
self.assertEqual(400, response.status_code)
payload = json.loads(response.content)
self.assertFalse(payload.get('success'))
self.assertIn('already exists', payload.get('value'))
self.assertIn('belongs to an existing account', payload.get('value'))
def assert_json_success_response_looks_correct(self, response):
"""Asserts the json response indicates success and redirection."""
......
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