diff --git a/openedx/core/djangoapps/user_authn/utils.py b/openedx/core/djangoapps/user_authn/utils.py index e9fddab58f41b6bc141f8d73471fd920bece01eb..2ed90062f136e62ed550dbebf6ee410cb1b8b9c1 100644 --- a/openedx/core/djangoapps/user_authn/utils.py +++ b/openedx/core/djangoapps/user_authn/utils.py @@ -58,3 +58,12 @@ def generate_password(length=12, chars=string.ascii_letters + string.digits): password += choice(string.ascii_letters) password += ''.join([choice(chars) for _i in range(length - 2)]) return password + + +def is_registration_api_v1(request): + """ + Checks if registration api is v1 + :param request: + :return: Bool + """ + return 'v1' in request.get_full_path() and 'register' not in request.get_full_path() diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 965f4c9baeb393a48145cd61ca1acfea1c799714..d9105f4702d23874b5f5c108a0d091f86933b4c7 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -48,7 +48,7 @@ from openedx.core.djangoapps.user_api.accounts.api import ( get_username_existence_validation_error, get_username_validation_error ) -from openedx.core.djangoapps.user_authn.utils import generate_password +from openedx.core.djangoapps.user_authn.utils import generate_password, is_registration_api_v1 from openedx.core.djangoapps.user_api.preferences import api as preferences_api from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies from openedx.core.djangoapps.user_authn.views.registration_form import ( @@ -157,6 +157,10 @@ def create_account_with_params(request, params): 'REGISTRATION_EXTRA_FIELDS', getattr(settings, 'REGISTRATION_EXTRA_FIELDS', {}) ) + if is_registration_api_v1(request): + if 'confirm_email' in extra_fields: + del extra_fields['confirm_email'] + # registration via third party (Google, Facebook) using mobile application # doesn't use social auth pipeline (no redirect uri(s) etc involved). # In this case all related info (required for account linking) diff --git a/openedx/core/djangoapps/user_authn/views/registration_form.py b/openedx/core/djangoapps/user_authn/views/registration_form.py index b3ce0e4b33010c2df1155755b5f2dcb11a320ee1..fbc7ce5344875a49d2195ade99e8977a746a0f71 100644 --- a/openedx/core/djangoapps/user_authn/views/registration_form.py +++ b/openedx/core/djangoapps/user_authn/views/registration_form.py @@ -23,6 +23,7 @@ from edxmako.shortcuts import marketing_link from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api import accounts from openedx.core.djangoapps.user_api.helpers import FormDescription +from openedx.core.djangoapps.user_authn.utils import is_registration_api_v1 as is_api_v1 from openedx.core.djangolib.markup import HTML, Text from openedx.features.enterprise_support.api import enterprise_customer_for_request from student.models import ( @@ -373,7 +374,7 @@ class RegistrationFormFactory(object): Returns: HttpResponse """ - form_desc = FormDescription("post", reverse("user_api_registration")) + form_desc = FormDescription("post", self._get_registration_submit_url(request)) self._apply_third_party_auth_overrides(request, form_desc) # Custom form fields can be added via the form set in settings.REGISTRATION_EXTENSION_FORM @@ -429,16 +430,17 @@ class RegistrationFormFactory(object): form_desc, required=self._is_field_required(field_name) ) - # remove confirm_email form v1 registration form - if 'v1' in request.get_full_path(): + if is_api_v1(request): for index, field in enumerate(form_desc.fields): if field['name'] == 'confirm_email': del form_desc.fields[index] break - return form_desc + def _get_registration_submit_url(self, request): + return reverse("user_api_registration") if is_api_v1(request) else reverse("user_api_registration_v2") + def _add_email_field(self, form_desc, required=True): """Add an email field to a form description. Arguments: @@ -481,6 +483,7 @@ class RegistrationFormFactory(object): form_desc.add_field( "confirm_email", + field_type="email", label=email_label, required=required, error_messages={ diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_register.py b/openedx/core/djangoapps/user_authn/views/tests/test_register.py index d3e83c810ee38718c34f176f07100a44696d8d2e..4a0d7f7a54f33fc0ed4394e672565d9e7a2fd2b5 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -1894,7 +1894,7 @@ class RegistrationViewTestV2(RegistrationViewTestV1): {"confirm_email": "required"}, { "name": "confirm_email", - "type": "text", + "type": "email", "required": True, "label": "Confirm Email", "errorMessages": {