Compare commits
No commits in common. "bc4beb825a8d484f4ef0ad22a69824c00e9e6a87" and "5aae7134695f4920c6c9409fa310575fa79009ba" have entirely different histories.
bc4beb825a
...
5aae713469
3 changed files with 6 additions and 73 deletions
|
|
@ -18,4 +18,3 @@ class Config:
|
|||
|
||||
# Admin
|
||||
ADMIN_KEY = os.getenv('ADMIN_KEY')
|
||||
COLLECT_COOLDOWN = os.getenv('COLLECT_COOLDOWN')
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import mysql.connector
|
||||
from flask import Blueprint
|
||||
from interbend.db import db, get_user
|
||||
from interbend.auth import *
|
||||
import hmac
|
||||
import decimal
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
admin_bp = Blueprint('admin_bp', __name__)
|
||||
|
|
@ -15,13 +13,13 @@ def _keychecker(key):
|
|||
return True
|
||||
|
||||
|
||||
@admin_bp.route('/set-job', methods=['POST'])
|
||||
def set_job():
|
||||
@admin_bp.route('/salary', methods=['POST'])
|
||||
def set_salary():
|
||||
data = request.get_json()
|
||||
bid = data.get('bid')
|
||||
job_id = data.get('job')
|
||||
salary_class = data.get('class')
|
||||
key = data.get('key')
|
||||
if not bid or not job_id or not key:
|
||||
if not bid or not salary_class or not key:
|
||||
return jsonify({"error": "BID, salary class, and key are required"}), 400
|
||||
if not _keychecker(key):
|
||||
return jsonify({"error":"Admin Key required"}), 403
|
||||
|
|
@ -29,41 +27,10 @@ def set_job():
|
|||
if not user:
|
||||
return jsonify({"error": "User not found"}), 404
|
||||
with db.cursor(dictionary=True) as cur:
|
||||
cur.execute("UPDATE user_jobs SET job_id = %s WHERE bid = %s", (job_id, bid))
|
||||
cur.execute("UPDATE users SET salary_class = %s WHERE bid = %s", (salary_class, bid))
|
||||
db.commit()
|
||||
return jsonify({"message": "Salary class updated successfully"}), 200
|
||||
|
||||
@admin_bp.route('/add-money', methods=['POST', 'PATCH'])
|
||||
def add_money():
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({"error": "No data provided"}), 400
|
||||
bid = data.get('bid')
|
||||
amount = data.get('amount')
|
||||
key = data.get('key')
|
||||
if not bid or not money or not key:
|
||||
return jsonify({"error": "BID, Amount and AdminKey are required"}), 400
|
||||
if not _keychecker(key):
|
||||
return jsonify({"error":"Admin Key required"}), 403
|
||||
try:
|
||||
amount_dec = decimal.Decimal(amount)
|
||||
except (ValueError, decimal.InvalidOperation):
|
||||
return jsonify({"error": "Invalid amount"}), 400
|
||||
user = get_user(bid)
|
||||
if not user:
|
||||
return jsonify({"error": "User not found"}), 404
|
||||
balance = user["balance"]
|
||||
new_balance = balance + amount_dec
|
||||
try:
|
||||
with db.cursor(dictionary=True) as cur:
|
||||
cur.execute("UPDATE users SET balance = %s WHERE bid = %s", (new_balance, bid))
|
||||
db.commit()
|
||||
return jsonify({"message": "Money successfully updated!"}), 200
|
||||
except mysql.connector.Error as err:
|
||||
db.rollback()
|
||||
current_app.logger.error(f"Database error in add_money: {err}")
|
||||
return jsonify({"error":"A database error occurred, please try again later."}), 500
|
||||
|
||||
@admin_bp.route('/change-password', methods=['POST', 'PATCH'])
|
||||
def change_password():
|
||||
data = request.get_json()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
from flask import Blueprint
|
||||
|
||||
from config import Config
|
||||
from interbend.db import db, get_user
|
||||
from interbend.auth import *
|
||||
import mysql.connector
|
||||
|
|
@ -15,41 +13,10 @@ def get_balance():
|
|||
return jsonify({"error": "User not found."}), 404
|
||||
return jsonify({"balance": user["balance"]})
|
||||
|
||||
@transactions_bp.route('/collect', methods=['POST'])
|
||||
@jwt_required
|
||||
def collect():
|
||||
user_bid = request.bid
|
||||
data = request.get_json()
|
||||
cooldown = Config.COLLECT_COOLDOWN
|
||||
try:
|
||||
db.start_transaction()
|
||||
with db.cursor(dictionary=True) as cur:
|
||||
query = """
|
||||
SELECT uj.job_id, \
|
||||
uj.collected, \
|
||||
j.salary_class, \
|
||||
s.money AS salary_amount
|
||||
FROM user_jobs uj \
|
||||
JOIN jobs j ON uj.job_id = j.job_id \
|
||||
JOIN salary s ON j.salary_class = s.class
|
||||
WHERE uj.user_bid = %s \
|
||||
"""
|
||||
cur.execute(query, (user_bid,))
|
||||
user_jobs = cur.fetchall()
|
||||
if not user_jobs:
|
||||
db.rollback()
|
||||
return jsonify({"error": "You do not have a job to collect a salary from."}), 400
|
||||
total_payout = 0
|
||||
jobs_collected_count = 0
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
|
||||
|
||||
|
||||
@transactions_bp.route('/transfer', methods=['POST'])
|
||||
@jwt_required
|
||||
def transfer():
|
||||
# Ignore warning because it's dynamically added via jwt required.
|
||||
# Ignore warning because its dynamically added via jwt required.
|
||||
user_bid = request.bid
|
||||
data = request.get_json()
|
||||
fbid = data.get('from')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue