- 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)
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
from functools import lru_cache
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
|
|
|
# API
|
|
api_key: str = "changeme-secret-key"
|
|
host: str = "0.0.0.0"
|
|
port: int = 8000
|
|
debug: bool = False
|
|
|
|
# Telegram
|
|
telegram_token: str = ""
|
|
|
|
# WhatsApp (Green API)
|
|
whatsapp_id_instance: str = ""
|
|
whatsapp_api_token: str = ""
|
|
|
|
# SMS / USB-Modem
|
|
sms_port: str = "/dev/ttyUSB0"
|
|
sms_baud_rate: int = 115200
|
|
sms_enabled: bool = False
|
|
|
|
# Datenbank
|
|
database_url: str = "sqlite:///./mcm.db"
|
|
|
|
# TUI Web-Modus
|
|
web_port: int = 8001
|
|
|
|
# Benutzer-Authentifizierung
|
|
secret_key: str = "change-this-secret-key-min-32-chars!!"
|
|
token_expire_hours: int = 24
|
|
default_admin_user: str = "admin"
|
|
default_admin_password: str = "admin"
|
|
|
|
@property
|
|
def telegram_enabled(self) -> bool:
|
|
return bool(self.telegram_token)
|
|
|
|
@property
|
|
def whatsapp_enabled(self) -> bool:
|
|
return bool(self.whatsapp_id_instance and self.whatsapp_api_token)
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|
|
|
|
|
|
settings = get_settings()
|