diff --git a/common/djangoapps/user_api/tests/test_views.py b/common/djangoapps/user_api/tests/test_views.py index d712f98211..8c84d3dedd 100644 --- a/common/djangoapps/user_api/tests/test_views.py +++ b/common/djangoapps/user_api/tests/test_views.py @@ -832,9 +832,6 @@ class RegistrationViewTest(ApiTestCase): u"required": True, u"label": u"Email", u"placeholder": u"username@domain.com", - u"instructions": u"The email address you used to register with {platform_name}".format( - platform_name=settings.PLATFORM_NAME - ), u"restrictions": { "min_length": account_api.EMAIL_MIN_LENGTH, "max_length": account_api.EMAIL_MAX_LENGTH @@ -913,9 +910,6 @@ class RegistrationViewTest(ApiTestCase): u"required": True, u"label": u"Email", u"placeholder": u"username@domain.com", - "instructions": "The email address you used to register with {platform_name}".format( - platform_name=settings.PLATFORM_NAME - ), u"restrictions": { "min_length": account_api.EMAIL_MIN_LENGTH, "max_length": account_api.EMAIL_MAX_LENGTH @@ -1354,7 +1348,10 @@ class RegistrationViewTest(ApiTestCase): "honor_code": "true", }) self.assertEqual(response.status_code, 409) - self.assertEqual(response.content, json.dumps(["email"])) + self.assertEqual( + response.content, + "It looks like {} belongs to an existing account.".format(self.EMAIL) + ) def test_register_duplicate_username(self): # Register the first user @@ -1376,7 +1373,10 @@ class RegistrationViewTest(ApiTestCase): "honor_code": "true", }) self.assertEqual(response.status_code, 409) - self.assertEqual(response.content, json.dumps(["username"])) + self.assertEqual( + response.content, + "It looks like {} belongs to an existing account.".format(self.USERNAME) + ) def test_register_duplicate_username_and_email(self): # Register the first user @@ -1398,7 +1398,12 @@ class RegistrationViewTest(ApiTestCase): "honor_code": "true", }) self.assertEqual(response.status_code, 409) - self.assertEqual(response.content, json.dumps(["email", "username"])) + self.assertEqual( + response.content, + "It looks like {} and {} belong to an existing account.".format( + self.EMAIL, self.USERNAME + ) + ) def _assert_reg_field(self, extra_fields_setting, expected_field): """Retrieve the registration form description from the server and diff --git a/common/djangoapps/user_api/views.py b/common/djangoapps/user_api/views.py index 8c4b9ade5a..81b791f18f 100644 --- a/common/djangoapps/user_api/views.py +++ b/common/djangoapps/user_api/views.py @@ -255,16 +255,36 @@ class RegistrationView(APIView): HttpResponse: 302 if redirecting to another page. """ - # Handle duplicate username/email - conflicts = account_api.check_account_exists( - username=request.POST.get('username'), - email=request.POST.get('email') - ) + email = request.POST.get('email') + username = request.POST.get('username') + + # Handle duplicate email/username + conflicts = account_api.check_account_exists(email=email, username=username) if conflicts: + if all(conflict in conflicts for conflict in ['email', 'username']): + # Translators: This message is shown to users who attempt to create a new + # account using both an email address and a username associated with an + # existing account. + error_msg = _( + u"It looks like {email_address} and {username} belong to an existing account." + ).format(email_address=email, username=username) + elif 'email' in conflicts: + # Translators: This message is shown to users who attempt to create a new + # account using an email address associated with an existing account. + error_msg = _( + u"It looks like {email_address} belongs to an existing account." + ).format(email_address=email) + else: + # Translators: This message is shown to users who attempt to create a new + # account using a username associated with an existing account. + error_msg = _( + u"It looks like {username} belongs to an existing account." + ).format(username=username) + return HttpResponse( status=409, - content=json.dumps(conflicts), - content_type="application/json" + content=error_msg, + content_type="text/plain" ) # For the initial implementation, shim the existing login view @@ -281,18 +301,11 @@ class RegistrationView(APIView): # a field on the registration form meant to hold the user's email address. email_placeholder = _(u"username@domain.com") - # Translators: These instructions appear on the registration form, immediately - # below a field meant to hold the user's email address. - email_instructions = _( - u"The email address you used to register with {platform_name}" - ).format(platform_name=settings.PLATFORM_NAME) - form_desc.add_field( "email", field_type="email", label=email_label, placeholder=email_placeholder, - instructions=email_instructions, restrictions={ "min_length": account_api.EMAIL_MIN_LENGTH, "max_length": account_api.EMAIL_MAX_LENGTH,