diff --git a/public/js/profile.js b/public/js/profile.js index a2991b6..19616a9 100644 --- a/public/js/profile.js +++ b/public/js/profile.js @@ -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(); }); diff --git a/server.js b/server.js index 34bd950..a0315ed 100644 --- a/server.js +++ b/server.js @@ -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); }