From 2fc04e65db843d0d59c12b80789f75c52436bb9f Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah Date: Wed, 25 May 2022 14:56:38 +0500 Subject: [PATCH] fix: Name field validation issue from lms [VAN-965] --- openedx/core/djangoapps/user_api/accounts/api.py | 7 ++++++- openedx/core/djangoapps/user_authn/views/register.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/user_api/accounts/api.py b/openedx/core/djangoapps/user_api/accounts/api.py index 754882f2ce..8cc013cb94 100644 --- a/openedx/core/djangoapps/user_api/accounts/api.py +++ b/openedx/core/djangoapps/user_api/accounts/api.py @@ -5,6 +5,7 @@ Programmatic integration point for User API Accounts sub-application import datetime +import re from django.conf import settings from django.core.exceptions import ObjectDoesNotExist @@ -403,7 +404,11 @@ def get_name_validation_error(name): :return: Validation error message. """ - return '' if name else accounts.REQUIRED_FIELD_NAME_MSG + if name: + regex = re.findall(r'https|http?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', name) + return _('Enter a valid name') if bool(regex) else '' + else: + return accounts.REQUIRED_FIELD_NAME_MSG def get_username_validation_error(username): diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 7ba3a8920e..2f73253800 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -795,8 +795,11 @@ class RegistrationValidationView(APIView): def name_handler(self, request): """ Validates whether fullname is valid """ name = request.data.get('name') + validation_error = get_name_validation_error(name) + if validation_error: + return validation_error self.username_suggestions = generate_username_suggestions(name) - return get_name_validation_error(name) + return validation_error def username_handler(self, request): """ Validates whether the username is valid. """