Commit 907d3e9f by Douglas Hall

Merge pull request #11379 from edx/hasnain-naveed/HOL-44-extented

HOL-44 / Added check for duplication of email
parents bea3663e 0971e371
...@@ -243,6 +243,12 @@ class AccountCreationForm(forms.Form): ...@@ -243,6 +243,12 @@ class AccountCreationForm(forms.Form):
# reject the registration. # reject the registration.
if not CourseEnrollmentAllowed.objects.filter(email=email).exists(): if not CourseEnrollmentAllowed.objects.filter(email=email).exists():
raise ValidationError(_("Unauthorized email address.")) 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 return email
def clean_year_of_birth(self): def clean_year_of_birth(self):
......
...@@ -1899,7 +1899,7 @@ def auto_auth(request): ...@@ -1899,7 +1899,7 @@ def auto_auth(request):
# the new user object. # the new user object.
try: try:
user, profile, reg = _do_create_account(form) user, profile, reg = _do_create_account(form)
except AccountValidationError: except (AccountValidationError, ValidationError):
# Attempt to retrieve the existing user. # Attempt to retrieve the existing user.
user = User.objects.get(username=username) user = User.objects.get(username=username)
user.email = email user.email = email
......
...@@ -374,7 +374,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase): ...@@ -374,7 +374,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase):
self.assertEqual(400, response.status_code) self.assertEqual(400, response.status_code)
payload = json.loads(response.content) payload = json.loads(response.content)
self.assertFalse(payload.get('success')) 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): def assert_json_success_response_looks_correct(self, response):
"""Asserts the json response indicates success and redirection.""" """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