Merge pull request #11379 from edx/hasnain-naveed/HOL-44-extented
HOL-44 / Added check for duplication of email
This commit is contained in:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user