diff --git a/backend/main.py b/backend/main.py index e46b880..98caa83 100644 --- a/backend/main.py +++ b/backend/main.py @@ -10,6 +10,7 @@ from .database import engine, Base, get_db from .models import User, Project, Message from .auth import get_password_hash, generate_totp_secret, get_totp_uri, verify_password, verify_totp, create_access_token, verify_token from .schemas import AdminCreate, LoginRequest, ProjectCreate, ProjectResponse, ProjectRename, MessageCreate, MessageResponse +from .models import User, Project, Message, SystemSettings # Création des tables dans la base de données Base.metadata.create_all(bind=engine) @@ -58,17 +59,16 @@ def login_page(db: Session = Depends(get_db)): @app.post("/api/setup") def create_admin(admin_data: AdminCreate, db: Session = Depends(get_db)): - """Reçoit les données du frontend, crée l'admin et retourne le QR Code 2FA.""" + """Reçoit les données du frontend, crée l'admin, sauvegarde la configuration et retourne le QR Code 2FA.""" if not is_setup_required(db): raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail="L'installation a déjà été effectuée." ) - # Sécurisation des accès + # Création du Super Admin hashed_pw = get_password_hash(admin_data.password) totp_secret = generate_totp_secret() - new_admin = User( email=admin_data.email, username=admin_data.username, @@ -76,16 +76,25 @@ def create_admin(admin_data: AdminCreate, db: Session = Depends(get_db)): totp_secret=totp_secret, is_admin=True ) - db.add(new_admin) + + # Sauvegarde des paramètres système + new_settings = SystemSettings( + smtp_host=admin_data.smtp_host, + smtp_port=admin_data.smtp_port, + smtp_user=admin_data.smtp_user, + smtp_password=admin_data.smtp_password, + gemini_api_key=admin_data.gemini_api_key, + openrouter_api_key=admin_data.openrouter_api_key + ) + db.add(new_settings) + db.commit() db.refresh(new_admin) - # Génération de l'URI pour l'affichage du QR Code côté frontend totp_uri = get_totp_uri(totp_secret, new_admin.username) - return { - "message": "Administrateur créé avec succès.", + "message": "Configuration terminée avec succès.", "totp_secret": totp_secret, "totp_uri": totp_uri } diff --git a/backend/models.py b/backend/models.py index a625b73..aa10625 100644 --- a/backend/models.py +++ b/backend/models.py @@ -41,4 +41,17 @@ class Message(Base): project_id = Column(Integer, ForeignKey("projects.id"), nullable=False) # Relation - project = relationship("Project", back_populates="messages") \ No newline at end of file + project = relationship("Project", back_populates="messages") + +class SystemSettings(Base): + __tablename__ = "system_settings" + + id = Column(Integer, primary_key=True, index=True) + # Serveur Mail (Obligatoire) + smtp_host = Column(String, nullable=False) + smtp_port = Column(Integer, nullable=False) + smtp_user = Column(String, nullable=False) + smtp_password = Column(String, nullable=False) + # Clés API (Optionnelles) + gemini_api_key = Column(String, nullable=True) + openrouter_api_key = Column(String, nullable=True) \ No newline at end of file diff --git a/backend/schemas.py b/backend/schemas.py index 06cd645..000fe30 100644 --- a/backend/schemas.py +++ b/backend/schemas.py @@ -6,6 +6,14 @@ class AdminCreate(BaseModel): email: EmailStr username: str password: str + # Serveur Mail (Obligatoire) + smtp_host: str + smtp_port: int + smtp_user: str + smtp_password: str + # Clés API (Optionnelles) + gemini_api_key: Optional[str] = None + openrouter_api_key: Optional[str] = None class LoginRequest(BaseModel): username: str @@ -24,10 +32,10 @@ class ProjectResponse(ProjectBase): created_at: datetime is_pinned: bool - class Config: +class Config: from_attributes = True - # --- NOUVEAU : Schémas pour les Messages --- +# --- NOUVEAU : Schémas pour les Messages --- class MessageBase(BaseModel): role: str content: str @@ -40,8 +48,5 @@ class MessageResponse(MessageBase): created_at: datetime project_id: int - class Config: - from_attributes = True - class ProjectRename(BaseModel): title: str \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index 0d21b32..97e197b 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -3,60 +3,122 @@
-
Configuration de l'Orchestrateur Multi-IA
+Configuration Initiale (Super Admin)
Scannez ce QR Code avec votre application 2FA (Keepassium, Google Authenticator...).
-Secret manuel : {{ totpSecret }}
+Secret manuel : {{ totpSecret }}