modified: app.py
new file: templates/edit_user.html
This commit is contained in:
34
app.py
34
app.py
@@ -316,6 +316,40 @@ def server_admin_dashboard(guild_id):
|
|||||||
flash("You do not have permission to access this server's admin dashboard.", "danger")
|
flash("You do not have permission to access this server's admin dashboard.", "danger")
|
||||||
return redirect(url_for("user_landing_page"))
|
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 die Daten eines spezifischen Benutzers auf einem bestimmten Server."""
|
||||||
|
if is_server_admin(guild_id):
|
||||||
|
connection = get_db_connection()
|
||||||
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
points = int(request.form.get("points", 0))
|
||||||
|
level = int(request.form.get("level", 1))
|
||||||
|
ban = int(request.form.get("ban", 0))
|
||||||
|
|
||||||
|
# Update der Benutzerdaten
|
||||||
|
cursor.execute("""
|
||||||
|
UPDATE user_data
|
||||||
|
SET points = %s, level = %s, ban = %s
|
||||||
|
WHERE guild_id = %s AND user_id = %s
|
||||||
|
""", (points, level, ban, guild_id, user_id))
|
||||||
|
connection.commit()
|
||||||
|
|
||||||
|
flash("User data updated successfully!", "success")
|
||||||
|
# Nach dem Speichern zum server_admin_dashboard weiterleiten
|
||||||
|
return redirect(url_for("server_admin_dashboard", guild_id=guild_id))
|
||||||
|
|
||||||
|
# Daten des spezifischen Benutzers laden
|
||||||
|
cursor.execute("SELECT * FROM user_data WHERE guild_id = %s AND user_id = %s", (guild_id, user_id))
|
||||||
|
user_data = cursor.fetchone()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
return render_template("edit_user.html", user_data=user_data, guild_id=guild_id)
|
||||||
|
return redirect(url_for("landing_page"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/ban_user/<int:guild_id>/<int:user_id>")
|
@app.route("/ban_user/<int:guild_id>/<int:user_id>")
|
||||||
def ban_user(guild_id, user_id):
|
def ban_user(guild_id, user_id):
|
||||||
|
|||||||
31
templates/edit_user.html
Normal file
31
templates/edit_user.html
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Edit User</title>
|
||||||
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% include 'navigation.html' %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h2>Edit User - {{ user_data.user_id }}</h2>
|
||||||
|
<form method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="points">Points</label>
|
||||||
|
<input type="number" class="form-control" id="points" name="points" value="{{ user_data.points }}" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="level">Level</label>
|
||||||
|
<input type="number" class="form-control" id="level" name="level" value="{{ user_data.level }}" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="ban" name="ban" value="1" {% if user_data.ban %}checked{% endif %}>
|
||||||
|
<label class="form-check-label" for="ban">Ban User</label>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary mt-3">Save Changes</button>
|
||||||
|
<a href="{{ url_for('server_admin_dashboard', guild_id=guild_id) }}" class="btn btn-secondary mt-3">Back to Dashboard</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user