From 3d4d0499faf260735eda5e580bfc32107b648078 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:55:06 +0200 Subject: [PATCH] modified: app.py new file: templates/admin_dashboard.html new file: templates/user_dashboard.html --- app.py | 60 +++++++++++++++++++++++++++++++++- templates/admin_dashboard.html | 33 +++++++++++++++++++ templates/user_dashboard.html | 37 +++++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 templates/admin_dashboard.html create mode 100644 templates/user_dashboard.html diff --git a/app.py b/app.py index fc880f1..650b0b0 100644 --- a/app.py +++ b/app.py @@ -126,7 +126,65 @@ def callback(): # Speichere die Benutzerinformationen in der Session session['discord_user'] = user_info - return redirect(url_for("dashboard")) + # Hole Benutzerrollen und andere Daten aus der Datenbank + connection = get_db_connection() + cursor = connection.cursor(dictionary=True) + + cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_info["id"],)) + user_data = cursor.fetchone() + + cursor.close() + connection.close() + + # Weiterleiten basierend auf den Berechtigungen + if user_data and user_data["permission"] >= 8: + return redirect(url_for("admin_dashboard")) + else: + return redirect(url_for("user_dashboard")) + +@app.route("/admin_dashboard") +def admin_dashboard(): + """Zeigt das Admin-Dashboard an (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() + cursor = connection.cursor(dictionary=True) + + cursor.execute("SELECT permission FROM user_data WHERE user_id = %s", (user_id,)) + user_data = cursor.fetchone() + + cursor.close() + connection.close() + + if user_data and user_data["permission"] >= 8: + return render_template("admin_dashboard.html", user_info=user_info) + else: + return redirect(url_for("user_dashboard")) + return redirect(url_for("login")) + +@app.route("/user_dashboard") +def user_dashboard(): + """Zeigt das User-Dashboard an.""" + 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 points, ban FROM user_data WHERE user_id = %s", (user_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) + else: + return "User data not found", 404 + return redirect(url_for("login")) @app.route("/dashboard") def dashboard(): diff --git a/templates/admin_dashboard.html b/templates/admin_dashboard.html new file mode 100644 index 0000000..047124e --- /dev/null +++ b/templates/admin_dashboard.html @@ -0,0 +1,33 @@ + + + + + + Admin Dashboard + + + + + +
+

Welcome, {{ user_info.username }} (Admin)

+

Here you can manage the system and users.

+
+ Manage Users + View Logs +
+
+ + diff --git a/templates/user_dashboard.html b/templates/user_dashboard.html new file mode 100644 index 0000000..8bbcee6 --- /dev/null +++ b/templates/user_dashboard.html @@ -0,0 +1,37 @@ + + + + + + User Dashboard + + + + + +
+

Welcome, {{ user_info.username }}

+

Here you can see your personal data.

+
+

Points: {{ user_data.points }}

+

Status: {{ "Banned" if user_data.ban else "Active" }}

+
+
+ +