aboutsummaryrefslogtreecommitdiff
path: root/api/user/info.py
blob: 7bf3ee3587cbbce34296626d74188b1db6f61ed5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Blueprint, request
from main import cursor
from auth.login_token import token_login
import json

info = Blueprint('info', __name__)

@info.route('/info', methods = ['GET', 'POST'])
def index():
    data_string = request.data or "{}"
    data = json.loads(data_string)

    username = data.get("username") or ""
    id = data.get("id") or ""
    token = request.cookies.get("token") or ""

    if not username and \
       not id and \
       not token:
           return "", 400

    if token: id = token_login(token)[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()

    #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],
    }