modified: app.py
modified: templates/admin_giveaways.html modified: templates/redeem_giveaway.html modified: templates/user_giveaways.html
This commit is contained in:
175
app.py
175
app.py
@@ -411,154 +411,61 @@ def download_logs():
|
||||
return redirect(url_for("landing_page"))
|
||||
|
||||
@app.route("/admin/giveaways", methods=["GET", "POST"])
|
||||
def manage_giveaways():
|
||||
"""Verwalte alle Giveaways (nur für Admins)."""
|
||||
if "discord_user" in session:
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
# Überprüfe, ob der Benutzer Admin-Rechte hat
|
||||
connection = get_db_connection() # Verbindung zur User-Datenbank
|
||||
def admin_giveaways():
|
||||
"""Zeigt eine Liste aller Giveaways an und ermöglicht das Bearbeiten und Sortieren."""
|
||||
if is_admin():
|
||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_id,))
|
||||
user_data = cursor.fetchone()
|
||||
# Sortierung nach bestimmten Feldern
|
||||
sort_field = request.args.get("sort", "id") # Standardmäßig nach 'id' sortieren
|
||||
order = request.args.get("order", "asc") # Standardmäßig aufsteigend sortieren
|
||||
|
||||
if user_data and user_data["permission"] >= 8:
|
||||
connection.close()
|
||||
|
||||
# Verbindung zur Giveaway-Datenbank herstellen
|
||||
giveaway_connection = get_giveaway_db_connection()
|
||||
giveaway_cursor = giveaway_connection.cursor(dictionary=True)
|
||||
|
||||
# Alle Giveaways aus der Giveaway-Datenbank abrufen
|
||||
giveaway_cursor.execute("SELECT * FROM giveaways")
|
||||
giveaways = giveaway_cursor.fetchall()
|
||||
|
||||
giveaway_cursor.close()
|
||||
giveaway_connection.close()
|
||||
|
||||
return render_template("admin_giveaways.html", user_info=user_info, giveaways=giveaways)
|
||||
else:
|
||||
return redirect(url_for("user_dashboard"))
|
||||
# Holen aller Giveaways aus der Datenbank
|
||||
cursor.execute(f"SELECT * FROM giveaways ORDER BY {sort_field} {order}")
|
||||
giveaways = cursor.fetchall()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
return render_template("admin_giveaways.html", giveaways=giveaways, sort_field=sort_field, order=order)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
|
||||
@app.route("/admin/giveaway/edit/<int:id>", methods=["GET", "POST"])
|
||||
def edit_giveaway(id):
|
||||
"""Bearbeite ein bestehendes Giveaway."""
|
||||
if "discord_user" in session:
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
# Überprüfe, ob der Benutzer Admin-Rechte hat
|
||||
connection = get_db_connection()
|
||||
@app.route("/admin/giveaways/edit/<int:giveaway_id>", methods=["GET", "POST"])
|
||||
def edit_giveaway(giveaway_id):
|
||||
"""Bearbeitet ein spezifisches Giveaway."""
|
||||
if is_admin():
|
||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_id,))
|
||||
user_data = cursor.fetchone()
|
||||
if request.method == "POST":
|
||||
platform = request.form.get("platform")
|
||||
name = request.form.get("name")
|
||||
game_key = request.form.get("game_key")
|
||||
winner_dc_id = request.form.get("winner_dc_id")
|
||||
aktiv = bool(request.form.get("aktiv"))
|
||||
|
||||
if user_data and user_data["permission"] >= 8:
|
||||
connection.close()
|
||||
# Update der Giveaways-Daten
|
||||
cursor.execute("""
|
||||
UPDATE giveaways
|
||||
SET platform = %s, name = %s, game_key = %s, winner_dc_id = %s, aktiv = %s
|
||||
WHERE id = %s
|
||||
""", (platform, name, game_key, winner_dc_id, aktiv, giveaway_id))
|
||||
connection.commit()
|
||||
|
||||
giveaway_connection = get_giveaway_db_connection()
|
||||
cursor = giveaway_connection.cursor(dictionary=True)
|
||||
flash("Giveaway updated successfully!", "success")
|
||||
return redirect(url_for("admin_giveaways"))
|
||||
|
||||
if request.method == "POST":
|
||||
platform = request.form["platform"]
|
||||
name = request.form["name"]
|
||||
game_key = request.form["game_key"]
|
||||
winner_dc_id = request.form["winner_dc_id"]
|
||||
|
||||
# Update the giveaway
|
||||
cursor.execute("""
|
||||
UPDATE giveaways
|
||||
SET platform = %s, name = %s, game_key = %s, winner_dc_id = %s
|
||||
WHERE id = %s
|
||||
""", (platform, name, game_key, winner_dc_id, id))
|
||||
giveaway_connection.commit()
|
||||
|
||||
cursor.close()
|
||||
giveaway_connection.close()
|
||||
|
||||
return redirect(url_for("manage_giveaways"))
|
||||
|
||||
# Hole die aktuellen Daten des Giveaways
|
||||
cursor.execute("SELECT * FROM giveaways WHERE id = %s", (id,))
|
||||
giveaway = cursor.fetchone()
|
||||
|
||||
cursor.close()
|
||||
giveaway_connection.close()
|
||||
|
||||
return render_template("edit_giveaway.html", giveaway=giveaway)
|
||||
# Daten des spezifischen Giveaways laden
|
||||
cursor.execute("SELECT * FROM giveaways WHERE id = %s", (giveaway_id,))
|
||||
giveaway = cursor.fetchone()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
return render_template("edit_giveaway.html", giveaway=giveaway)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/admin/giveaway/delete/<int:id>", methods=["POST"])
|
||||
def delete_giveaway(id):
|
||||
"""Lösche ein Giveaway aus der Datenbank."""
|
||||
if "discord_user" in session:
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_id,))
|
||||
user_data = cursor.fetchone()
|
||||
|
||||
if user_data and user_data["permission"] >= 8:
|
||||
connection.close()
|
||||
|
||||
# Verbindung zur Giveaway-Datenbank herstellen
|
||||
giveaway_connection = get_giveaway_db_connection()
|
||||
cursor = giveaway_connection.cursor()
|
||||
|
||||
cursor.execute("DELETE FROM giveaways WHERE id = %s", (id,))
|
||||
giveaway_connection.commit()
|
||||
|
||||
cursor.close()
|
||||
giveaway_connection.close()
|
||||
|
||||
return redirect(url_for("manage_giveaways"))
|
||||
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/admin/giveaway/toggle_active/<int:id>", methods=["POST"])
|
||||
def toggle_active(id):
|
||||
"""Aktiviere oder deaktiviere ein Giveaway."""
|
||||
if "discord_user" in session:
|
||||
user_info = session["discord_user"]
|
||||
user_id = user_info["id"]
|
||||
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_id,))
|
||||
user_data = cursor.fetchone()
|
||||
|
||||
if user_data and user_data["permission"] >= 8:
|
||||
connection.close()
|
||||
|
||||
giveaway_connection = get_giveaway_db_connection()
|
||||
cursor = giveaway_connection.cursor(dictionary=True)
|
||||
|
||||
# Hole den aktuellen Status
|
||||
cursor.execute("SELECT aktiv FROM giveaways WHERE id = %s", (id,))
|
||||
giveaway = cursor.fetchone()
|
||||
|
||||
# Toggle den Aktiv-Status
|
||||
new_status = not giveaway["aktiv"]
|
||||
cursor.execute("UPDATE giveaways SET aktiv = %s WHERE id = %s", (new_status, id))
|
||||
giveaway_connection.commit()
|
||||
|
||||
cursor.close()
|
||||
giveaway_connection.close()
|
||||
|
||||
return redirect(url_for("manage_giveaways"))
|
||||
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/user/giveaways", methods=["GET"])
|
||||
def user_giveaways():
|
||||
|
||||
Reference in New Issue
Block a user