add temporary access when database is empty

This commit is contained in:
Thomas Peetz
2026-02-10 08:36:43 +01:00
parent 69fb3c1e97
commit cc9d54f671
4 changed files with 19 additions and 9 deletions
+10 -4
View File
@@ -13,7 +13,7 @@ from pydantic import ValidationError
from src.core.config import settings
from src.core.log_conf import logger
from src.db.models.admin import Profile
from src.db.repository.admin import get_profile
from src.db.repository.admin import get_profile, is_database_empty
from src.db.session import SessionLocal
from src.schema.admin import ProfileModel, TokenData
@@ -57,11 +57,17 @@ def authenticate_user(username: str, password: str) -> Optional[Profile]:
user = get_profile(username=username, db=db)
logger.debug(user)
if not user:
if is_database_empty(db):
logger.info("database is empty, use temporary access")
user = Profile()
user.email = "init_user@thpeetz.de"
return user
return None
if bcrypt.checkpw(password.encode(), user.password.encode()):
print("User successful authenticated")
else:
logger.info("Authentication failed!")
if bcrypt.checkpw(password.encode(), user.password.encode()):
print("User successful authenticated")
else:
logger.info("Authentication failed!")
return user