From 0971e3715a4b15b042a28877ccd9b5fa6f1beaf1 Mon Sep 17 00:00:00 2001 From: Hasnain Date: Fri, 29 Jan 2016 17:49:50 +0500 Subject: [PATCH] Added check for duplication of email --- common/djangoapps/student/forms.py | 6 ++++++ common/djangoapps/student/views.py | 2 +- common/djangoapps/third_party_auth/tests/specs/base.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/student/forms.py b/common/djangoapps/student/forms.py index dd3e462531..5150e1a704 100644 --- a/common/djangoapps/student/forms.py +++ b/common/djangoapps/student/forms.py @@ -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): diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index c79f6bb187..89040c6dc6 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -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 diff --git a/common/djangoapps/third_party_auth/tests/specs/base.py b/common/djangoapps/third_party_auth/tests/specs/base.py index b510c26106..84ab7e07e6 100644 --- a/common/djangoapps/third_party_auth/tests/specs/base.py +++ b/common/djangoapps/third_party_auth/tests/specs/base.py @@ -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."""