feat: intégration du formulaire de modification du mot de passe utilisateur via le tableau de bord
This commit is contained in:
1 parent
b6765a9bc8
commit
aed936578a
3 files changed
+105
-3
No files matched your search
@@ -12,6 +12,7 @@ from .schemas import AdminCreate, LoginRequest, ProjectCreate, ProjectResponse,
|
|||||||
from .models import User, Project, Message, SystemSettings
|
from .models import User, Project, Message, SystemSettings
|
||||||
from .orchestrator import run_orchestrator, sync_providers_models
|
from .orchestrator import run_orchestrator, sync_providers_models
|
||||||
from .models import User, Project, Message, SystemSettings, AIModel
|
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
|
# Création des tables dans la base de données
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
@@ -94,6 +95,19 @@ def dashboard(request: Request):
|
|||||||
frontend_path = os.path.join(os.getcwd(), "frontend", "dashboard.html")
|
frontend_path = os.path.join(os.getcwd(), "frontend", "dashboard.html")
|
||||||
return FileResponse(frontend_path)
|
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 ---
|
# --- GESTION DES PROJETS ---
|
||||||
|
|
||||||
def get_current_user(request: Request, db: Session = Depends(get_db)):
|
def get_current_user(request: Request, db: Session = Depends(get_db)):
|
||||||
|
|||||||
@@ -57,3 +57,7 @@ class MessageResponse(MessageBase):
|
|||||||
|
|
||||||
class ProjectRename(BaseModel):
|
class ProjectRename(BaseModel):
|
||||||
title: str
|
title: str
|
||||||
|
|
||||||
|
class PasswordChange(BaseModel):
|
||||||
|
old_password: str
|
||||||
|
new_password: str
|
||||||
+87
-3
@@ -24,6 +24,39 @@
|
|||||||
<body class="h-screen flex overflow-hidden">
|
<body class="h-screen flex overflow-hidden">
|
||||||
|
|
||||||
<div id="app" class="flex w-full h-full relative bg-aethas-dark">
|
<div id="app" class="flex w-full h-full relative bg-aethas-dark">
|
||||||
|
|
||||||
|
<!-- MODAL PARAMÈTRES -->
|
||||||
|
<div v-if="isSettingsModalOpen" class="fixed inset-0 bg-black/80 z-[100] flex items-center justify-center p-4">
|
||||||
|
<div class="bg-aethas-panel border border-gray-600 rounded-2xl w-full max-w-md overflow-hidden shadow-[0_0_30px_rgba(0,0,0,0.7)]">
|
||||||
|
<div class="p-4 border-b border-gray-700 flex justify-between items-center bg-gray-800/50">
|
||||||
|
<h2 class="text-lg font-bold text-white flex items-center gap-2"><i data-lucide="settings" class="w-5 h-5 text-aethas-cyan"></i> Paramètres</h2>
|
||||||
|
<button @click="closeSettings" class="text-gray-400 hover:text-white"><i data-lucide="x" class="w-5 h-5"></i></button>
|
||||||
|
</div>
|
||||||
|
<div class="p-6 space-y-4">
|
||||||
|
<h3 class="text-sm font-semibold text-aethas-cyan uppercase tracking-wider mb-2">Sécurité du compte</h3>
|
||||||
|
<div v-if="settingsMessage" :class="['p-3 rounded text-sm text-center', settingsMessage.includes('succès') ? 'bg-green-900/50 text-green-200 border border-green-500' : 'bg-red-900/50 text-red-200 border border-red-500']">{{ settingsMessage }}</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm text-gray-300 mb-1">Ancien mot de passe</label>
|
||||||
|
<input v-model="passForm.old" type="password" class="w-full bg-aethas-dark border border-gray-600 rounded-lg px-4 py-2 focus:border-aethas-cyan focus:outline-none" placeholder="••••••••">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm text-gray-300 mb-1">Nouveau mot de passe</label>
|
||||||
|
<input v-model="passForm.new" type="password" class="w-full bg-aethas-dark border border-gray-600 rounded-lg px-4 py-2 focus:border-aethas-cyan focus:outline-none" placeholder="8 caractères minimum">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm text-gray-300 mb-1">Confirmer le mot de passe</label>
|
||||||
|
<input v-model="passForm.confirm" type="password" class="w-full bg-aethas-dark border border-gray-600 rounded-lg px-4 py-2 focus:border-aethas-cyan focus:outline-none" placeholder="••••••••">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button @click="changePassword" :disabled="isSavingSettings" class="w-full mt-4 bg-gray-700 hover:bg-gray-600 text-white font-semibold py-2.5 px-4 rounded-lg transition-colors border border-gray-500 disabled:opacity-50">
|
||||||
|
<span v-if="isSavingSettings">Mise à jour...</span>
|
||||||
|
<span v-else>Modifier le mot de passe</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="isSidebarOpen" @click="toggleSidebar" class="md:hidden fixed inset-0 bg-black/60 z-40 transition-opacity"></div>
|
<div v-if="isSidebarOpen" @click="toggleSidebar" class="md:hidden fixed inset-0 bg-black/60 z-40 transition-opacity"></div>
|
||||||
|
|
||||||
<div :class="['transition-all duration-300 flex-shrink-0 relative z-50', isSidebarOpen ? 'w-72' : 'w-0']">
|
<div :class="['transition-all duration-300 flex-shrink-0 relative z-50', isSidebarOpen ? 'w-72' : 'w-0']">
|
||||||
@@ -84,7 +117,7 @@
|
|||||||
<div class="w-8 h-8 rounded-full bg-gradient-to-tr from-aethas-cyan to-aethas-purple flex items-center justify-center text-sm font-bold shadow-md">{{ username.charAt(0).toUpperCase() }}</div>
|
<div class="w-8 h-8 rounded-full bg-gradient-to-tr from-aethas-cyan to-aethas-purple flex items-center justify-center text-sm font-bold shadow-md">{{ username.charAt(0).toUpperCase() }}</div>
|
||||||
<span class="text-sm font-medium">{{ username }}</span>
|
<span class="text-sm font-medium">{{ username }}</span>
|
||||||
</div>
|
</div>
|
||||||
<button class="text-gray-400 hover:text-white transition-colors" title="Paramètres">
|
<button @click="openSettings" class="text-gray-400 hover:text-white transition-colors" title="Paramètres">
|
||||||
<i data-lucide="settings" class="w-5 h-5"></i>
|
<i data-lucide="settings" class="w-5 h-5"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -157,7 +190,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const { createApp, ref, onMounted, nextTick, computed } = Vue;
|
const { createApp, ref, reactive, onMounted, nextTick, computed } = Vue;
|
||||||
|
|
||||||
createApp({
|
createApp({
|
||||||
setup() {
|
setup() {
|
||||||
@@ -171,6 +204,11 @@
|
|||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
const isAiThinking = ref(false);
|
const isAiThinking = ref(false);
|
||||||
|
|
||||||
|
const isSettingsModalOpen = ref(false);
|
||||||
|
const isSavingSettings = ref(false);
|
||||||
|
const settingsMessage = ref("");
|
||||||
|
const passForm = reactive({ old: '', new: '', confirm: '' });
|
||||||
|
|
||||||
const pinnedProjects = computed(() => projects.value.filter(p => p.is_pinned));
|
const pinnedProjects = computed(() => projects.value.filter(p => p.is_pinned));
|
||||||
const recentProjects = computed(() => projects.value.filter(p => !p.is_pinned));
|
const recentProjects = computed(() => projects.value.filter(p => !p.is_pinned));
|
||||||
|
|
||||||
@@ -188,6 +226,51 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openSettings = () => {
|
||||||
|
isSettingsModalOpen.value = true;
|
||||||
|
settingsMessage.value = "";
|
||||||
|
passForm.old = ''; passForm.new = ''; passForm.confirm = '';
|
||||||
|
nextTick(() => lucide.createIcons());
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeSettings = () => {
|
||||||
|
isSettingsModalOpen.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const changePassword = async () => {
|
||||||
|
settingsMessage.value = "";
|
||||||
|
if (passForm.new !== passForm.confirm) {
|
||||||
|
settingsMessage.value = "Les nouveaux mots de passe ne correspondent pas.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (passForm.new.length < 8) {
|
||||||
|
settingsMessage.value = "Le mot de passe doit faire au moins 8 caractères.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isSavingSettings.value = true;
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/users/me/password', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ old_password: passForm.old, new_password: passForm.new })
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
settingsMessage.value = data.message;
|
||||||
|
passForm.old = ''; passForm.new = ''; passForm.confirm = '';
|
||||||
|
setTimeout(() => closeSettings(), 2000);
|
||||||
|
} else {
|
||||||
|
settingsMessage.value = data.detail;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
settingsMessage.value = "Erreur de connexion au serveur.";
|
||||||
|
} finally {
|
||||||
|
isSavingSettings.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const fetchProjects = async () => {
|
const fetchProjects = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/projects');
|
const response = await fetch('/api/projects');
|
||||||
@@ -317,7 +400,8 @@
|
|||||||
return {
|
return {
|
||||||
username, isSidebarOpen, toggleSidebar, prompt, autoResize, promptTextarea,
|
username, isSidebarOpen, toggleSidebar, prompt, autoResize, promptTextarea,
|
||||||
projects, pinnedProjects, recentProjects, activeProject, messages, isAiThinking,
|
projects, pinnedProjects, recentProjects, activeProject, messages, isAiThinking,
|
||||||
createNewProject, selectProject, renameProject, sendMessage, isLoading, togglePin, deleteProject
|
createNewProject, selectProject, renameProject, sendMessage, isLoading, togglePin, deleteProject,
|
||||||
|
isSettingsModalOpen, openSettings, closeSettings, passForm, settingsMessage, isSavingSettings, changePassword
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}).mount('#app');
|
}).mount('#app');
|
||||||
|
|||||||
Reference in new issue
Block a user