Run: black and isort

This commit is contained in:
2025-10-05 02:28:47 +02:00
parent bd3e23da07
commit 6e9f8a0589
12 changed files with 222 additions and 189 deletions

View File

@@ -1,17 +1,21 @@
import logging
from typing import Optional, Dict, Any
from typing import Any, Dict, Optional
from database.interface import DatabaseInterface
from utils.password_utils import PasswordUtils
from utils.validation import ValidationUtils
logger = logging.getLogger(__name__)
class AuthService:
def __init__(self, database: DatabaseInterface):
self.db = database
def authenticate(self, email: str, password: str) -> tuple[bool, Optional[Dict[str, Any]], str]:
def authenticate(
self, email: str, password: str
) -> tuple[bool, Optional[Dict[str, Any]], str]:
if not ValidationUtils.validate_email(email):
return False, None, "Invalid email format"
@@ -21,10 +25,12 @@ class AuthService:
# User holen
user = self.db.get_user_by_email(email.lower())
if not user:
logger.warning(f"Authentication failed: user not found for email {email}")
logger.warning(
f"Authentication failed: user not found for email {email}"
)
return False, None, "Invalid email or password"
# Passwort prüfen
stored_hash = user.get('password_hash')
stored_hash = user.get("password_hash")
if not stored_hash:
logger.error(f"No password hash found for user {email}")
return False, None, "Authentication error"
@@ -35,14 +41,16 @@ class AuthService:
logger.info(f"Authentication successful for user: {email}")
# Sensible Daten nicht zurückgeben
safe_user_data = {
'id': user['id'],
'username': user['username'],
'email': user['email'],
'created_at': user.get('created_at')
"id": user["id"],
"username": user["username"],
"email": user["email"],
"created_at": user.get("created_at"),
}
return True, safe_user_data, "Authentication successful"
else:
logger.warning(f"Authentication failed: wrong password for email {email}")
logger.warning(
f"Authentication failed: wrong password for email {email}"
)
return False, None, "Invalid email or password"
except Exception as e:

View File

@@ -1,16 +1,20 @@
import logging
from typing import Optional, Dict, Any
from typing import Any, Dict, Optional
from database.interface import DatabaseInterface
from utils.password_utils import PasswordUtils
from utils.validation import ValidationUtils
logger = logging.getLogger(__name__)
class UserService:
def __init__(self, database: DatabaseInterface):
self.db = database
def create_user(self, username: str, email: str, password: str) -> tuple[bool, list[str]]:
def create_user(
self, username: str, email: str, password: str
) -> tuple[bool, list[str]]:
errors = []
# Validierung
@@ -53,7 +57,6 @@ class UserService:
logger.error(f"Error creating user: {e}")
return False, [f"Database error: {str(e)}"]
def get_user_by_email(self, email: str) -> Optional[Dict[str, Any]]:
if not ValidationUtils.validate_email(email):
return None
@@ -70,4 +73,4 @@ class UserService:
return self.db.get_user_by_username(username)
except Exception as e:
logger.error(f"Error getting user by username: {e}")
return None
return None