fix(profile): make save button work and verify current password

This commit is contained in:
dev
2026-10-22 17:30:08 +03:00
parent 0ecbca5f13
commit af67526df7
2 changed files with 9 additions and 1 deletions
+5 -1
View File
@@ -342,7 +342,10 @@
if (data.name !== undefined) body.name = data.name;
if (data.email !== undefined) body.email = data.email;
if (data.phone !== undefined) body.phone = data.phone;
if (data.password) body.password = data.password;
if (data.password) {
body.password = data.password;
body.old_password = data.oldPassword;
}
setLoading(els.btnSave, true);
clearErrors();
@@ -903,6 +906,7 @@
if (!isPasswordVisible) setDirty('general', generalSnapshot() !== generalBaseline);
});
els.btnSave.addEventListener('click', saveProfile);
els.btnCancel.addEventListener('click', () => { loadProfile(); });
els.btnLogout.addEventListener('click', () => { doLogout(); });
+4
View File
@@ -4467,6 +4467,10 @@ app.put('/api/users/:id/profile', requireAuth, async (req, res) => {
let hash = null;
if (req.body?.password) {
if (String(req.body.password).length < 6) return res.status(400).json({ error: 'Пароль должен быть не короче 6 символов' });
const oldPassword = String(req.body?.old_password || '');
if (!oldPassword) return res.status(400).json({ error: 'Введите текущий пароль' });
const oldOk = await bcrypt.compare(oldPassword, target.password_hash);
if (!oldOk) return res.status(400).json({ error: 'Неверный текущий пароль' });
hash = await bcrypt.hash(String(req.body.password), 10);
}