From 3c87a971eaf317a220bfca36e035a0fc4388ea19 Mon Sep 17 00:00:00 2001
From: bton
Date: Wed, 18 Sep 2024 22:25:50 +0200
Subject: [PATCH] added a function to transfare money between two user
---
Website/__init__.py | 25 ++++++++++++++++++++++++
Website/templates/base.html | 1 +
Website/templates/transfare.html | 33 ++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+)
create mode 100644 Website/templates/transfare.html
diff --git a/Website/__init__.py b/Website/__init__.py
index 307dace..d942b8e 100644
--- a/Website/__init__.py
+++ b/Website/__init__.py
@@ -283,6 +283,31 @@ def create_app(test_config=None):
socketio.emit("error", "418", to=session[id])
leave_room(session[id])
+ @app.route("/transfare")
+ def transfare():
+ db = get_db()
+ c = db.cursor()
+ c.execute("SELECT * FROM users")
+ user_list = c.fetchall()
+ return render_template("transfare.html", user_list=user_list)
+
+ @app.route("/api/transfare", methods=['POST'])
+ def api_transfare():
+ db = get_db()
+ c = db.cursor()
+ transfare_from = request.form["transfarefrom"]
+ transfare_to = request.form["transfareto"]
+ change = int(request.form["change"]) * 100
+ c.execute("SELECT * FROM users WHERE id=?", [transfare_from])
+ if c.fetchall() == []:
+ return render_template("error.html", error_code="043")
+ c.execute("SELECT * FROM users WHERE id=?", [transfare_to])
+ if c.fetchall() == []:
+ return render_template("error.html", error_code="043")
+ db_handler.change_balance(transfare_from, -change)
+ db_handler.change_balance(transfare_to, change)
+ return render_template("redirect.html")
+
@app.route("/api/balance", methods=['POST', 'GET'])
def api_change():
if request.method == 'POST':
diff --git a/Website/templates/base.html b/Website/templates/base.html
index 69fdd57..cb34bcc 100644
--- a/Website/templates/base.html
+++ b/Website/templates/base.html
@@ -17,6 +17,7 @@
| user and tag list
| Documentation
| transactionlist
+ | transfare
diff --git a/Website/templates/transfare.html b/Website/templates/transfare.html
new file mode 100644
index 0000000..22c1c73
--- /dev/null
+++ b/Website/templates/transfare.html
@@ -0,0 +1,33 @@
+{% extends "base.html" %}
+
+{% block title %}
+ transfare
+{% endblock %}
+{% block content %}
+
+{% endblock %}
+