fix: registration form population with unicode through tpa (#30935)

Fixes the registration form username field prefilling with the
third party auth data when unicode usernames are allowed.
This commit is contained in:
Eugene Dyudyunov
2022-09-07 18:59:58 +03:00
committed by GitHub
parent 0be6a7aa93
commit 3d86f8d8de
2 changed files with 40 additions and 2 deletions

View File

@@ -67,8 +67,13 @@ def clean_json(value, of_type):
def clean_username(username=''):
""" Simple helper method to ensure a username is compatible with our system requirements. """
return ('_').join(re.findall(r'[a-zA-Z0-9\-]+', username))[:USERNAME_MAX_LENGTH]
"""
Simple helper method to ensure a username is compatible with our system requirements.
"""
if settings.FEATURES.get("ENABLE_UNICODE_USERNAME"):
return ('_').join(re.findall(settings.USERNAME_REGEX_PARTIAL, username))[:USERNAME_MAX_LENGTH]
else:
return ('_').join(re.findall(r'[a-zA-Z0-9\-]+', username))[:USERNAME_MAX_LENGTH]
class AuthNotConfigured(SocialAuthBaseException):