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 bf0f6120f7..6ca5234e26 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -792,8 +792,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. """