+
+
+
+
+
+ 修改密码
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1750,7 +1778,34 @@
.catch(() => { window.location.href = '/login'; });
}
+ function changePassword() {
+ const currentPwd = document.getElementById('currentPassword').value;
+ const newPwd = document.getElementById('newPassword').value;
+ const confirmPwd = document.getElementById('confirmPassword').value;
+ if (!currentPwd) { showToast('请输入当前密码', 'error'); return; }
+ if (!newPwd || newPwd.length < 6) { showToast('新密码至少6位', 'error'); return; }
+ if (newPwd !== confirmPwd) { showToast('两次密码不一致', 'error'); return; }
+
+ fetch('/api/user/password', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ current_password: currentPwd, new_password: newPwd })
+ })
+ .then(r => r.json().then(data => ({ ok: r.ok, data })))
+ .then(({ ok, data }) => {
+ if (ok) {
+ showToast('密码修改成功', 'success');
+ closeModal('changePasswordModal');
+ document.getElementById('currentPassword').value = '';
+ document.getElementById('newPassword').value = '';
+ document.getElementById('confirmPassword').value = '';
+ } else {
+ showToast(data.error || '修改失败', 'error');
+ }
+ })
+ .catch(() => showToast('网络错误', 'error'));
+ }
// 点击overlay关闭弹窗
document.querySelectorAll('.modal-overlay').forEach(function(overlay) {