updated confirm_email field type (#24205)
* updated confirm_email field type and removed confirm email form v1
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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={
|
||||
|
||||
@@ -1894,7 +1894,7 @@ class RegistrationViewTestV2(RegistrationViewTestV1):
|
||||
{"confirm_email": "required"},
|
||||
{
|
||||
"name": "confirm_email",
|
||||
"type": "text",
|
||||
"type": "email",
|
||||
"required": True,
|
||||
"label": "Confirm Email",
|
||||
"errorMessages": {
|
||||
|
||||
Reference in New Issue
Block a user