modified: app.py
modified: templates/server_admin_dashboard.html
This commit is contained in:
64
app.py
64
app.py
@@ -291,66 +291,30 @@ def user_server_data(guild_id):
|
|||||||
@app.route("/server_admin_dashboard/<int:guild_id>")
|
@app.route("/server_admin_dashboard/<int:guild_id>")
|
||||||
def server_admin_dashboard(guild_id):
|
def server_admin_dashboard(guild_id):
|
||||||
"""Serverbasiertes Admin-Dashboard für server-spezifische Admin-Rechte."""
|
"""Serverbasiertes Admin-Dashboard für server-spezifische Admin-Rechte."""
|
||||||
user_info = session.get("discord_user")
|
|
||||||
if user_info:
|
|
||||||
user_id = user_info["id"]
|
|
||||||
|
|
||||||
# Überprüfen, ob der Benutzer Admin-Rechte auf dem Server hat
|
|
||||||
if is_server_admin(guild_id):
|
|
||||||
connection = get_db_connection()
|
|
||||||
cursor = connection.cursor(dictionary=True)
|
|
||||||
|
|
||||||
# Hole die Benutzer und Giveaways für den spezifischen Server
|
|
||||||
cursor.execute("SELECT * FROM user_data WHERE guild_id = %s", (guild_id,))
|
|
||||||
users = cursor.fetchall()
|
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s", (guild_id,))
|
|
||||||
giveaways = cursor.fetchall()
|
|
||||||
|
|
||||||
# Hole den Gildennamen aus der guilds-Tabelle
|
|
||||||
cursor.execute("SELECT name FROM guilds WHERE guild_id = %s", (guild_id,))
|
|
||||||
guild_name_result = cursor.fetchone()
|
|
||||||
guild_name = guild_name_result["name"] if guild_name_result else "Unknown Guild"
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
connection.close()
|
|
||||||
|
|
||||||
return render_template("server_admin_dashboard.html",
|
|
||||||
users=users, giveaways=giveaways,
|
|
||||||
guild_id=guild_id, guild_name=guild_name)
|
|
||||||
|
|
||||||
flash("You do not have permission to access this server's admin dashboard.", "danger")
|
|
||||||
return redirect(url_for("user_landing_page"))
|
|
||||||
|
|
||||||
@app.route("/edit_user/<int:guild_id>/<int:user_id>", methods=["GET", "POST"])
|
|
||||||
def edit_user(guild_id, user_id):
|
|
||||||
"""Bearbeitet Benutzerinformationen für einen bestimmten Server."""
|
|
||||||
if is_server_admin(guild_id):
|
if is_server_admin(guild_id):
|
||||||
connection = get_db_connection()
|
connection = get_db_connection()
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
if request.method == "POST":
|
# Giveaways für den Server abrufen
|
||||||
points = request.form["points"]
|
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s", (guild_id,))
|
||||||
level = request.form["level"]
|
giveaways = cursor.fetchall()
|
||||||
permission = request.form["permission"]
|
|
||||||
|
|
||||||
cursor.execute("""
|
# Benutzer auf dem Server abrufen
|
||||||
UPDATE user_data
|
cursor.execute("SELECT * FROM user_data WHERE guild_id = %s", (guild_id,))
|
||||||
SET points = %s, level = %s, permission = %s
|
server_users = cursor.fetchall()
|
||||||
WHERE guild_id = %s AND user_id = %s
|
|
||||||
""", (points, level, permission, guild_id, user_id))
|
|
||||||
connection.commit()
|
|
||||||
|
|
||||||
flash("User data updated successfully!", "success")
|
# Servername aus der guilds-Tabelle holen
|
||||||
return redirect(url_for("server_admin_dashboard", guild_id=guild_id))
|
cursor.execute("SELECT name FROM guilds WHERE guild_id = %s", (guild_id,))
|
||||||
|
guild_name_result = cursor.fetchone()
|
||||||
|
guild_name = guild_name_result["name"] if guild_name_result else "Unknown Guild"
|
||||||
|
|
||||||
cursor.execute("SELECT * FROM user_data WHERE guild_id = %s AND user_id = %s", (guild_id, user_id))
|
|
||||||
user = cursor.fetchone()
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
return render_template("edit_user.html", user=user, guild_id=guild_id)
|
return render_template("server_admin_dashboard.html", giveaways=giveaways, server_users=server_users, guild_id=guild_id, guild_name=guild_name)
|
||||||
return redirect(url_for("landing_page"))
|
|
||||||
|
flash("You do not have permission to access this server's admin dashboard.", "danger")
|
||||||
|
return redirect(url_for("user_landing_page"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/ban_user/<int:guild_id>/<int:user_id>")
|
@app.route("/ban_user/<int:guild_id>/<int:user_id>")
|
||||||
|
|||||||
@@ -3,91 +3,103 @@
|
|||||||
<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>Server Admin Dashboard - {{ guild_name }}</title>
|
<title>Server Admin Dashboard</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>
|
<style>
|
||||||
.table-container {
|
.scrollable-table {
|
||||||
max-height: 400px; /* Begrenzte Höhe für die Tabellen */
|
max-height: 400px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
h2 {
|
.status-badge {
|
||||||
color: #343a40;
|
font-size: 0.9rem;
|
||||||
|
padding: 0.5em;
|
||||||
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include 'navigation.html' %}
|
{% include 'navigation.html' %}
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h2 class="text-center">Server Admin Dashboard for {{ guild_name }}</h2>
|
<h1 class="text-center">Server Admin Dashboard for {{ guild_name }}</h1>
|
||||||
<p class="text-center text-muted">Manage server-specific settings for server <strong>{{ guild_id }}</strong>.</p>
|
<p class="text-center text-muted">Manage server-specific settings and data for server <strong>{{ guild_id }}</strong>.</p>
|
||||||
|
|
||||||
<!-- User Management Section -->
|
<!-- Giveaway Management Section -->
|
||||||
<div class="mt-5">
|
<div class="card mt-4">
|
||||||
<h4>User Management</h4>
|
<div class="card-body">
|
||||||
<div class="table-container">
|
<h5 class="card-title">Giveaway Management</h5>
|
||||||
<table class="table table-striped">
|
<p class="card-text">View and manage all active giveaways for this server.</p>
|
||||||
<thead>
|
<div class="table-responsive scrollable-table">
|
||||||
<tr>
|
<table class="table table-bordered">
|
||||||
<th>Discord ID</th>
|
<thead>
|
||||||
<th>Points</th>
|
<tr>
|
||||||
<th>Level</th>
|
<th>Name</th>
|
||||||
<th>Role</th>
|
<th>Platform</th>
|
||||||
<th>Action</th>
|
<th>Winner</th>
|
||||||
</tr>
|
<th>Status</th>
|
||||||
</thead>
|
<th>Actions</th>
|
||||||
<tbody>
|
</tr>
|
||||||
{% for user in users %}
|
</thead>
|
||||||
<tr>
|
<tbody>
|
||||||
<td>{{ user.user_id }}</td>
|
{% for giveaway in giveaways %}
|
||||||
<td>{{ user.points }}</td>
|
<tr>
|
||||||
<td>{{ user.level }}</td>
|
<td>{{ giveaway.name }}</td>
|
||||||
<td>{{ user.permission }}</td>
|
<td>{{ giveaway.platform }}</td>
|
||||||
<td>
|
<td>{{ giveaway.winner_dc_id }}</td>
|
||||||
<a href="{{ url_for('edit_user', guild_id=guild_id, user_id=user.user_id) }}" class="btn btn-primary btn-sm">Edit</a>
|
<td>
|
||||||
<a href="{{ url_for('ban_user', guild_id=guild_id, user_id=user.user_id) }}" class="btn btn-danger btn-sm">Ban</a>
|
{% if giveaway.aktiv %}
|
||||||
</td>
|
<span class="badge badge-success status-badge">Redeemed</span>
|
||||||
</tr>
|
{% else %}
|
||||||
{% endfor %}
|
<span class="badge badge-warning status-badge">Not Redeemed</span>
|
||||||
</tbody>
|
{% endif %}
|
||||||
</table>
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('edit_giveaway', guild_id=guild_id, uuid=giveaway['uuid']) }}" class="btn btn-primary btn-sm">Edit</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Giveaway Management Section -->
|
<!-- User Management Section -->
|
||||||
<div class="mt-5">
|
<div class="card mt-4">
|
||||||
<h4>Giveaway Management</h4>
|
<div class="card-body">
|
||||||
<div class="table-container">
|
<h5 class="card-title">User Management</h5>
|
||||||
<table class="table table-striped">
|
<p class="card-text">Manage server members' data, including points, bans, and permissions.</p>
|
||||||
<thead>
|
<div class="table-responsive scrollable-table">
|
||||||
<tr>
|
<table class="table table-bordered">
|
||||||
<th>Name</th>
|
<thead>
|
||||||
<th>Platform</th>
|
<tr>
|
||||||
<th>Winner ID</th>
|
<th>User ID</th>
|
||||||
<th>Status</th>
|
<th>Points</th>
|
||||||
<th>Action</th>
|
<th>Level</th>
|
||||||
</tr>
|
<th>Banned</th>
|
||||||
</thead>
|
<th>Actions</th>
|
||||||
<tbody>
|
</tr>
|
||||||
{% for giveaway in giveaways %}
|
</thead>
|
||||||
<tr>
|
<tbody>
|
||||||
<td>{{ giveaway.name }}</td>
|
{% for user in server_users %}
|
||||||
<td>{{ giveaway.platform }}</td>
|
<tr>
|
||||||
<td>{{ giveaway.winner_dc_id }}</td>
|
<td>{{ user.user_id }}</td>
|
||||||
<td>
|
<td>{{ user.points }}</td>
|
||||||
{% if giveaway.aktiv %}
|
<td>{{ user.level }}</td>
|
||||||
<span class="badge badge-success">Redeemed</span>
|
<td>
|
||||||
{% else %}
|
{% if user.ban %}
|
||||||
<span class="badge badge-warning">Not Redeemed</span>
|
<span class="badge badge-danger status-badge">Banned</span>
|
||||||
{% endif %}
|
{% else %}
|
||||||
</td>
|
<span class="badge badge-success status-badge">Active</span>
|
||||||
<td>
|
{% endif %}
|
||||||
<a href="{{ url_for('edit_giveaway', guild_id=guild_id, uuid=giveaway.uuid) }}" class="btn btn-primary btn-sm">Edit</a>
|
</td>
|
||||||
<a href="{{ url_for('delete_giveaway', guild_id=guild_id, uuid=giveaway.uuid) }}" class="btn btn-danger btn-sm">Delete</a>
|
<td>
|
||||||
</td>
|
<a href="{{ url_for('edit_user', guild_id=guild_id, user_id=user.user_id) }}" class="btn btn-primary btn-sm">Edit</a>
|
||||||
</tr>
|
</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
</tbody>
|
{% endfor %}
|
||||||
</table>
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user