feat: Multi-User-Unterstützung mit JWT-Authentifizierung

- User-Modell (username, password_hash, role admin/user, is_active)
- Standard-Admin-Benutzer wird beim ersten Start automatisch angelegt
- JWT-Tokens (HS256) für Benutzer-Sessions, konfigurierbare Ablaufzeit
- API-Key bleibt für service-to-service-Calls (backward-compatible)
- POST /api/v1/auth/login → JWT-Token
- GET  /api/v1/auth/me   → aktueller Benutzer
- CRUD /api/v1/users/    → Benutzerverwaltung (nur Admin)
- TUI zeigt Login-Screen beim Start; nach Erfolg → MainScreen
- Passwort-Hashing mit bcrypt (python-jose für JWT)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 20:55:13 +01:00
parent 6742242fe0
commit cd26b80d00
14 changed files with 421 additions and 10 deletions

View File

@@ -23,6 +23,23 @@ def _uuid() -> str:
return str(uuid.uuid4())
# ── User ───────────────────────────────────────────────────────────────────────
class User(Base):
__tablename__ = "users"
id = Column(String(36), primary_key=True, default=_uuid)
username = Column(String(64), nullable=False, unique=True, index=True)
password_hash = Column(String(255), nullable=False)
role = Column(
Enum("admin", "user", name="user_role"),
nullable=False,
default="user",
)
is_active = Column(Boolean, default=True, nullable=False)
created_at = Column(DateTime, default=func.now(), nullable=False)
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
# ── Many-to-many: Conversation ↔ Contact ──────────────────────────────────────
conversation_participants = Table(
"conversation_participants",