Merge pull request #27 from ThomasRubini/refactor

This commit is contained in:
Thomas Rubini 2023-01-13 09:49:03 +01:00 committed by GitHub
commit 0ee67fafbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View File

@ -158,6 +158,18 @@ def get_game_info(game_id):
else:
return None
def check_username(username):
if not username:
return False
if not username.isalnum():
return False
if not username == username.strip():
return False
if not len(username) < 16:
return False
return True
def generateNpcText(npc: tables.Npc, lang: str) -> dict:
data = {}
data["name"] = getTextFromLid(lang, npc.NAME_LID)

View File

@ -2,7 +2,6 @@ import flask
import json
from truthseeker import APP
from truthseeker.logic import game_logic
from truthseeker.utils import check_username
routes_api = flask.Blueprint("api", __name__)
@ -12,7 +11,7 @@ def create_game():
username = flask.request.values.get("username")
if username==None:
return {"error": 1, "msg": "username not set"}
if not check_username(username):
if not game_logic.check_username(username):
return {"error": 1, "msg": "invalid username"}
response = {}
@ -47,7 +46,7 @@ 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):
if not game_logic.check_username(username):
return {"error": 1, "msg": "invalid username"}
game = game_logic.get_game(game_id)

View File

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