modified: app.py
modified: templates/index.html modified: templates/settings.html
This commit is contained in:
53
app.py
53
app.py
@@ -1,7 +1,6 @@
|
|||||||
from flask import Flask, render_template, redirect, url_for, request, session
|
from flask import Flask, render_template, redirect, url_for, request, session
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import psutil
|
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -11,12 +10,13 @@ app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
|||||||
DB_HOST = os.getenv("DB_HOST")
|
DB_HOST = os.getenv("DB_HOST")
|
||||||
DB_PORT = os.getenv("DB_PORT")
|
DB_PORT = os.getenv("DB_PORT")
|
||||||
DB_USER = os.getenv("DB_USER")
|
DB_USER = os.getenv("DB_USER")
|
||||||
DB_PASS = os.getenv("DB_PASSWORD")
|
DB_PASS = os.getenv("DB_PASS")
|
||||||
DB_NAME = os.getenv("DB_DATABASE")
|
DB_NAME = os.getenv("DB_NAME")
|
||||||
|
|
||||||
# Globale Variablen für die Intros
|
# Globale Variablen für die Intros und Themes
|
||||||
INTRO_FILE = "introduction.txt"
|
INTRO_FILE = "introduction.txt"
|
||||||
ASKNOTES_INTRO_FILE = "asknotesintro.txt"
|
ASKNOTES_INTRO_FILE = "asknotesintro.txt"
|
||||||
|
THEME_FILE = "theme.txt"
|
||||||
|
|
||||||
# Speichern der Prozess-ID
|
# Speichern der Prozess-ID
|
||||||
bot_process = None
|
bot_process = None
|
||||||
@@ -68,6 +68,21 @@ def get_db_connection():
|
|||||||
database=DB_NAME
|
database=DB_NAME
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_current_theme():
|
||||||
|
"""Lädt das aktuelle Theme."""
|
||||||
|
return load_text_file(THEME_FILE) or "light" # Standard-Theme ist 'light'
|
||||||
|
|
||||||
|
def set_current_theme(theme):
|
||||||
|
"""Speichert das aktuelle Theme."""
|
||||||
|
save_text_file(THEME_FILE, theme)
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
if "username" in session:
|
||||||
|
theme = get_current_theme()
|
||||||
|
return render_template("index.html", bot_running=bot_status(), theme=theme)
|
||||||
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
@app.route("/login", methods=["GET", "POST"])
|
@app.route("/login", methods=["GET", "POST"])
|
||||||
def login():
|
def login():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
@@ -78,7 +93,8 @@ def login():
|
|||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
else:
|
else:
|
||||||
return "Invalid credentials!"
|
return "Invalid credentials!"
|
||||||
return render_template("login.html")
|
theme = get_current_theme()
|
||||||
|
return render_template("login.html", theme=theme)
|
||||||
|
|
||||||
@app.route("/logout")
|
@app.route("/logout")
|
||||||
def logout():
|
def logout():
|
||||||
@@ -107,46 +123,33 @@ def settings():
|
|||||||
asknotes_introduction = request.form.get("asknotes_introduction")
|
asknotes_introduction = request.form.get("asknotes_introduction")
|
||||||
theme = request.form.get("theme")
|
theme = request.form.get("theme")
|
||||||
|
|
||||||
# Speichern der Intros
|
# Speichern der Intros und des Themes
|
||||||
save_text_file(INTRO_FILE, introduction)
|
save_text_file(INTRO_FILE, introduction)
|
||||||
save_text_file(ASKNOTES_INTRO_FILE, asknotes_introduction)
|
save_text_file(ASKNOTES_INTRO_FILE, asknotes_introduction)
|
||||||
|
set_current_theme(theme)
|
||||||
# Speichern des ausgewählten Themes in der Session
|
|
||||||
session['theme'] = theme
|
|
||||||
|
|
||||||
return redirect(url_for("settings"))
|
return redirect(url_for("settings"))
|
||||||
|
|
||||||
# Laden der aktuellen Inhalte aus den Textdateien
|
# Laden der aktuellen Inhalte aus den Textdateien
|
||||||
introduction = load_text_file(INTRO_FILE)
|
introduction = load_text_file(INTRO_FILE)
|
||||||
asknotes_introduction = load_text_file(ASKNOTES_INTRO_FILE)
|
asknotes_introduction = load_text_file(ASKNOTES_INTRO_FILE)
|
||||||
|
current_theme = get_current_theme()
|
||||||
|
|
||||||
return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction, theme=session.get('theme', 'light'))
|
return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction, current_theme=current_theme)
|
||||||
return redirect(url_for("login"))
|
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
def index():
|
|
||||||
if "username" in session:
|
|
||||||
# Sicherstellen, dass das Theme gesetzt ist
|
|
||||||
if 'theme' not in session:
|
|
||||||
session['theme'] = 'light' # Standard-Theme setzen
|
|
||||||
return render_template("index.html", bot_running=bot_status(), theme=session['theme'])
|
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
@app.route("/users")
|
@app.route("/users")
|
||||||
def users():
|
def users():
|
||||||
|
"""Zeigt eine Liste aller Benutzer aus der Datenbank an."""
|
||||||
if "username" in session:
|
if "username" in session:
|
||||||
# Sicherstellen, dass das Theme gesetzt ist
|
|
||||||
if 'theme' not in session:
|
|
||||||
session['theme'] = 'light'
|
|
||||||
|
|
||||||
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 * FROM user_data")
|
||||||
users = cursor.fetchall()
|
users = cursor.fetchall()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
theme = get_current_theme()
|
||||||
return render_template("users.html", users=users, theme=session['theme'])
|
return render_template("users.html", users=users, theme=theme)
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link href="{{ url_for('static', filename='css/theme-' + theme + '.css') }}" rel="stylesheet">
|
|
||||||
<title>Admin Panel</title>
|
<title>Admin Panel</title>
|
||||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
<link href="{{ url_for('static', filename='css/' + theme + '.css') }}" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link href="{{ url_for('static', filename='css/theme-' + theme + '.css') }}" rel="stylesheet">
|
|
||||||
<title>Settings</title>
|
<title>Settings</title>
|
||||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
@@ -20,12 +19,13 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="asknotes_introduction">Asknotes Introduction Text</label>
|
<label for="asknotes_introduction">Asknotes Introduction Text</label>
|
||||||
<textarea id="asknotes_introduction" name="asknotes_introduction" class="form-control" rows="5">{{ asknotes_introduction }}</textarea>
|
<textarea id="asknotes_introduction" name="asknotes_introduction" class="form-control" rows="5">{{ asknotes_introduction }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="theme">Select Theme</label>
|
<label for="theme">Select Theme</label>
|
||||||
<select id="theme" name="theme" class="form-control">
|
<select id="theme" name="theme" class="form-control">
|
||||||
<option value="light" {% if theme == 'light' %}selected{% endif %}>Light Theme</option>
|
<option value="light" {% if current_theme == "light" %}selected{% endif %}>Light</option>
|
||||||
<option value="dark" {% if theme == 'dark' %}selected{% endif %}>Dark Theme</option>
|
<option value="dark" {% if current_theme == "dark" %}selected{% endif %}>Dark</option>
|
||||||
|
<option value="blue" {% if current_theme == "blue" %}selected{% endif %}>Blue</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary btn-block">Save Settings</button>
|
<button type="submit" class="btn btn-primary btn-block">Save Settings</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user