From a6174bafcfac58d2f6bc3537870d3a3e3b76cc8f Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 15 Jan 2021 10:49:47 +0100 Subject: heb gedeeltelijk user/info geïmplementeerd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/tests.sh | 13 ++++++++++--- api/user/info.py | 27 +++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'api') diff --git a/api/tests.sh b/api/tests.sh index 6608611..002f85f 100755 --- a/api/tests.sh +++ b/api/tests.sh @@ -35,6 +35,15 @@ login_email () { localhost:5000/api/auth/login } +user_info () { + curl -X GET \ + -H "Content-Type: application/json" \ + -d '{ + "username": "loekaars" + }' \ + localhost:5000/api/user/info +} + # login_token () { # curl -X POST \ # -H "Content-Type: application/json" \ @@ -45,7 +54,5 @@ login_email () { # localhost:5000/api/auth/token # } -signup -login_email -login_username +user_info diff --git a/api/user/info.py b/api/user/info.py index 9c08e67..b63e2c9 100644 --- a/api/user/info.py +++ b/api/user/info.py @@ -1,7 +1,30 @@ -from flask import Blueprint +from flask import Blueprint, request +from main import cursor info = Blueprint('info', __name__) @info.route('/info') def index(): - return "user info :tada:" + data = request.get_json() + + username = data.get("username") or "" + id = data.get("id") or "" + + if not username and \ + not id: + return "", 400 + + 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() + + #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], + } -- cgit v1.2.3