From 50a5a556415ba4f5be025be9c4c9dfd8693d72d1 Mon Sep 17 00:00:00 2001 From: Anorak_1 Date: Sun, 30 Oct 2022 23:04:59 +0100 Subject: [PATCH] Modified file: .gitignote Modified to ignore test file Modified file: backend.py Added non-secure first version of Score POST request to / endpoint --- .gitignore | 3 ++- backend.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9bfc4d3..3413432 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -leaderboard.db \ No newline at end of file +leaderboard.db +test.py \ No newline at end of file diff --git a/backend.py b/backend.py index b4d8b3a..bf92c67 100644 --- a/backend.py +++ b/backend.py @@ -1,9 +1,12 @@ from flask import Flask, request from flask_restful import Resource, Api +from flask_cors import CORS import sqlite3 app = Flask("LeaderAPI") +CORS(app) api = Api(app) +#app.config['CORS_HEADERS'] = 'Content-Type' class LeaderAPI(Resource): @@ -16,6 +19,21 @@ class LeaderAPI(Resource): # dictionary of leaderboard is json, encoding using json.dumps results in double encoding with "" and return to browser as type string return list(leaderboard) + def post(self): + data = request.get_json() + print(data) + # Pylance error seems to be fine, no problems I guess + username = data['username'] + time = data['time'] + gamemap = data['map'] + version = str(data['version']) + dbcon = sqlite3.connect("leaderboard.db") + db = dbcon.cursor() + db.execute(f"INSERT INTO leaderboard (time_username, time_time, time_map, time_gamever) VALUES ('{username}', {time}, '{gamemap}', '{version}')") + dbcon.commit() + db.close() + dbcon.close() + class TokenAPI(Resource): def get(self): print(request.remote_addr)