modified: app.py
new file: templates/server_admin_dashboard.html new file: templates/server_giveaways.html
This commit is contained in:
114
app.py
114
app.py
@@ -189,8 +189,7 @@ def callback():
|
|||||||
print(f"Error in OAuth2 callback: {e}")
|
print(f"Error in OAuth2 callback: {e}")
|
||||||
flash("Ein Fehler ist beim Authentifizierungsprozess aufgetreten.", "danger")
|
flash("Ein Fehler ist beim Authentifizierungsprozess aufgetreten.", "danger")
|
||||||
return redirect(url_for("landing_page"))
|
return redirect(url_for("landing_page"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/user_server_data/<int:guild_id>")
|
@app.route("/user_server_data/<int:guild_id>")
|
||||||
def user_server_data(guild_id):
|
def user_server_data(guild_id):
|
||||||
"""Zeigt die serverbezogenen Nutzerdaten für den ausgewählten Server an."""
|
"""Zeigt die serverbezogenen Nutzerdaten für den ausgewählten Server an."""
|
||||||
@@ -216,6 +215,76 @@ def user_server_data(guild_id):
|
|||||||
|
|
||||||
return redirect(url_for("landing_page"))
|
return redirect(url_for("landing_page"))
|
||||||
|
|
||||||
|
@app.route("/server_admin_dashboard/<int:guild_id>")
|
||||||
|
def server_admin_dashboard(guild_id):
|
||||||
|
"""Serverbasiertes Admin-Dashboard für server-spezifische Admin-Rechte"""
|
||||||
|
user_info = session.get("discord_user")
|
||||||
|
if user_info:
|
||||||
|
user_id = user_info["id"]
|
||||||
|
|
||||||
|
# Überprüfe, ob der Benutzer Admin-Rechte auf dem spezifischen Server hat
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s AND guild_id = %s", (user_id, guild_id))
|
||||||
|
user_data = cursor.fetchone()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
if user_data and user_data['permission'] >= 8:
|
||||||
|
# Benutzer ist Admin auf diesem Server
|
||||||
|
return render_template("server_admin_dashboard.html", guild_id=guild_id)
|
||||||
|
|
||||||
|
return redirect(url_for("user_landing_page"))
|
||||||
|
|
||||||
|
@app.route("/user_dashboard/<int:guild_id>")
|
||||||
|
def user_dashboard(guild_id):
|
||||||
|
"""Serverbasiertes User-Dashboard"""
|
||||||
|
user_info = session.get("discord_user")
|
||||||
|
if user_info:
|
||||||
|
user_id = user_info["id"]
|
||||||
|
|
||||||
|
# Hole die serverbezogenen Nutzerdaten
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
cursor.execute("SELECT * FROM user_data WHERE user_id = %s AND guild_id = %s", (user_id, guild_id))
|
||||||
|
user_data = cursor.fetchone()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
if user_data:
|
||||||
|
return render_template("user_dashboard.html", user_info=user_info, user_data=user_data, guild_id=guild_id)
|
||||||
|
|
||||||
|
return redirect(url_for("user_landing_page"))
|
||||||
|
|
||||||
|
@app.route("/server_giveaways/<int:guild_id>")
|
||||||
|
def server_giveaways(guild_id):
|
||||||
|
"""Serverbasiertes Giveaway-Management"""
|
||||||
|
user_info = session.get("discord_user")
|
||||||
|
if user_info:
|
||||||
|
user_id = user_info["id"]
|
||||||
|
|
||||||
|
# Überprüfe, ob der Benutzer Admin-Rechte auf diesem Server hat
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
cursor.execute("SELECT permission FROM user_data WHERE user_id = %s AND guild_id = %s", (user_id, guild_id))
|
||||||
|
user_data = cursor.fetchone()
|
||||||
|
|
||||||
|
if user_data and user_data['permission'] >= 8:
|
||||||
|
# Hole die Giveaways für diesen Server
|
||||||
|
cursor.execute("SELECT * FROM giveaway_data WHERE guild_id = %s", (guild_id,))
|
||||||
|
giveaways = cursor.fetchall()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
return render_template("server_giveaways.html", giveaways=giveaways, guild_id=guild_id)
|
||||||
|
|
||||||
|
return redirect(url_for("user_landing_page"))
|
||||||
|
|
||||||
@app.route("/user_landing_page")
|
@app.route("/user_landing_page")
|
||||||
def user_landing_page():
|
def user_landing_page():
|
||||||
@@ -232,41 +301,12 @@ def user_landing_page():
|
|||||||
|
|
||||||
return redirect(url_for("landing_page"))
|
return redirect(url_for("landing_page"))
|
||||||
|
|
||||||
|
@app.route("/global_admin_dashboard")
|
||||||
|
def global_admin_dashboard():
|
||||||
@app.route("/server_selection")
|
"""Globales Admin-Dashboard nur für globale Admins"""
|
||||||
def server_selection():
|
if session.get("is_admin"):
|
||||||
"""Zeigt dem Benutzer eine Liste aller Server an, auf denen er sich befindet und die in der Datenbank vorhanden sind."""
|
return render_template("admin_dashboard.html")
|
||||||
if "discord_user" in session:
|
return redirect(url_for("user_landing_page"))
|
||||||
user_info = session["discord_user"]
|
|
||||||
user_id = user_info["id"]
|
|
||||||
|
|
||||||
connection = get_db_connection()
|
|
||||||
cursor = connection.cursor(dictionary=True)
|
|
||||||
|
|
||||||
# Abfrage der Gilden, auf denen der Benutzer in der Datenbank Einträge hat
|
|
||||||
cursor.execute("""
|
|
||||||
SELECT DISTINCT user_data.guild_id, guilds.name, guilds.icon
|
|
||||||
FROM user_data
|
|
||||||
JOIN guilds ON user_data.guild_id = guilds.guild_id
|
|
||||||
WHERE user_data.user_id = %s
|
|
||||||
""", (user_id,))
|
|
||||||
guilds = cursor.fetchall()
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
connection.close()
|
|
||||||
|
|
||||||
return render_template("server_selection.html", guilds=guilds)
|
|
||||||
|
|
||||||
return redirect(url_for("login"))
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin_dashboard")
|
|
||||||
def admin_dashboard():
|
|
||||||
"""Zeigt das Bot-Admin-Dashboard an (nur für globale Admins)."""
|
|
||||||
if is_bot_admin():
|
|
||||||
return render_template("admin_dashboard.html", bot_running=bot_status())
|
|
||||||
return redirect(url_for("landing_page"))
|
|
||||||
|
|
||||||
@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):
|
||||||
|
|||||||
11
templates/server_admin_dashboard.html
Normal file
11
templates/server_admin_dashboard.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{% include 'navigation.html' %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h1>Admin Dashboard for Server {{ guild_id }}</h1>
|
||||||
|
<p>Manage server-specific settings for this guild.</p>
|
||||||
|
|
||||||
|
<h3>Manage Giveaways</h3>
|
||||||
|
<a href="{{ url_for('server_giveaways', guild_id=guild_id) }}" class="btn btn-primary">View Giveaways</a>
|
||||||
|
|
||||||
|
<h3>Manage Points</h3>
|
||||||
|
<a href="{{ url_for('manage_points', guild_id=guild_id) }}" class="btn btn-primary">Manage Points</a>
|
||||||
|
</div>
|
||||||
29
templates/server_giveaways.html
Normal file
29
templates/server_giveaways.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% include 'navigation.html' %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h1>Giveaways for Server {{ guild_id }}</h1>
|
||||||
|
<a href="{{ url_for('add_giveaway', guild_id=guild_id) }}" class="btn btn-primary">Add Giveaway</a>
|
||||||
|
|
||||||
|
<table class="table mt-4">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Platform</th>
|
||||||
|
<th>Winner</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for giveaway in giveaways %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ giveaway.name }}</td>
|
||||||
|
<td>{{ giveaway.platform }}</td>
|
||||||
|
<td>{{ giveaway.winner_dc_id }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('edit_giveaway', giveaway_id=giveaway.id, guild_id=guild_id) }}" class="btn btn-warning">Edit</a>
|
||||||
|
<a href="{{ url_for('delete_giveaway', giveaway_id=giveaway.id, guild_id=guild_id) }}" class="btn btn-danger">Delete</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user