fix: Name field validation issue from lms [VAN-965]

This commit is contained in:
Syed Sajjad Hussain Shah
2022-05-25 14:56:38 +05:00
parent fb9c808939
commit 2fc04e65db
2 changed files with 10 additions and 2 deletions

View File

@@ -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):

View File

@@ -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. """