aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-25 11:21:52 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-25 11:21:52 +0100
commita58a34f4d312cfd392477631215821826db4fa3f (patch)
tree79c17d4b987357d0f6e77004c7e070e6910fba8f /api
parent644e0ee607c026831341b1991d1180ef05a0adc5 (diff)
more login_token -> @auth_required
Diffstat (limited to 'api')
-rw-r--r--api/game/accept.py18
-rw-r--r--api/game/info.py1
-rw-r--r--api/game/new.py15
-rw-r--r--api/game/random.py12
-rw-r--r--api/social/request_list.py10
5 files changed, 12 insertions, 44 deletions
diff --git a/api/game/accept.py b/api/game/accept.py
index 66f20b6..36bc018 100644
--- a/api/game/accept.py
+++ b/api/game/accept.py
@@ -5,7 +5,7 @@ import time
import json
import random
from game.socket import game, games
-from auth.login_token import token_login
+from hierarchy import auth_required
from game.info import valid_game_id
from socket_io import io
from game.new import start_game
@@ -13,20 +13,8 @@ from game.new import start_game
join_game = Blueprint('game_accept', __name__)
@join_game.route('/accept', methods = ['POST'])
-def index():
- data = request.get_json()
-
- token = request.cookies.get("token") or ""
- game_id = data.get("id") or ""
-
- if not valid_game_id(game_id): return "", 403
-
- if not token:
- print("a temporary user should be set up here")
-
- user_id = token_login(token)
- if not user_id: return "", 403
-
+@auth_required("user")
+def index(user_id):
if cursor.execute("select status from games where game_id = ?", [game_id]).fetchone()[0] != "wait_for_opponent":
return "", 403
diff --git a/api/game/info.py b/api/game/info.py
index a58edde..030c6ae 100644
--- a/api/game/info.py
+++ b/api/game/info.py
@@ -1,7 +1,6 @@
from flask import Blueprint, request
from functools import reduce
from db import cursor
-from auth.login_token import token_login
from user.info import format_user
from rating import outcome
from ruleset import resolve_ruleset
diff --git a/api/game/new.py b/api/game/new.py
index 8268ea2..5d8d5b7 100644
--- a/api/game/new.py
+++ b/api/game/new.py
@@ -4,7 +4,7 @@ from db import cursor, connection
from socket_io import io
from randid import new_uuid
from game.socket import games, game
-from auth.login_token import token_login
+from hierarchy import auth_required
def create_game(user_1_id, private = False, user_2_id = None):
timestamp = int( time.time() * 1000 )
@@ -34,18 +34,9 @@ def start_game(game_id, user_2_id):
new_game = Blueprint('new_game', __name__)
@new_game.route('/new', methods = ["GET", "POST"])
-def index():
- data = request.get_json()
-
- token = request.cookies.get("token") or ""
- if not token:
- print("a temporary user should be set up here")
-
- user_id = token_login(token)
- if not user_id: return "", 403
-
+@auth_required("user")
+def index(user_id):
game_id = create_game(user_id, True)
-
return { "id": game_id }, 200
dynamic_route = ["/game", new_game]
diff --git a/api/game/random.py b/api/game/random.py
index 096d5be..7e4c512 100644
--- a/api/game/random.py
+++ b/api/game/random.py
@@ -6,20 +6,14 @@ import json
import random
from game.socket import game, games
from game.new import create_game, start_game
-from auth.login_token import token_login
+from hierarchy import auth_required
from socket_io import io
random_game = Blueprint('random', __name__)
@random_game.route('/random')
-def index():
- token = request.cookies.get("token") or ""
- if not token:
- print("a temporary user should be set up here")
-
- user_id = token_login(token)
- if not user_id: return "", 403
-
+@auth_required("user")
+def index(user_id):
public_games = cursor.execute("select game_id from games where private = FALSE and status = \"wait_for_opponent\"").fetchall()
game_started = False
diff --git a/api/social/request_list.py b/api/social/request_list.py
index 56426dc..a2b23d5 100644
--- a/api/social/request_list.py
+++ b/api/social/request_list.py
@@ -1,18 +1,14 @@
from flask import Blueprint, request
from db import cursor, connection
-from auth.login_token import token_login
+from hierarchy import auth_required
from user.info import format_user
import time
requests = Blueprint('requests', __name__)
@requests.route("/requests")
-def route():
- token = request.cookies.get("token") or ""
- if not token: return "", 401
- user_2_id = token_login(token) or ""
- if not user_2_id: return "", 403
-
+@auth_required("user")
+def route(user_2_id):
request_list = cursor.execute("select user_1_id from social where user_2_id = ? and type = \"outgoing\"",
[user_2_id]).fetchall()