diff --git a/Website/__init__.py b/Website/__init__.py index dc82896..7e5af6b 100644 --- a/Website/__init__.py +++ b/Website/__init__.py @@ -249,29 +249,41 @@ def create_app(test_config=None): socketio.emit("error", "418", to=session[id]) leave_room(session[id]) - #api - @app.route("/api/balance", methods=['POST']) + @app.route("/api/balance", methods=['POST', 'GET']) def api_change(): - db = get_db() - c = db.cursor() - userid = request.form["id"] - c.execute("SELECT * FROM users WHERE id=?", [userid]) - user_list = c.fetchall() - if user_list != []: - user = user_list[0] - try: - change = int(request.args.get("change")) - except: - change = -1.5 - c.execute(f"UPDATE users SET balance = balance + {change*100} WHERE id={user[0]}") - db.commit() - c.execute(f"SELECT * FROM users WHERE id = {userid}") - user_new = c.fetchone() - log(type="balance", userid=user[0], before=user[2], after=user_new[2]) - socketio.emit("update", "update") - return make_response(json.dumps({"mode":"balance", "username":user[1], "balance":user_new[2]})) - else: - return make_response(json.dumps({"mode":"error","error":"043"})) + if request.method == 'POST': + db = get_db() + c = db.cursor() + userid = request.form["id"] + c.execute("SELECT * FROM users WHERE id=?", [userid]) + user_list = c.fetchall() + if user_list != []: + user = user_list[0] + try: + change = int(request.args.get("change")) + except: + change = -1.5 + c.execute(f"UPDATE users SET balance = balance + {change*100} WHERE id={user[0]}") + db.commit() + c.execute(f"SELECT * FROM users WHERE id = {userid}") + user_new = c.fetchone() + log(type="balance", userid=user[0], before=user[2], after=user_new[2]) + socketio.emit("update", "update") + return make_response(json.dumps({"mode":"balance", "username":user[1], "balance":user_new[2]})) + else: + return make_response(json.dumps({"mode":"error","error":"043"})) + + elif request.method == 'GET': + db = get_db() + c = db.cursor() + userid = reqest.args.get("id") + c.execute("SELECT * FROM users WHERE id=?", [userid]) + user = c.fetchone() + if user != None: + return make_response(json.dumps({"mode":"balance", "username":user[1], "balance":user[2]})) + else: + return make_response(json.dumps({"mode":"error", "error":"043"})) + @app.route("/api/tag_id", methods=['POST']) diff --git a/Website/templates/documentation.html b/Website/templates/documentation.html index a706288..d290e17 100644 --- a/Website/templates/documentation.html +++ b/Website/templates/documentation.html @@ -29,6 +29,7 @@

If change = None or NaN the change will be -1

+

Get method ?id=user_id

Response: {"mode":"error" "error":"{error}"} or