Compare commits

..

12 Commits

Author SHA1 Message Date
fac7ca4af8 Cleanup 2025-10-16 09:40:31 +02:00
b378275dff Black and ISORT fixes 2025-10-07 09:39:51 +02:00
ad8018ad7e Remove __pycache__ directories and ignore them 2025-10-07 09:37:24 +02:00
f987812860 Fixes 2025-10-07 09:36:42 +02:00
34a592c8db Cleanup 2025-10-07 09:30:13 +02:00
1c46b2dcaf Fixed error in linters 2025-10-07 09:07:04 +02:00
Florian Uhlig
5141af559e Merge pull request #7 from florianuhlig/main
main to Dev
2025-10-07 09:04:14 +02:00
965ba94dd7 test 2025-10-07 09:01:59 +02:00
712abb07d6 Removed Test.txt 2025-10-07 08:58:05 +02:00
d1ba462624 Removed: Test.txt 2025-10-07 08:57:29 +02:00
Florian Uhlig
7818275eee Merge pull request #6 from florianuhlig/Development
Development merge to Main
2025-10-07 08:53:18 +02:00
Florian Uhlig
125a3e76a3 Merge pull request #5 from florianuhlig/Development
Development
2025-10-05 03:07:22 +02:00
22 changed files with 47 additions and 73 deletions

View File

@@ -6,7 +6,7 @@ on:
- Development - Development
jobs: jobs:
build-and-test: Review:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

View File

@@ -5,8 +5,7 @@ on:
branches: branches:
- Development - Development
jobs: jobs:
check: Linters:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository

View File

@@ -1,31 +0,0 @@
name: Unit Test
on:
push:
branches:
- main
jobs:
Unit-Test:
runs-on: ubuntu-latest
steps:
# 1. Check out code
- name: Checkout repository
uses: actions/checkout@v3
# 2. Set up Python
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: '3.9'
# 3. Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest python-dotenv
# 6. Run unit tests
- name: Run pytest
run: pytest

6
.gitignore vendored
View File

@@ -1,6 +0,0 @@
.gitignore
/.idea/
testing.py
/databases/
.venv
.env

View File

