letzte korrekturen und aufräumen

This commit is contained in:
2025-02-19 21:39:15 +01:00
parent e097facef7
commit 3757658539
4 changed files with 152 additions and 102 deletions

View File

@@ -546,6 +546,50 @@ def dashboard():
# SUPPORT & SETTINGS ROUTEN (Aus V1)
# ------------------------------------------------------------
@app.route('/delete_notification/<int:notif_id>', methods=['POST'])
def delete_notification(notif_id):
if 'user_id' not in session:
flash("Bitte melde dich an!", "red")
return redirect(url_for('login'))
user_id = session['user_id']
db = get_db()
# Prüfen, ob die Notification existiert
row = db.execute("""
SELECT user_id
FROM notifications
WHERE id=?
""", (notif_id,)).fetchone()
if not row:
flash("Benachrichtigung existiert nicht.", "red")
return redirect(url_for('dashboard'))
# Wenn user_id = NULL => globale Notification
# Du kannst selbst definieren, ob jeder sie löschen darf oder nur Admin
# Hier: Jeder kann globale Notification löschen, wenn er sie sieht.
# Oder du sagst: Nur Admin kann globale Notis löschen -> if row['user_id'] is None and not is_admin(): ...
if row['user_id'] is None:
# Optional: Nur Admin löschen
if not is_admin():
flash('Nicht erlaubt', 'red')
return redirect(url_for('dashboard'))
pass
else:
# Wenn es eine user-spezifische Notification ist: user_id muss übereinstimmen
if row['user_id'] != user_id:
flash("Keine Berechtigung, diese Benachrichtigung zu löschen.", "red")
return redirect(url_for('dashboard'))
# Benachrichtigung löschen
db.execute("DELETE FROM notifications WHERE id=?", (notif_id,))
db.commit()
flash("Benachrichtigung gelöscht!", "green")
return redirect(url_for('dashboard'))
@app.route('/send_support_message', methods=['POST'])
def send_support_message():
"""
@@ -665,6 +709,7 @@ def add_bookmarks_multi():
if not target_list:
flash("Bitte mindestens einen Benutzer auswählen!", "red")
return redirect(url_for('admin_panel'))
icon = request.form.get('icon_class')
db = get_db()
for uid in target_list:

View File

@@ -1,154 +1,150 @@
<!-- templates/admin.html -->
{% extends "base.html" %}
{% block title %}
Admin-Bereich
{% endblock title %}
{% block content %}
<div class="container mx-auto py-8 px-4">
<h1 class="text-3xl font-bold text-center mb-6">Admin-Bereich</h1>
<div class="container mx-auto px-4 sm:px-6 lg:px-8 py-10">
<h1 class="text-3xl font-bold text-center mb-8">Admin-Bereich</h1>
<!-- Flash-Messages -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="bg-{{category}}-500 text-white p-2 rounded mb-2">
<div class="bg-{{ category }}-500 text-white p-3 rounded mb-4">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
<!-- Grid Layout für 4 Spalten / Boxen -->
<div class="grid gap-6 md:grid-cols-2 xl:grid-cols-4">
<!-- Grid Layout für Boxen -->
<div class="grid gap-8 sm:grid-cols-1 md:grid-cols-2 xl:grid-cols-4">
<!-- NEUEN BENUTZER ANLEGEN -->
<div class="glassmorphism p-4 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-3">Neuen Benutzer anlegen</h2>
<form method="POST" action="{{ url_for('admin_panel') }}" class="space-y-3">
<div>
<label class="block">Benutzername:</label>
<input type="text" name="new_username" required class="w-full p-2 rounded" />
</div>
<div>
<label class="block">Passwort:</label>
<input type="password" name="new_password" required class="w-full p-2 rounded" />
</div>
<div class="flex items-center space-x-2">
<input type="checkbox" name="new_is_admin" class="h-4 w-4" />
<span>Als Admin markieren</span>
</div>
<button type="submit" class="bg-green-600 text-white py-2 px-4 rounded shadow hover:bg-green-700">
Erstellen
</button>
<div class="glassmorphism p-6 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-4">Neuen Benutzer anlegen</h2>
<form method="POST" action="{{ url_for('admin_panel') }}" class="space-y-4">
<div>
<label class="block mb-1 font-medium">Benutzername:</label>
<input type="text" name="new_username" required class="w-full p-3 rounded border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
</div>
<div>
<label class="block mb-1 font-medium">Passwort:</label>
<input type="password" name="new_password" required class="w-full p-3 rounded border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
</div>
<div class="flex items-center space-x-2">
<input type="checkbox" name="new_is_admin" class="h-5 w-5 rounded border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
<span class="font-medium">Als Admin markieren</span>
</div>
<button type="submit" class="bg-green-600 hover:bg-green-700 text-white py-3 px-6 rounded shadow transition duration-200">
Erstellen
</button>
</form>
</div>
<!-- BENUTZERVERWALTUNG -->
<div class="glassmorphism p-4 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-3">Benutzerverwaltung</h2>
<table class="w-full table-auto">
<thead>
<tr class="border-b">
<th class="p-2">ID</th>
<th class="p-2">Username</th>
<th class="p-2">Admin?</th>
<th class="p-2">Aktion</th>
</tr>
</thead>
<tbody>
{% for u in users %}
<tr class="border-b">
<td class="p-2">{{ u.id }}</td>
<td class="p-2">{{ u.username }}</td>
<td class="p-2">{{ 'Ja' if u.is_admin else 'Nein' }}</td>
<td class="p-2 space-x-2">
<!-- Lesezeichen-Verwaltung. Auch für eigenen Account. -->
<a href="{{ url_for('manage_bookmarks', user_id=u.id) }}"
class="bg-blue-500 hover:bg-blue-600 text-white px-3 py-1 rounded text-sm">
Lesezeichen
</a>
<!-- User löschen -->
<form method="POST" action="{{ url_for('delete_user', user_id=u.id) }}" class="inline"
onsubmit="return confirm('Benutzer wirklich löschen?')">
<button class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded text-sm">
Löschen
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div style="background-color: transparent !important;" class="glassmorphism p-6 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-4">Benutzerverwaltung</h2>
<div class="overflow-x-auto">
<table class="w-full table-auto">
<thead>
<tr class="border-b">
<th class="p-3 text-left">ID</th>
<th class="p-3 text-left">Username</th>
<th class="p-3 text-left">Admin?</th>
<th class="p-3 text-left">Aktion</th>
</tr>
</thead>
<tbody>
{% for u in users %}
<tr class="border-b">
<td class="p-3">{{ u.id }}</td>
<td class="p-3">{{ u.username }}</td>
<td class="p-3">{{ 'Ja' if u.is_admin else 'Nein' }}</td>
<td class="p-3 space-x-2">
<a href="{{ url_for('manage_bookmarks', user_id=u.id) }}"
style="margin: 10px !important;" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded text-sm transition duration-200">
Lesezeichen
</a>
<form method="POST" action="{{ url_for('delete_user', user_id=u.id) }}" class="inline"
onsubmit="return confirm('Benutzer wirklich löschen?')">
<button style="margin: 10px !important;" class="bg-red-500 text-white px-4 py-2 rounded text-sm transition duration-200">
Löschen
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!-- BENACHRICHTIGUNG ERSTELLEN (MULTI-USER) -->
<div class="glassmorphism p-4 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-3">Benachrichtigung erstellen</h2>
<form method="POST" action="{{ url_for('add_notification_multi') }}" class="space-y-3">
<div class="glassmorphism p-6 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-4">Benachrichtigung erstellen</h2>
<form method="POST" action="{{ url_for('add_notification_multi') }}" class="space-y-4">
<div>
<label class="block mb-1">Nachricht:</label>
<textarea name="message" rows="2" required class="w-full p-2 rounded"></textarea>
<label class="block mb-1 font-medium">Nachricht:</label>
<textarea name="message" rows="3" required class="w-full p-3 rounded border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400"></textarea>
</div>
<div>
<p class="mb-1">Für welche Benutzer?</p>
<!-- Checkboxen oder Multi-Select -->
<p class="mb-2 font-medium">Für welche Benutzer?</p>
<div class="flex flex-wrap gap-2">
<label class="inline-flex items-center gap-1 bg-gray-200 dark:bg-gray-800 p-1 rounded"
<label class="inline-flex items-center gap-1 bg-gray-200 dark:bg-gray-800 p-2 rounded cursor-pointer"
for="notify_all">
<input type="checkbox" id="notify_all" name="target_users" value="all" />
<input type="checkbox" id="notify_all" name="target_users" value="all" class="h-5 w-5 rounded border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
Alle
</label>
{% for u in users %}
<label class="inline-flex items-center gap-1 bg-gray-200 dark:bg-gray-800 p-1 rounded">
<input type="checkbox" name="target_users" value="{{ u.id }}" />
<label class="inline-flex items-center gap-1 bg-gray-200 dark:bg-gray-800 p-2 rounded cursor-pointer">
<input type="checkbox" name="target_users" value="{{ u.id }}" class="h-5 w-5 rounded border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
{{ u.username }}
</label>
{% endfor %}
</div>
</div>
<button type="submit" class="bg-purple-500 hover:bg-purple-600 text-white px-4 py-2 rounded">
<button type="submit" class="bg-purple-500 hover:bg-purple-600 text-white px-6 py-3 rounded shadow transition duration-200">
Senden
</button>
</form>
</div>
<!-- LESEZEICHEN-VERWALTUNG (MULTI-USER) -->
<div class="glassmorphism p-4 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-3">Lesezeichen-Verwaltung</h2>
<form method="POST" action="{{ url_for('add_bookmarks_multi') }}" class="space-y-3">
<p>Für welche Benutzer soll das Lesezeichen gelten?</p>
<div class="glassmorphism p-6 rounded shadow flex flex-col">
<h2 class="text-xl font-semibold mb-4">Lesezeichen-Verwaltung</h2>
<form method="POST" action="{{ url_for('add_bookmarks_multi') }}" class="space-y-4">
<p class="font-medium">Für welche Benutzer soll das Lesezeichen gelten?</p>
<div class="flex flex-wrap gap-2">
{% for u in users %}
<label class="inline-flex items-center gap-1 bg-gray-200 dark:bg-gray-800 p-1 rounded">
<input type="checkbox" name="target_users" value="{{ u.id }}" />
<label class="inline-flex items-center gap-1 bg-gray-200 dark:bg-gray-800 p-2 rounded cursor-pointer">
<input type="checkbox" name="target_users" value="{{ u.id }}" class="h-5 w-5 rounded border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
{{ u.username }}
</label>
{% endfor %}
</div>
<div>
<label class="block mb-1">Titel:</label>
<input type="text" name="title" required class="w-full p-2 rounded" />
<label class="block mb-1 font-medium">Titel:</label>
<input type="text" name="title" required class="w-full p-3 rounded border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
</div>
<div>
<label class="block mb-1">URL:</label>
<input type="text" name="url" required class="w-full p-2 rounded" />
<label class="block mb-1 font-medium">URL:</label>
<input type="text" name="url" required class="w-full p-3 rounded border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
</div>
<div>
<label class="block mb-1">Icon (FontAwesome CSS-Klasse):</label>
<input type="text" name="icon_class" placeholder="z.B. fas fa-user" class="w-full p-2 rounded" />
<label class="block mb-1 font-medium">Icon (FontAwesome CSS-Klasse):</label>
<input type="text" name="icon_class" placeholder="z.B. fas fa-user" class="w-full p-3 rounded border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-400" />
</div>
<button type="submit" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded">
<button type="submit" class="bg-green-600 hover:bg-green-700 text-white px-6 py-3 rounded shadow transition duration-200">
Hinzufügen
</button>
</form>
<!-- Wenn single_user und bookmarks gesetzt, einzelne Liste zeigen -->
{% if single_user and bookmarks %}
<p class="mt-4 mb-2 font-semibold">Lesezeichen für {{ single_user.username }}:</p>
<ul class="space-y-2">
<p class="mt-6 mb-4 font-semibold">Lesezeichen für {{ single_user.username }}:</p>
<ul class="space-y-3">
{% for bm in bookmarks %}
<li class="bg-gray-200 dark:bg-gray-800 p-2 rounded flex justify-between items-center">
<li class="bg-gray-200 dark:bg-gray-800 p-3 rounded flex justify-between items-center">
<div>
<i class="{{ bm.icon_class }} mr-2"></i>
<a href="{{ bm.url }}" target="_blank" class="text-blue-500 hover:underline">
@@ -158,7 +154,7 @@ Admin-Bereich
<form method="POST"
action="{{ url_for('delete_bookmark', bookmark_id=bm.id, user_id=single_user.id) }}"
onsubmit="return confirm('Lesezeichen wirklich löschen?')">
<button class="text-red-500 hover:text-red-700">
<button class="text-red-500 hover:text-red-700 transition duration-200">
<i class="fas fa-trash-alt"></i>
</button>
</form>
@@ -166,14 +162,14 @@ Admin-Bereich
{% endfor %}
</ul>
{% else %}
<p class="text-sm text-gray-400 mt-4">Wähle oben in der Benutzerverwaltung „Lesezeichen“ für einen Nutzer aus, um konkrete Einträge zu sehen.</p>
<p class="text-sm text-gray-400 mt-6">Wähle oben in der Benutzerverwaltung „Lesezeichen“ für einen Nutzer aus, um konkrete Einträge zu sehen.</p>
{% endif %}
</div>
</div> <!-- Grid Ende -->
<a href="{{ url_for('dashboard') }}"
class="inline-block bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded mt-6">
class="inline-block bg-blue-500 hover:bg-blue-600 text-white px-6 py-3 rounded shadow transition duration-200 mt-8">
Zurück zum Dashboard
</a>
</div>

View File

@@ -24,15 +24,15 @@
<!-- Websuche: ohne Input-BG/Border -->
<div class="glassmorphism p-4 shadow-lg mb-6 w-full max-w-lg">
<form id="searchForm" style="background-color: transparent !important;" class="flex flex-col sm:flex-row items-center justify-center">
<input type="text" style="background-color: transparent !important;" id="searchInput" placeholder="Suche..."
<form id="searchForm" style="background-color: transparent !important; padding-bottom: 2px;" class="flex flex-col sm:flex-row items-center justify-center">
<input type="text" style="background-color: transparent !important; padding-bottom: 2px !important;" id="searchInput" placeholder="Suche..."
class="flex-grow bg-transparent border-0 outline-none placeholder-gray-500 text-gray-800
dark:placeholder-gray-300" />
<select id="searchEngine" style="background-color: transparent !important;" class="bg-transparent border-0 outline-none text-gray-800 dark:text-white ml-2">
<select id="searchEngine" style="background-color: transparent !important; padding-bottom: 2px !important;" class="bg-transparent border-0 outline-none text-gray-800 dark:text-white ml-2">
<option value="qwant">Qwant</option>
<option value="google">Google</option>
</select>
<button type="submit" class="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600 ml-2">
<button type="submit" class="bg-green-500 text-white px-2 py-2 rounded hover:bg-green-600 ml-2">
Los
</button>
</form>
@@ -68,12 +68,21 @@
<h2 class="text-lg font-semibold mb-2">Benachrichtigungen</h2>
{% if notifications %}
<ul class="space-y-2 max-h-56 overflow-auto">
{% for note in notifications %}
<li class="bg-gray-100 dark:bg-gray-700 p-2 rounded">
{{ note.message }}<br>
<span class="text-xs text-gray-500">{{ note.created_at }}</span>
</li>
{% endfor %}
{% for note in notifications %}
<li class="bg-gray-100 dark:bg-gray-700 p-2 rounded flex justify-between items-center">
<div>
{{ note.message }}<br>
<span class="text-xs text-gray-500">{{ note.created_at }}</span>
</div>
<form method="POST" action="{{ url_for('delete_notification', notif_id=note.id) }}"
onsubmit="return confirm('Benachrichtigung wirklich löschen?')"
class="inline">
<button class="text-red-500 hover:text-red-700 text-sm ml-2" title="Benachrichtigung löschen">
<i class="fas fa-times"></i>
</button>
</form>
</li>
{% endfor %}
</ul>
{% else %}
<p class="text-sm">Keine neuen Benachrichtigungen</p>

Binary file not shown.