modified: app.py
modified: templates/admin_giveaways.html
This commit is contained in:
171
app.py
171
app.py
@@ -411,61 +411,154 @@ def download_logs():
|
|||||||
return redirect(url_for("landing_page"))
|
return redirect(url_for("landing_page"))
|
||||||
|
|
||||||
@app.route("/admin/giveaways", methods=["GET", "POST"])
|
@app.route("/admin/giveaways", methods=["GET", "POST"])
|
||||||
def admin_giveaways():
|
def manage_giveaways():
|
||||||
"""Zeigt eine Liste aller Giveaways an und ermöglicht das Bearbeiten und Sortieren."""
|
"""Verwalte alle Giveaways (nur für Admins)."""
|
||||||
if is_admin():
|
if "discord_user" in session:
|
||||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
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
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
# Sortierung nach bestimmten Feldern
|
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_id,))
|
||||||
sort_field = request.args.get("sort", "id") # Standardmäßig nach 'id' sortieren
|
user_data = cursor.fetchone()
|
||||||
order = request.args.get("order", "asc") # Standardmäßig aufsteigend sortieren
|
|
||||||
|
|
||||||
# Holen aller Giveaways aus der Datenbank
|
if user_data and user_data["permission"] >= 8:
|
||||||
cursor.execute(f"SELECT * FROM giveaways ORDER BY {sort_field} {order}")
|
connection.close()
|
||||||
giveaways = cursor.fetchall()
|
|
||||||
|
|
||||||
cursor.close()
|
# Verbindung zur Giveaway-Datenbank herstellen
|
||||||
connection.close()
|
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"))
|
||||||
|
|
||||||
return render_template("admin_giveaways.html", giveaways=giveaways, sort_field=sort_field, order=order)
|
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
@app.route("/admin/giveaways/edit/<int:giveaway_id>", methods=["GET", "POST"])
|
|
||||||
def edit_giveaway(giveaway_id):
|
@app.route("/admin/giveaway/edit/<int:id>", methods=["GET", "POST"])
|
||||||
"""Bearbeitet ein spezifisches Giveaway."""
|
def edit_giveaway(id):
|
||||||
if is_admin():
|
"""Bearbeite ein bestehendes Giveaway."""
|
||||||
connection = get_giveaway_db_connection() # Verbindung zur Giveaway-Datenbank
|
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()
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
if request.method == "POST":
|
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_id,))
|
||||||
platform = request.form.get("platform")
|
user_data = cursor.fetchone()
|
||||||
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"))
|
|
||||||
|
|
||||||
# Update der Giveaways-Daten
|
if user_data and user_data["permission"] >= 8:
|
||||||
cursor.execute("""
|
connection.close()
|
||||||
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()
|
|
||||||
|
|
||||||
flash("Giveaway updated successfully!", "success")
|
giveaway_connection = get_giveaway_db_connection()
|
||||||
return redirect(url_for("admin_giveaways"))
|
cursor = giveaway_connection.cursor(dictionary=True)
|
||||||
|
|
||||||
# Daten des spezifischen Giveaways laden
|
if request.method == "POST":
|
||||||
cursor.execute("SELECT * FROM giveaways WHERE id = %s", (giveaway_id,))
|
platform = request.form["platform"]
|
||||||
giveaway = cursor.fetchone()
|
name = request.form["name"]
|
||||||
|
game_key = request.form["game_key"]
|
||||||
|
winner_dc_id = request.form["winner_dc_id"]
|
||||||
|
|
||||||
cursor.close()
|
# Update the giveaway
|
||||||
connection.close()
|
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)
|
||||||
|
|
||||||
return render_template("edit_giveaway.html", giveaway=giveaway)
|
|
||||||
return redirect(url_for("login"))
|
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"])
|
@app.route("/user/giveaways", methods=["GET"])
|
||||||
def user_giveaways():
|
def user_giveaways():
|
||||||
|
|||||||
@@ -4,14 +4,8 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Admin - Giveaways</title>
|
<title>Manage Giveaways</title>
|
||||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<style>
|
|
||||||
th a {
|
|
||||||
color: inherit;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -31,12 +25,15 @@
|
|||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h1 class="text-center">Giveaways Management</h1>
|
<h1 class="text-center">Giveaways Management</h1>
|
||||||
<table class="table table-bordered table-hover mt-4">
|
<p class="text-center">Manage all active and inactive giveaways in the system.</p>
|
||||||
<thead class="thead-dark">
|
|
||||||
|
<table class="table table-striped mt-4">
|
||||||
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><a href="{{ url_for('admin_giveaways', sort='id', order='asc' if sort_field == 'id' and order == 'desc' else 'desc') }}">ID</a></th>
|
<th>ID</th>
|
||||||
<th><a href="{{ url_for('admin_giveaways', sort='platform', order='asc' if sort_field == 'platform' and order == 'desc' else 'desc') }}">Platform</a></th>
|
<th>Platform</th>
|
||||||
<th><a href="{{ url_for('admin_giveaways', sort='name', order='asc' if sort_field == 'name' and order == 'desc' else 'desc') }}">Name</a></th>
|
<th>Name</th>
|
||||||
|
<th>UUID</th>
|
||||||
<th>Game Key</th>
|
<th>Game Key</th>
|
||||||
<th>Winner Discord ID</th>
|
<th>Winner Discord ID</th>
|
||||||
<th>Active</th>
|
<th>Active</th>
|
||||||
@@ -49,26 +46,26 @@
|
|||||||
<td>{{ giveaway.id }}</td>
|
<td>{{ giveaway.id }}</td>
|
||||||
<td>{{ giveaway.platform }}</td>
|
<td>{{ giveaway.platform }}</td>
|
||||||
<td>{{ giveaway.name }}</td>
|
<td>{{ giveaway.name }}</td>
|
||||||
|
<td>{{ giveaway.uuid }}</td>
|
||||||
<td>{{ giveaway.game_key }}</td>
|
<td>{{ giveaway.game_key }}</td>
|
||||||
<td>{{ giveaway.winner_dc_id or 'Not Assigned' }}</td>
|
<td>{{ giveaway.winner_dc_id }}</td>
|
||||||
|
<td>{{ 'Yes' if giveaway.aktiv else 'No' }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if giveaway.aktiv %}
|
<a href="{{ url_for('edit_giveaway', id=giveaway.id) }}" class="btn btn-sm btn-primary">Edit</a>
|
||||||
<span class="badge badge-success">Active</span>
|
<form method="POST" action="{{ url_for('delete_giveaway', id=giveaway.id) }}" style="display: inline;">
|
||||||
{% else %}
|
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
|
||||||
<span class="badge badge-danger">Inactive</span>
|
</form>
|
||||||
{% endif %}
|
<form method="POST" action="{{ url_for('toggle_active', id=giveaway.id) }}" style="display: inline;">
|
||||||
</td>
|
<button type="submit" class="btn btn-sm {{ 'btn-success' if not giveaway.aktiv else 'btn-warning' }}">
|
||||||
<td>
|
{{ 'Activate' if not giveaway.aktiv else 'Deactivate' }}
|
||||||
<a href="{{ url_for('edit_giveaway', giveaway_id=giveaway.id) }}" class="btn btn-primary btn-sm">Edit</a>
|
</button>
|
||||||
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user