feat: Phase 2 - Authentication and authorization (T-010 to T-013)

This commit is contained in:
2026-02-06 13:15:25 +01:00
parent ec65991ac1
commit 508f0723af
11 changed files with 321 additions and 20 deletions

35
backend/app/seed.py Normal file
View File

@@ -0,0 +1,35 @@
"""
Seed script — creates the initial admin user if it does not already exist.
Usage:
python -m app.seed
"""
from app.auth import hash_password
from app.database import SessionLocal
from app.models.user import User
def seed_admin() -> None:
"""Create the default admin user when it is missing."""
db = SessionLocal()
try:
existing = db.query(User).filter(User.username == "admin").first()
if existing:
print("Admin user already exists — skipping.")
return
admin = User(
username="admin",
hashed_password=hash_password("admin123"),
role="admin",
)
db.add(admin)
db.commit()
print("Admin user created successfully.")
finally:
db.close()
if __name__ == "__main__":
seed_admin()