Bug fixing fehlende oder Fehlerhafte Module korrigiert
This commit is contained in:
+7
-1
@@ -11,11 +11,16 @@ WORKDIR /app
|
||||
|
||||
# Backend-Dateien korrekt kopieren
|
||||
COPY backend/app.py ./backend/app.py
|
||||
COPY backend/datenbankverbindung.py ./backend/datenbankverbindung.py
|
||||
COPY backend/util ./backend/util
|
||||
COPY backend/auth ./backend/auth
|
||||
COPY backend/tools ./backend/tools
|
||||
COPY backend/templates ./backend/templates
|
||||
COPY backend/config ./config
|
||||
COPY backend/requirements.txt ./requirements.txt
|
||||
|
||||
COPY backend/setup_routes.py ./backend/setup_routes.py
|
||||
|
||||
|
||||
# Frontend aus Build-Stage übernehmen
|
||||
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
|
||||
|
||||
@@ -24,5 +29,6 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Flask starten
|
||||
WORKDIR /app/backend
|
||||
ENV PYTHONPATH=/app/backend
|
||||
EXPOSE 5000
|
||||
CMD ["python", "app.py"]
|
||||
|
||||
+7
-2
@@ -1,14 +1,19 @@
|
||||
from flask import Flask, send_from_directory, redirect
|
||||
import os
|
||||
import sys
|
||||
if __name__ != '__main__':
|
||||
import sys
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
|
||||
from flask import Flask, send_from_directory, redirect
|
||||
from util.logger import logger
|
||||
from util.db_config import is_configured, load_config, test_connection
|
||||
from util.setup_routes import setup_blueprint
|
||||
from setup_routes import setup_blueprint
|
||||
from auth import auth_bp
|
||||
from tools import md5_blueprint
|
||||
|
||||
app = Flask(__name__, template_folder="templates")
|
||||
|
||||
|
||||
# 📦 Blueprints registrieren
|
||||
app.register_blueprint(setup_blueprint)
|
||||
app.register_blueprint(auth_bp)
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
from flask import Blueprint
|
||||
from auth.login import login_route
|
||||
from auth.logout import logout_route
|
||||
from auth.setup_admin import initialize_admin_user
|
||||
|
||||
auth_bp = Blueprint('auth', __name__)
|
||||
|
||||
# Endpunkte registrieren
|
||||
auth_bp.add_url_rule('/api/login', view_func=login_route, methods=['POST'])
|
||||
auth_bp.add_url_rule('/api/logout', view_func=logout_route, methods=['POST'])
|
||||
|
||||
# exportiere Blueprint und Admin-Setup
|
||||
__all__ = ['auth_bp', 'initialize_admin_user']
|
||||
|
||||
@@ -5,7 +5,7 @@ from datetime import datetime, timedelta
|
||||
import jwt
|
||||
|
||||
from util.logger import logger
|
||||
from util.db_config import load_db_config
|
||||
from util.db_config import load_config
|
||||
from auth.token import SECRET_KEY
|
||||
|
||||
def login_route():
|
||||
@@ -14,7 +14,7 @@ def login_route():
|
||||
password = data.get('password')
|
||||
|
||||
try:
|
||||
config = load_db_config()
|
||||
config = load_config()
|
||||
conn = connect(**config)
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("SELECT * FROM users WHERE username = %s", (username,))
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# auth/setup_admin.py
|
||||
|
||||
import mysql.connector
|
||||
from werkzeug.security import generate_password_hash
|
||||
from util.logger import logger
|
||||
|
||||
def initialize_admin_user(config):
|
||||
try:
|
||||
conn = mysql.connector.connect(**config)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
role VARCHAR(20) NOT NULL
|
||||
)
|
||||
""")
|
||||
|
||||
# 🔍 Prüfe, ob es bereits einen Admin gibt
|
||||
cursor.execute("SELECT COUNT(*) FROM users WHERE role = 'admin'")
|
||||
if cursor.fetchone()[0] == 0:
|
||||
cursor.execute(
|
||||
"INSERT INTO users (username, password, role) VALUES (%s, %s, %s)",
|
||||
("admin", generate_password_hash("admin"), "admin")
|
||||
)
|
||||
logger.info("Admin user created (username: admin, password: admin)")
|
||||
else:
|
||||
logger.info("Admin user already exists.")
|
||||
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Admin-Setup] Failed to initialize admin user: {e}")
|
||||
@@ -1,7 +1,7 @@
|
||||
import time
|
||||
import os
|
||||
from flask import Blueprint, request, render_template, redirect, jsonify
|
||||
from backend.util.db_config import load_config, save_config, test_connection, is_configured
|
||||
from util.db_config import load_config, save_config, test_connection, is_configured
|
||||
from auth.setup_admin import initialize_admin_user
|
||||
from util.logger import logger
|
||||
|
||||
@@ -1 +1 @@
|
||||
from util import setup_routes
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ from util.logger import logger
|
||||
|
||||
CONFIG_PATH = "./config/db_config.json"
|
||||
|
||||
def is_configured():
|
||||
return os.path.exists(CONFIG_PATH)
|
||||
|
||||
def load_config():
|
||||
try:
|
||||
with open(CONFIG_PATH, "r") as f:
|
||||
|
||||
Reference in New Issue
Block a user