diff --git a/backend/main.py b/backend/main.py index 673fbc2..3c6da93 100644 --- a/backend/main.py +++ b/backend/main.py @@ -12,6 +12,7 @@ from .schemas import AdminCreate, LoginRequest, ProjectCreate, ProjectResponse, from .models import User, Project, Message, SystemSettings from .orchestrator import run_orchestrator, sync_providers_models from .models import User, Project, Message, SystemSettings, AIModel +from .schemas import AdminCreate, LoginRequest, ProjectCreate, ProjectResponse, ProjectRename, MessageCreate, MessageResponse, PasswordChangeS # Création des tables dans la base de données Base.metadata.create_all(bind=engine) @@ -94,6 +95,19 @@ def dashboard(request: Request): frontend_path = os.path.join(os.getcwd(), "frontend", "dashboard.html") return FileResponse(frontend_path) +@app.put("/api/users/me/password") +def change_password(passwords: PasswordChange, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)): + """Permet à l'utilisateur connecté de modifier son propre mot de passe.""" + if not verify_password(passwords.old_password, current_user.hashed_password): + raise HTTPException(status_code=400, detail="L'ancien mot de passe est incorrect.") + + if len(passwords.new_password) < 8: + raise HTTPException(status_code=400, detail="Le nouveau mot de passe doit contenir au moins 8 caractères.") + + current_user.hashed_password = get_password_hash(passwords.new_password) + db.commit() + return {"message": "Mot de passe mis à jour avec succès."} + # --- GESTION DES PROJETS --- def get_current_user(request: Request, db: Session = Depends(get_db)): diff --git a/backend/schemas.py b/backend/schemas.py index 9dc5b66..849066c 100644 --- a/backend/schemas.py +++ b/backend/schemas.py @@ -56,4 +56,8 @@ class MessageResponse(MessageBase): project_id: int class ProjectRename(BaseModel): - title: str \ No newline at end of file + title: str + +class PasswordChange(BaseModel): + old_password: str + new_password: str \ No newline at end of file diff --git a/frontend/dashboard.html b/frontend/dashboard.html index 3c5afde..759e948 100644 --- a/frontend/dashboard.html +++ b/frontend/dashboard.html @@ -24,6 +24,39 @@
+ + +
+
+
+

Paramètres

+ +
+
+

Sécurité du compte

+
{{ settingsMessage }}
+ +
+ + +
+
+ + +
+
+ + +
+ + +
+
+
+
@@ -84,7 +117,7 @@
{{ username.charAt(0).toUpperCase() }}
{{ username }}
-
@@ -157,7 +190,7 @@