aboutsummaryrefslogtreecommitdiff
path: root/api/user/info.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-09 15:04:42 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-09 15:04:42 +0100
commitda56acd469aa3dc07f9316f8543f7b32fe29deda (patch)
tree0413d61f01795e91d168070cfcd1cbd6b0cc4a0d /api/user/info.py
parenta024764a6b889d8a07119e71d91cc8a9440c8c20 (diff)
search function working :tada:
Diffstat (limited to 'api/user/info.py')
-rw-r--r--api/user/info.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/api/user/info.py b/api/user/info.py
index edb7743..3d4f4fb 100644
--- a/api/user/info.py
+++ b/api/user/info.py
@@ -3,6 +3,17 @@ from db import cursor
from auth.login_token import token_login
import json
+def format_user(user_id):
+ user = cursor.execute("select username, user_id, country, type, registered, avatar from users where user_id = ?", [user_id]).fetchone()
+ return {
+ "username": user[0],
+ "id": user[1],
+ "country": user[2],
+ "type": user[3],
+ "registered": user[4],
+ "avatar": user[5],
+ }
+
info = Blueprint('info', __name__)
@info.route('/info', methods = ['GET', 'POST'])
@@ -11,29 +22,26 @@ def index():
data = json.loads(data_string)
username = data.get("username") or ""
- id = data.get("id") or ""
+ user_id = data.get("id") or ""
token = request.cookies.get("token") or ""
if not username and \
- not id and \
+ not user_id and \
not token:
return "", 400
- if token: id = token_login(token)
+ if token:
+ user_id = token_login(token)
+ elif username:
+ temp_user_id = cursor.execute("select user_id from users where username = ?", [username]).fetchone()
+ if temp_user_id:
+ user_id = temp_user_id[0]
- if username:
- user = cursor.execute("select username, user_id, country, type, registered, avatar from users where username = ?", [username]).fetchone()
- else:
- user = cursor.execute("select username, user_id, country, type, registered, avatar from users where user_id = ?", [id]).fetchone()
+ user = format_user(user_id)
+
+ if not user: return "", 403
#TODO: rating uitrekenen zodra er game functionaliteit is
- return {
- "username": user[0],
- "id": user[1],
- "country": user[2],
- "type": user[3],
- "registered": user[4],
- "avatar": user[5],
- }
+ return user
dynamic_route = ["/user", info]