v4.1 管理员邮箱绑定与SMTP找回密码

1. users 表新增 email 列,管理员添加/编辑支持绑定邮箱,修改密码页支持自助绑定
2. 新增 SMTP 邮件发送工具与配置(FRONTEND_URL/SMTP_* 等)
3. 新增忘记密码/重置密码公开接口与页面:一次性令牌、30分钟有效、请求限流、重置后强制重新登录
4. 登录与 /api/auth/me 返回邮箱并同步 PHP Session
5. 版本升级至4.1(sql/upgrades/v4.1.sql)
This commit is contained in:
canglan committed 2026-09-17 20:49:15 +08:00
1 parent 3588b4c28c
commit 058dee9dc4
31 files changed
+762 -34

No files matched your search

+7 -4
View File
@@ -118,11 +118,12 @@ async function loadAdmins() {
};
const canEdit = !admin.is_locked && admin.group_id;
const editItem = canEdit
? `<a onclick="showEditAdminModal(${admin.user_id}, '${escapeHtml(admin.username)}', '${escapeHtml(admin.real_name)}', ${admin.group_id})">编辑</a>`
? `<a onclick="showEditAdminModal(${admin.user_id}, '${escapeHtml(admin.username)}', '${escapeHtml(admin.real_name)}', ${admin.group_id}, '${escapeHtml(admin.email || '')}')">编辑</a>`
: '';
html += `<tr>
<td>${escapeHtml(admin.username)}</td>
<td>${escapeHtml(admin.real_name)}</td>
<td>${admin.email ? escapeHtml(admin.email) : '<span class="text-muted">未绑定</span>'}</td>
<td>${escapeHtml(admin.group_name || admin.role_type || '-')}${admin.is_locked ? ' <span class="subject-status subject-status-active">锁定</span>' : ''}</td>
<td>加${caps.add} / 扣${caps.subtract}</td>
<td><span class="subject-status ${statusClass}">${statusText}</span></td>
@@ -140,18 +141,19 @@ async function loadAdmins() {
</tr>`;
});
if (res.data.admins.length === 0) {
html = '<tr><td colspan="6" style="text-align:center;">暂无管理员</td></tr>';
html = '<tr><td colspan="7" style="text-align:center;">暂无管理员</td></tr>';
}
document.getElementById('adminList').innerHTML = html;
}
}
function showEditAdminModal(userId, username, realName, groupId) {
function showEditAdminModal(userId, username, realName, groupId, email) {
currentEditUserId = userId;
document.getElementById('editAdminUserId').value = userId;
document.getElementById('editAdminUsername').value = username;
document.getElementById('editAdminRealName').value = realName;
document.getElementById('editAdminGroupId').value = groupId || '';
document.getElementById('editAdminEmail').value = email || '';
document.getElementById('editAdminModal').style.display = 'flex';
}
@@ -166,7 +168,8 @@ async function submitEditAdmin() {
const res = await apiPut(`/api/admin/update/${currentEditUserId}`, {
real_name: document.getElementById('editAdminRealName').value.trim(),
group_id: groupId
group_id: groupId,
email: document.getElementById('editAdminEmail').value.trim()
});
if (res && res.success) {
+4 -1
View File
@@ -23,6 +23,7 @@
const realName = document.getElementById('adminRealName').value.trim();
const password = document.getElementById('adminPassword').value;
const groupId = parseInt(document.getElementById('adminGroupId').value);
const email = document.getElementById('adminEmail').value.trim();
if (!username || !realName || !groupId) {
showToast('请填写完整信息', 'warning');
@@ -33,7 +34,8 @@
username: username,
real_name: realName,
password: password || undefined,
group_id: groupId
group_id: groupId,
email: email || undefined
});
if (res && res.success) {
@@ -49,6 +51,7 @@
document.getElementById('adminRealName').value = '';
document.getElementById('adminPassword').value = '';
document.getElementById('adminGroupId').value = '';
document.getElementById('adminEmail').value = '';
loadAdmins();
} else {
showToast(res?.message || '添加失败', 'error');