Compare commits
2 commits
4e44457c8d
...
e8c84ba809
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8c84ba809 | ||
|
|
0e73430d70 |
2 changed files with 16 additions and 8 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
.venv
|
.venv/
|
||||||
.env
|
.env
|
||||||
.idea
|
.idea/
|
||||||
|
|
|
||||||
20
app.py
20
app.py
|
|
@ -7,6 +7,7 @@ import mysql.connector
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import jwt
|
import jwt
|
||||||
|
import hmac
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
@ -156,11 +157,17 @@ def transfer():
|
||||||
return jsonify({"error":"User not found"}), 404
|
return jsonify({"error":"User not found"}), 404
|
||||||
if sender["balance"] < amount:
|
if sender["balance"] < amount:
|
||||||
return jsonify({"error": "Insufficient funds"}), 400
|
return jsonify({"error": "Insufficient funds"}), 400
|
||||||
with db.cursor(dictionary=True) as cur:
|
try:
|
||||||
cur.execute("UPDATE users SET balance = balance - %s WHERE bid = %s", (amount, fbid))
|
db.start_transaction()
|
||||||
cur.execute("UPDATE users SET balance = balance + %s WHERE bid = %s", (amount, tbid))
|
with db.cursor(dictionary=True) as cur:
|
||||||
db.commit()
|
cur.execute("UPDATE users SET balance = balance - %s WHERE bid = %s", (amount, fbid))
|
||||||
return jsonify({"message": "Transfer successful"}), 200
|
cur.execute("UPDATE users SET balance = balance + %s WHERE bid = %s", (amount, tbid))
|
||||||
|
db.commit()
|
||||||
|
return jsonify({"message": "Transfer successful"}), 200
|
||||||
|
except mysql.connector.Error as err:
|
||||||
|
db.rollback()
|
||||||
|
print(f"Transactional Error: {err}")
|
||||||
|
return jsonify({"error": "A database error occurred during the transfer."}), 500
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin/change-password', methods=['POST', 'PATCH'])
|
@app.route('/admin/change-password', methods=['POST', 'PATCH'])
|
||||||
|
|
@ -171,7 +178,8 @@ def change_password():
|
||||||
key = data.get('key')
|
key = data.get('key')
|
||||||
if not bid or not new_password or not key:
|
if not bid or not new_password or not key:
|
||||||
return jsonify({"error": "BID, new password, and key are required"}), 400
|
return jsonify({"error": "BID, new password, and key are required"}), 400
|
||||||
if key != os.getenv('ADMIN_KEY'):
|
oskey = os.getenv('ADMIN_KEY')
|
||||||
|
if not oskey or not hmac.compare_digest(key, oskey):
|
||||||
return jsonify({"error": "Admin Key required"}), 403
|
return jsonify({"error": "Admin Key required"}), 403
|
||||||
user = get_user(bid)
|
user = get_user(bid)
|
||||||
if not user:
|
if not user:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue