API & Client - allow only alphanumeric characters and '_' in username

This commit is contained in:
Sam
2022-02-13 12:08:24 +01:00
parent 66cd3c9655
commit 94a6f2fa9c
5 changed files with 206 additions and 8 deletions

View File

@ -37,6 +37,21 @@ def check_passwords(password: str, password_conf: str) -> str:
return ret
def check_username(username: str) -> str:
"""
Return if username is valid
"""
ret = ''
if not 2 < len(username) < 13:
ret += 'username: 3 to 12 characters required\n'
if not re.match(r'^[a-zA-Z0-9_]+$', username):
ret += (
'username: only alphanumeric characters and the '
'underscore character "_" allowed\n'
)
return ret
def register_controls(
username: str, email: str, password: str, password_conf: str
) -> str:
@ -45,9 +60,7 @@ def register_controls(
If not, it returns not empty string
"""
ret = ''
if not 2 < len(username) < 13:
ret += 'username: 3 to 12 characters required\n'
ret = check_username(username)
if not is_valid_email(email):
ret += 'email: valid email must be provided\n'
ret += check_passwords(password, password_conf)