modified: app.py
modified: templates/index.html new file: templates/user.html
This commit is contained in:
31
app.py
31
app.py
@@ -2,10 +2,18 @@ from flask import Flask, render_template, redirect, url_for, request, session
|
||||
import os
|
||||
import subprocess
|
||||
import psutil
|
||||
import mysql.connector
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
||||
|
||||
# Verwende Umgebungsvariablen aus Coolify für die Datenbankverbindung
|
||||
DB_HOST = os.getenv("DB_HOST")
|
||||
DB_PORT = os.getenv("DB_PORT")
|
||||
DB_USER = os.getenv("DB_USER")
|
||||
DB_PASS = os.getenv("DB_PASS")
|
||||
DB_NAME = os.getenv("DB_NAME")
|
||||
|
||||
# Globale Variablen für die Intros
|
||||
INTRO_FILE = "introduction.txt"
|
||||
ASKNOTES_INTRO_FILE = "asknotesintro.txt"
|
||||
@@ -50,6 +58,16 @@ def save_text_file(file_path, content):
|
||||
with open(file_path, 'w', encoding='utf-8') as file:
|
||||
file.write(content)
|
||||
|
||||
def get_db_connection():
|
||||
"""Stellt eine Verbindung zur MySQL-Datenbank her."""
|
||||
return mysql.connector.connect(
|
||||
host=DB_HOST,
|
||||
port=DB_PORT,
|
||||
user=DB_USER,
|
||||
password=DB_PASS,
|
||||
database=DB_NAME
|
||||
)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
if "username" in session:
|
||||
@@ -107,5 +125,18 @@ def settings():
|
||||
return render_template("settings.html", introduction=introduction, asknotes_introduction=asknotes_introduction)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/users")
|
||||
def users():
|
||||
"""Zeigt eine Liste aller Benutzer aus der Datenbank an."""
|
||||
if "username" in session:
|
||||
connection = get_db_connection()
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
cursor.execute("SELECT * FROM user_data")
|
||||
users = cursor.fetchall()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return render_template("users.html", users=users)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
|
||||
Reference in New Issue
Block a user