diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..a60b3be --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +#ignore = E226,E302,E41 +max-line-length = 130 +max-complexity = 10 diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index c211b2f..31c33e5 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -5,7 +5,7 @@ on: branches: - Development jobs: - on-success: + check: if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest steps: @@ -27,9 +27,3 @@ jobs: - name: Run pylint run: pylint frontend services utils - - on-failure: - if: ${{ github.event.workflow_run.conclusion == 'failure' }} - runs-on: ubuntu-latest - steps: - - run: echo 'The Review workflow failed' diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index c1e9191..9d7ccd1 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -6,7 +6,7 @@ on: - main jobs: - on-success: + Unit-Test: runs-on: ubuntu-latest steps: @@ -28,10 +28,4 @@ jobs: # 6. Run unit tests - name: Run pytest - run: pytest - - on-failure: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'failure' }} - steps: - - run: echo 'The triggering workflow failed' + run: pytest \ No newline at end of file diff --git a/config/__pycache__/database.cpython-312.pyc b/config/__pycache__/database.cpython-312.pyc new file mode 100644 index 0000000..760518b Binary files /dev/null and b/config/__pycache__/database.cpython-312.pyc differ diff --git a/database/__pycache__/__init__.cpython-312.pyc b/database/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..5989d4a Binary files /dev/null and b/database/__pycache__/__init__.cpython-312.pyc differ diff --git a/database/__pycache__/flask_integration.cpython-312.pyc b/database/__pycache__/flask_integration.cpython-312.pyc new file mode 100644 index 0000000..9d821a4 Binary files /dev/null and b/database/__pycache__/flask_integration.cpython-312.pyc differ diff --git a/database/__pycache__/interface.cpython-312.pyc b/database/__pycache__/interface.cpython-312.pyc new file mode 100644 index 0000000..c3b58ab Binary files /dev/null and b/database/__pycache__/interface.cpython-312.pyc differ diff --git a/database/__pycache__/sqlite_db.cpython-312.pyc b/database/__pycache__/sqlite_db.cpython-312.pyc new file mode 100644 index 0000000..8044406 Binary files /dev/null and b/database/__pycache__/sqlite_db.cpython-312.pyc differ diff --git a/database/flask_integration.py b/database/flask_integration.py index 1300051..883becd 100644 --- a/database/flask_integration.py +++ b/database/flask_integration.py @@ -1,6 +1,6 @@ import logging -from flask import current_app, g +from flask import g from .interface import DatabaseInterface diff --git a/database/interface.py b/database/interface.py index 0c05695..841bf1c 100644 --- a/database/interface.py +++ b/database/interface.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional +from typing import Any, Dict, Optional class DatabaseInterface(ABC): diff --git a/database/sqlite_db.py b/database/sqlite_db.py index 1e5074a..6efffda 100644 --- a/database/sqlite_db.py +++ b/database/sqlite_db.py @@ -31,7 +31,7 @@ class SQLiteDatabase(DatabaseInterface): self._local.connection.execute("PRAGMA synchronous=NORMAL") self._local.connection.execute("PRAGMA cache_size=1000") self._local.connection.execute("PRAGMA temp_store=MEMORY") - logger.debug(f"New SQLite connection created for thread") + logger.debug("New SQLite connection created for thread") return self._local.connection @@ -61,14 +61,14 @@ class SQLiteDatabase(DatabaseInterface): try: cursor.execute( """ - CREATE TABLE IF NOT EXISTS users - ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - username TEXT NOT NULL UNIQUE, - email TEXT NOT NULL UNIQUE, - password_hash TEXT NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) - """ + CREATE TABLE IF NOT EXISTS users + ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT NOT NULL UNIQUE, + email TEXT NOT NULL UNIQUE, + password_hash TEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) + """ ) conn.commit() logger.info("User table created/verified") diff --git a/frontend/__pycache__/app.cpython-312.pyc b/frontend/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000..c2a6ba3 Binary files /dev/null and b/frontend/__pycache__/app.cpython-312.pyc differ diff --git a/services/__pycache__/__init__.cpython-312.pyc b/services/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..d7639ef Binary files /dev/null and b/services/__pycache__/__init__.cpython-312.pyc differ diff --git a/services/__pycache__/auth_service.cpython-312.pyc b/services/__pycache__/auth_service.cpython-312.pyc new file mode 100644 index 0000000..cc9e2e4 Binary files /dev/null and b/services/__pycache__/auth_service.cpython-312.pyc differ diff --git a/services/__pycache__/user_service.cpython-312.pyc b/services/__pycache__/user_service.cpython-312.pyc new file mode 100644 index 0000000..feb1a13 Binary files /dev/null and b/services/__pycache__/user_service.cpython-312.pyc differ diff --git a/services/user_service.py b/services/user_service.py index 83fa5b7..e95d1d1 100644 --- a/services/user_service.py +++ b/services/user_service.py @@ -12,39 +12,38 @@ class UserService: def __init__(self, database: DatabaseInterface): self.db = database - def create_user( - self, username: str, email: str, password: str - ) -> tuple[bool, list[str]]: - errors = [] + def create_user(self, username: str, email: str, password: str) -> tuple[bool, list[str]]: + errors = self._validate_user_inputs(username, email, password) + if errors: + return False, errors - # Validierung + errors = self._check_user_existence(username, email) + if errors: + return False, errors + + password_hash = PasswordUtils.hash_password_simple(password) + return self._attempt_user_creation(username, email, password_hash) + + def _validate_user_inputs(self, username: str, email: str, password: str) -> list[str]: + errors = [] if not ValidationUtils.validate_username(username): errors.append("Invalid username format") - if not ValidationUtils.validate_email(email): errors.append("Invalid email format") - password_valid, password_errors = ValidationUtils.validate_password(password) if not password_valid: errors.extend(password_errors) + return errors - if errors: - return False, errors - - # Prüfe auf existierende User + def _check_user_existence(self, username: str, email: str) -> list[str]: + errors = [] if self.get_user_by_email(email): errors.append("Email already registered") - if self.get_user_by_username(username): errors.append("Username already taken") + return errors - if errors: - return False, errors - - # Passwort hashen - password_hash = PasswordUtils.hash_password_simple(password) - - # User erstellen + def _attempt_user_creation(self, username: str, email: str, password_hash: str) -> tuple[bool, list[str]]: try: success = self.db.create_user(username, email.lower(), password_hash) if success: diff --git a/utils/__pycache__/__init__.cpython-312.pyc b/utils/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..f45d26b Binary files /dev/null and b/utils/__pycache__/__init__.cpython-312.pyc differ diff --git a/utils/__pycache__/auth_decorators.cpython-312.pyc b/utils/__pycache__/auth_decorators.cpython-312.pyc new file mode 100644 index 0000000..c64c311 Binary files /dev/null and b/utils/__pycache__/auth_decorators.cpython-312.pyc differ diff --git a/utils/__pycache__/password_utils.cpython-312.pyc b/utils/__pycache__/password_utils.cpython-312.pyc new file mode 100644 index 0000000..fb59076 Binary files /dev/null and b/utils/__pycache__/password_utils.cpython-312.pyc differ diff --git a/utils/__pycache__/validation.cpython-312.pyc b/utils/__pycache__/validation.cpython-312.pyc new file mode 100644 index 0000000..7a3e984 Binary files /dev/null and b/utils/__pycache__/validation.cpython-312.pyc differ