fix(profile): make save button work and verify current password
This commit is contained in:
@@ -342,7 +342,10 @@
|
|||||||
if (data.name !== undefined) body.name = data.name;
|
if (data.name !== undefined) body.name = data.name;
|
||||||
if (data.email !== undefined) body.email = data.email;
|
if (data.email !== undefined) body.email = data.email;
|
||||||
if (data.phone !== undefined) body.phone = data.phone;
|
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);
|
setLoading(els.btnSave, true);
|
||||||
clearErrors();
|
clearErrors();
|
||||||
@@ -903,6 +906,7 @@
|
|||||||
if (!isPasswordVisible) setDirty('general', generalSnapshot() !== generalBaseline);
|
if (!isPasswordVisible) setDirty('general', generalSnapshot() !== generalBaseline);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
els.btnSave.addEventListener('click', saveProfile);
|
||||||
els.btnCancel.addEventListener('click', () => { loadProfile(); });
|
els.btnCancel.addEventListener('click', () => { loadProfile(); });
|
||||||
els.btnLogout.addEventListener('click', () => { doLogout(); });
|
els.btnLogout.addEventListener('click', () => { doLogout(); });
|
||||||
|
|
||||||
|
|||||||
@@ -4467,6 +4467,10 @@ app.put('/api/users/:id/profile', requireAuth, async (req, res) => {
|
|||||||
let hash = null;
|
let hash = null;
|
||||||
if (req.body?.password) {
|
if (req.body?.password) {
|
||||||
if (String(req.body.password).length < 6) return res.status(400).json({ error: 'Пароль должен быть не короче 6 символов' });
|
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);
|
hash = await bcrypt.hash(String(req.body.password), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user