@@ -1,7 +1,19 @@
import logging """
from datetime import datetime, timedelta # Add this line at the top Flask frontend application managing user routes and authentication.
"""
from flask import Flask, flash, redirect, render_template, request, session, url_for import logging
from datetime import datetime, timedelta
from flask import (
Flask,
flash,
redirect,
render_template,
request,
session,
url_for,
)
from config.database import DatabaseConfig from config.database import DatabaseConfig
from database import DatabaseFactory from database import DatabaseFactory
@@ -9,11 +21,13 @@ from database.flask_integration import FlaskDatabaseManager
from services.auth_service import AuthService from services.auth_service import AuthService
from services.user_service import UserService from services.user_service import UserService
from utils.auth_decorators import get_current_user, login_required, logout_required from utils.auth_decorators import get_current_user, login_required, logout_required
from utils.password_utils import PasswordUtils
# Logging konfigurieren # Logging konfigurieren
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
app = Flask(__name__) app = Flask(__name__)
app.secret_key = "your-secret-key-change-this-in-production" app.secret_key = "your-secret-key-change-this-in-production"
@@ -26,7 +40,6 @@ app.config["SESSION_COOKIE_SECURE"] = (
) )
app.config["SESSION_COOKIE_HTTPONLY"] = True # Verhindert XSS-Angriffe app.config["SESSION_COOKIE_HTTPONLY"] = True # Verhindert XSS-Angriffe
# Database Manager initialisieren # Database Manager initialisieren
db_config = DatabaseConfig() db_config = DatabaseConfig()
db_type, config = db_config.get_database_config() db_type, config = db_config.get_database_config()
@@ -84,12 +97,12 @@ def register():
if success: if success:
flash("Registration successful! Please log in.", "success") flash("Registration successful! Please log in.", "success")
logger.info(f"New user registered: {email}") logger.info("New user registered: %s", email)
return redirect(url_for("login")) return redirect(url_for("login"))
else:
for error in errors: for error in errors:
flash(error, "error") flash(error, "error")
return redirect(url_for("register")) return redirect(url_for("register"))
return render_template("register.html") return render_template("register.html")
@@ -125,8 +138,8 @@ def login():
if remember_me: if remember_me:
session.permanent = True session.permanent = True
flash(f'Welcome back, {user_data["username"]}!', "success") flash("Welcome back, " + user_data["username"] + "!", "success")
logger.info(f"User logged in: {email}") logger.info("User logged in: %s", email)
# Weiterleitung zu ursprünglich angeforderte Seite (falls vorhanden) # Weiterleitung zu ursprünglich angeforderte Seite (falls vorhanden)
next_page = request.args.get("next") next_page = request.args.get("next")
@@ -134,9 +147,8 @@ def login():
return redirect(next_page) return redirect(next_page)
return redirect(url_for("dashboard")) return redirect(url_for("dashboard"))
else: flash(message, "error")
flash(message, "error") return redirect(url_for("login"))
return redirect(url_for("login"))
return render_template("login.html") return render_template("login.html")
@@ -151,10 +163,10 @@ def logout():
# Session komplett löschen # Session komplett löschen
session.clear() session.clear()
flash(f"Goodbye, {username}! You have been logged out successfully.", "info") flash("Goodbye, " + username + "! You have been logged out successfully.", "info")
if user_email: if user_email:
logger.info(f"User logged out: {user_email}") logger.info("User logged out: %s", user_email)
return redirect(url_for("login")) return redirect(url_for("login"))
@@ -172,7 +184,7 @@ def dashboard():
"session_expires": "Never" if session.permanent else "24 hours", "session_expires": "Never" if session.permanent else "24 hours",
} }
logger.debug(f"Dashboard accessed by user: {user['email']}") logger.debug("Dashboard accessed by user: %s", user["email"])
return render_template("dashboard.html", user=user, dashboard_data=dashboard_data) return render_template("dashboard.html", user=user, dashboard_data=dashboard_data)
@@ -212,24 +224,21 @@ def change_password():
database = db_manager.get_db() database = db_manager.get_db()
auth_service = AuthService(database) auth_service = AuthService(database)
success, _, message = auth_service.authenticate(user["email"], current_password) success = auth_service.authenticate(user["email"], current_password)
if not success: if not success:
flash("Current password is incorrect", "error") flash("Current password is incorrect", "error")
return redirect(url_for("change_password")) return redirect(url_for("change_password"))
# Neues Passwort setzen
from utils.password_utils import PasswordUtils
new_password_hash = PasswordUtils.hash_password_simple(new_password) new_password_hash = PasswordUtils.hash_password_simple(new_password)
if database.update_user_password(user["email"], new_password_hash): if database.update_user_password(user["email"], new_password_hash):
flash("Password changed successfully", "success") flash("Password changed successfully", "success")
logger.info(f"Password changed for user: {user['email']}") logger.info("Password changed for user: %s", user["email"])
return redirect(url_for("dashboard")) return redirect(url_for("dashboard"))
else:
flash("Failed to change password", "error") flash("Failed to change password", "error")
return redirect(url_for("change_password")) return redirect(url_for("change_password"))
return render_template("change_password.html") return render_template("change_password.html")
@@ -237,12 +246,14 @@ def change_password():
# Error Handlers # Error Handlers
@app.errorhandler(404) @app.errorhandler(404)
def not_found(error): def not_found(error):
return render_template("404.html"), 404 """Handles 404 errors."""
return render_template("404.html"), error
@app.errorhandler(500) @app.errorhandler(500)
def internal_error(error): def internal_error(error):
logger.error(f"Internal server error: {error}") """Handles 500 internal server errors."""
logger.error("Internal server error: %s", error)
flash("An internal error occurred. Please try again.", "error") flash("An internal error occurred. Please try again.", "error")
return redirect(url_for("home")) return redirect(url_for("home"))
@@ -251,10 +262,7 @@ def internal_error(error):
@app.before_request @app.before_request
def check_session_timeout(): def check_session_timeout():
"""Prüft ob Session abgelaufen ist""" """Prüft ob Session abgelaufen ist"""
from datetime import datetime
if "user_id" in session: if "user_id" in session:
# Prüfe ob Session zu alt ist (optional)
login_time = session.get("login_time") login_time = session.get("login_time")
if login_time: if login_time:
try: try:

View File

@@ -1,3 +1,5 @@
"""Frontend Flask application module."""
import logging import logging
from typing import Any, Dict, Optional from typing import Any, Dict, Optional

View File

@@ -1,3 +1,5 @@
"""Frontend Flask application module."""
import logging import logging
from typing import Any, Dict, Optional from typing import Any, Dict, Optional