check if username is valid

This commit is contained in:
Thomas Rubini 2023-01-05 15:03:04 +01:00
parent 56a77b31c4
commit 45dface44b
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
2 changed files with 14 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import flask
import truthseeker
from truthseeker.logic import game_logic
from truthseeker.utils import check_username
routes_api = flask.Blueprint("api", __name__)
@ -11,7 +12,8 @@ def create_game():
username = flask.request.values.get("username")
if username==None:
return {"error": 1, "msg": "username not set"}
if not check_username(username):
return {"error": 1, "msg": "invalid username"}
response = {}
response["error"] = 0
@ -30,6 +32,8 @@ def join_game():
username = flask.request.values.get("username")
if game_id==None or username==None:
return {"error": 1, "msg": "username or game id not set"}
if not check_username(username):
return {"error": 1, "msg": "invalid username"}
game = game_logic.get_game(game_id)
if game == None:

9
truthseeker/utils.py Normal file
View File

@ -0,0 +1,9 @@
def check_username(username):
if not username:
return False
if not username == username.strip():
return False
if not len(username) < 16:
return False
return True