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

+10 -1
View File
@@ -34,7 +34,7 @@ include __DIR__ . '/../includes/header.php';
<div class="table-wrapper">
<table class="table">
<thead>
<tr><th>用户名</th><th>姓名</th><th>权限组</th><th>加减分上限</th><th>状态</th><th>操作</th></tr>
<tr><th>用户名</th><th>姓名</th><th>绑定邮箱</th><th>权限组</th><th>加减分上限</th><th>状态</th><th>操作</th></tr>
</thead>
<tbody id="adminList"></tbody>
</table>
@@ -72,6 +72,11 @@ include __DIR__ . '/../includes/header.php';
<label>姓名</label>
<input type="text" id="adminRealName" required placeholder="真实姓名">
</div>
<div class="form-group">
<label>绑定邮箱</label>
<input type="email" id="adminEmail" maxlength="100" placeholder="选填,用于找回密码">
<small>绑定后可通过登录页"忘记密码"重置密码</small>
</div>
<div class="form-group">
<label>密码</label>
<input type="text" id="adminPassword" placeholder="留空则自动生成">
@@ -108,6 +113,10 @@ include __DIR__ . '/../includes/header.php';
<label>姓名</label>
<input type="text" id="editAdminRealName" required>
</div>
<div class="form-group">
<label>绑定邮箱</label>
<input type="email" id="editAdminEmail" maxlength="100" placeholder="留空解除绑定">
</div>
<div class="form-group">
<label>权限组</label>
<select id="editAdminGroupId" required>
+48 -1
View File
@@ -18,7 +18,8 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
}
$page_title = '修改密码';
$role = $_SESSION['role'] ?? '';
$role = current_group_name();
$bound_email = $_SESSION['email'] ?? '';
include __DIR__ . '/../includes/header.php';
?>
@@ -44,6 +45,29 @@ include __DIR__ . '/../includes/header.php';
<button type="submit" class="btn btn-primary">确认修改</button>
</form>
</div>
<div class="card">
<div class="card-title">绑定邮箱(找回密码)</div>
<p style="font-size:13px; color:var(--color-text-secondary); margin-bottom:12px;">
绑定邮箱后,忘记密码时可在登录页通过“忘记密码”向该邮箱发送重置链接。
</p>
<div class="form-group">
<label>当前绑定邮箱</label>
<div id="currentEmail"><?php echo $bound_email ? htmlspecialchars($bound_email) : '未绑定'; ?></div>
</div>
<form id="emailForm">
<div class="form-group">
<label>新邮箱</label>
<input type="email" id="bindEmail" maxlength="100" placeholder="留空则解除绑定">
</div>
<div class="form-group">
<label>当前密码 <span style="color:red;">*</span></label>
<input type="password" id="emailPassword" required>
<small>安全验证:绑定邮箱需要输入当前登录密码</small>
</div>
<button type="submit" class="btn btn-primary">保存邮箱</button>
</form>
</div>
</div>
<script>
@@ -76,6 +100,29 @@ document.getElementById('passwordForm').addEventListener('submit', async (e) =>
showToast(res?.message || '密码修改失败', 'error');
}
});
document.getElementById('emailForm').addEventListener('submit', async (e) => {
e.preventDefault();
const email = document.getElementById('bindEmail').value.trim();
const password = document.getElementById('emailPassword').value;
if (!password) {
showToast('请输入当前密码', 'warning');
return;
}
const res = await apiPost('/api/auth/bind-email', {
password: password,
email: email
});
if (res && res.success) {
const bound = res.data && res.data.email ? res.data.email : '';
document.getElementById('currentEmail').textContent = bound || '未绑定';
document.getElementById('bindEmail').value = '';
document.getElementById('emailPassword').value = '';
showToast(res.message || '邮箱保存成功');
} else {
showToast(res?.message || '邮箱保存失败', 'error');
}
});
</script>
<?php include __DIR__ . '/../includes/footer.php'; ?>