modified: app.py
modified: templates/users.html
This commit is contained in:
88
app.py
88
app.py
@@ -130,17 +130,101 @@ def settings():
|
|||||||
|
|
||||||
@app.route("/users")
|
@app.route("/users")
|
||||||
def users():
|
def users():
|
||||||
"""Zeigt eine Liste aller Benutzer aus der Datenbank an."""
|
"""Zeigt eine Liste aller Benutzer an."""
|
||||||
if "username" in session:
|
if "username" in session:
|
||||||
connection = get_db_connection()
|
connection = get_db_connection()
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
cursor.execute("SELECT * FROM user_data")
|
|
||||||
|
cursor.execute("SELECT user_id, username, permission, points, ban FROM user_data")
|
||||||
users = cursor.fetchall()
|
users = cursor.fetchall()
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
return render_template("users.html", users=users)
|
return render_template("users.html", users=users)
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
@app.route("/ban_user/<int:user_id>")
|
||||||
|
def ban_user(user_id):
|
||||||
|
"""Banned einen Benutzer."""
|
||||||
|
if "username" in session:
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("UPDATE user_data SET ban = 1 WHERE user_id = %s", (user_id,))
|
||||||
|
connection.commit()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error banning user: {e}")
|
||||||
|
connection.rollback()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
@app.route("/update_points/<int:user_id>", methods=["POST"])
|
||||||
|
def update_points(user_id):
|
||||||
|
"""Aktualisiert die Punkte eines Benutzers."""
|
||||||
|
if "username" in session:
|
||||||
|
points_change = int(request.form["points_change"])
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("UPDATE user_data SET points = points + %s WHERE user_id = %s", (points_change, user_id))
|
||||||
|
connection.commit()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error updating points: {e}")
|
||||||
|
connection.rollback()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
@app.route("/unban_user/<int:user_id>")
|
||||||
|
def unban_user(user_id):
|
||||||
|
"""Entbannt einen Benutzer."""
|
||||||
|
if "username" in session:
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("UPDATE user_data SET ban = 0 WHERE user_id = %s", (user_id,))
|
||||||
|
connection.commit()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error unbanning user: {e}")
|
||||||
|
connection.rollback()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
@app.route("/update_role/<int:user_id>", methods=["POST"])
|
||||||
|
def update_role(user_id):
|
||||||
|
"""Aktualisiert die Rolle (Berechtigung) eines Benutzers."""
|
||||||
|
if "username" in session:
|
||||||
|
new_permission = request.form["permission"]
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("UPDATE user_data SET permission = %s WHERE user_id = %s", (new_permission, user_id))
|
||||||
|
connection.commit()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error updating role: {e}")
|
||||||
|
connection.rollback()
|
||||||
|
return redirect(url_for("users"))
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
@app.route("/logs")
|
@app.route("/logs")
|
||||||
def view_logs():
|
def view_logs():
|
||||||
"""Zeigt die Logs des Bots im Admin-Panel an."""
|
"""Zeigt die Logs des Bots im Admin-Panel an."""
|
||||||
|
|||||||
@@ -9,37 +9,43 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h1 class="text-center">User Management</h1>
|
<h1 class="text-center">User Management</h1>
|
||||||
<table class="table table-striped mt-4">
|
<table class="table table-bordered mt-4">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>User ID</th>
|
<th>Username</th>
|
||||||
<th>Permission Level</th>
|
<th>Permission Level</th>
|
||||||
<th>Points</th>
|
<th>Points</th>
|
||||||
<th>Ban Status</th>
|
<th>Ban Status</th>
|
||||||
<th>AskMultus Usage</th>
|
<th>Points Management</th>
|
||||||
<th>Filter Value</th>
|
<th>Actions</th>
|
||||||
<th>Rank</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ user.user_id }}</td>
|
<td>{{ user.username }}</td>
|
||||||
<td>{{ user.permission }}</td>
|
|
||||||
<td>{{ user.points }}</td>
|
|
||||||
<td>{{ 'Banned' if user.ban else 'Active' }}</td>
|
|
||||||
<td>{{ user.askmultus }}</td>
|
|
||||||
<td>{{ user.filter_value }}</td>
|
|
||||||
<td>
|
<td>
|
||||||
{% if user.permission == 10 %}
|
<form action="{{ url_for('update_role', user_id=user.user_id) }}" method="POST">
|
||||||
Owner
|
<select name="permission" class="form-control">
|
||||||
{% elif user.permission == 8 %}
|
<option value="0" {% if user.permission == 0 %}selected{% endif %}>User</option>
|
||||||
Admin
|
<option value="5" {% if user.permission == 5 %}selected{% endif %}>Mod</option>
|
||||||
{% elif user.permission == 5 %}
|
<option value="8" {% if user.permission == 8 %}selected{% endif %}>Admin</option>
|
||||||
Mod
|
<option value="10" {% if user.permission == 10 %}selected{% endif %}>Owner</option>
|
||||||
{% else %}
|
</select>
|
||||||
User
|
<button type="submit" class="btn btn-primary mt-2">Update Role</button>
|
||||||
{% endif %}
|
</form>
|
||||||
|
</td>
|
||||||
|
<td>{{ user.points }}</td>
|
||||||
|
<td>{{ "Banned" if user.ban else "Active" }}</td>
|
||||||
|
<td>
|
||||||
|
<form action="{{ url_for('update_points', user_id=user.user_id) }}" method="POST" class="form-inline">
|
||||||
|
<input type="number" name="points_change" class="form-control mr-2" placeholder="Change Points">
|
||||||
|
<button type="submit" class="btn btn-primary">Update</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('ban_user', user_id=user.user_id) }}" class="btn btn-danger">Ban</a>
|
||||||
|
<a href="{{ url_for('unban_user', user_id=user.user_id) }}" class="btn btn-success">Unban</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user