Atualizar app/app.py
This commit is contained in:
+67
@@ -56,6 +56,32 @@ def queue_admin_generate():
|
|||||||
# DECORATORS
|
# DECORATORS
|
||||||
# ================
|
# ================
|
||||||
|
|
||||||
|
def require_subscription(f):
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
db = SessionLocal()
|
||||||
|
|
||||||
|
if app.config["AUTH_MODE"] == "oauth":
|
||||||
|
email = session["user"]["email"]
|
||||||
|
else:
|
||||||
|
email = session["db_user"]["email"]
|
||||||
|
|
||||||
|
user = db.query(User).filter_by(email=email).first()
|
||||||
|
plan = db.query(Plan).filter_by(id=user.plan_id).first()
|
||||||
|
sub = db.query(Subscription).filter_by(user_email=email, status="active").first()
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
if not sub:
|
||||||
|
return jsonify({"erro": "Sua assinatura expirou ou não está ativa."}), 402
|
||||||
|
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
def make_cache_key(model, prompt):
|
def make_cache_key(model, prompt):
|
||||||
@@ -441,6 +467,47 @@ def legal_links():
|
|||||||
# ================
|
# ================
|
||||||
# ADMIN
|
# ADMIN
|
||||||
# ================
|
# ================
|
||||||
|
@app.route("/admin/plans")
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def admin_plans():
|
||||||
|
db = SessionLocal()
|
||||||
|
plans = db.query(Plan).all()
|
||||||
|
db.close()
|
||||||
|
return jsonify([{
|
||||||
|
"id": p.id,
|
||||||
|
"name": p.name,
|
||||||
|
"price_monthly": p.price_monthly,
|
||||||
|
"price_yearly": p.price_yearly,
|
||||||
|
"priority_queue": p.priority_queue
|
||||||
|
} for p in plans])
|
||||||
|
|
||||||
|
@app.route("/admin/plans/create", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def admin_create_plan():
|
||||||
|
data = request.json
|
||||||
|
db = SessionLocal()
|
||||||
|
p = Plan(**data)
|
||||||
|
db.add(p)
|
||||||
|
db.commit()
|
||||||
|
db.close()
|
||||||
|
return jsonify({"status": "ok"})
|
||||||
|
|
||||||
|
@app.route("/admin/subscriptions/<email>")
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def admin_subscriptions(email):
|
||||||
|
db = SessionLocal()
|
||||||
|
subs = db.query(Subscription).filter_by(user_email=email).all()
|
||||||
|
db.close()
|
||||||
|
return jsonify([{
|
||||||
|
"id": s.id,
|
||||||
|
"plan_id": s.plan_id,
|
||||||
|
"status": s.status,
|
||||||
|
"renew_at": s.renew_at.isoformat()
|
||||||
|
} for s in subs])
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin/users")
|
@app.route("/admin/users")
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
Reference in New Issue
Block a user