Compare commits
12 Commits
80a00a379e
...
DevV2
| Author | SHA1 | Date | |
|---|---|---|---|
| fac7ca4af8 | |||
| b378275dff | |||
| ad8018ad7e | |||
| f987812860 | |||
| 34a592c8db | |||
| 1c46b2dcaf | |||
|
|
5141af559e | ||
| 965ba94dd7 | |||
| 712abb07d6 | |||
| d1ba462624 | |||
|
|
7818275eee | ||
|
|
125a3e76a3 |
2
.github/workflows/code-review.yml
vendored
2
.github/workflows/code-review.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
- Development
|
- Development
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
Review:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
|
|||||||
3
.github/workflows/linters.yml
vendored
3
.github/workflows/linters.yml
vendored
@@ -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
|
||||||
|
|||||||
31
.github/workflows/unit-test.yml
vendored
31
.github/workflows/unit-test.yml
vendored
@@ -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
6
.gitignore
vendored
@@ -1,6 +0,0 @@
|
|||||||
.gitignore
|
|
||||||
/.idea/
|
|
||||||
testing.py
|
|
||||||
/databases/
|
|
||||||
.venv
|
|
||||||
.env
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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,9 +97,9 @@ 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"))
|
||||||
@@ -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,7 +147,6 @@ 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"))
|
||||||
|
|
||||||
@@ -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,22 +224,19 @@ 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"))
|
||||||
|
|
||||||
@@ -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:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,5 @@
|
|||||||
|
"""Frontend Flask application module."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"""Frontend Flask application module."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user