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

+140
View File
@@ -0,0 +1,140 @@
<?php
/**
* 班级操行分管理系统 - 重置密码
*
* 开发者: Canglan
* 联系方式: admin@sea-studio.top
* 版权归属: Sea Network Technology Studio
* 许可证: MIT License
*
* 版权所有 © Sea Network Technology Studio
*/
require_once __DIR__ . '/config.php';
$token = isset($_GET['token']) ? preg_replace('/[^A-Za-z0-9_\-]/', '', $_GET['token']) : '';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title><?php echo SITE_NAME; ?> - 重置密码</title>
<link rel="stylesheet" href="/assets/css/style.css">
</head>
<body>
<div class="login-container">
<div class="login-header">
<h1><?php echo SITE_NAME; ?></h1>
<p>重置管理员密码</p>
</div>
<div id="loadingBox" class="login-form" style="text-align:center; color:#888;">正在校验链接...</div>
<form id="resetForm" class="login-form" style="display:none;">
<div class="form-group">
<label>账号</label>
<input type="text" id="accountName" disabled>
</div>
<div class="form-group">
<label>新密码 <span style="color:red;">*</span></label>
<input type="password" id="newPassword" required>
<small>密码长度6-20位,需包含大写字母、小写字母、数字、特殊符号中的至少3种</small>
</div>
<div class="form-group">
<label>确认新密码 <span style="color:red;">*</span></label>
<input type="password" id="confirmPassword" required>
</div>
<button type="submit" class="btn-login" id="submitBtn">确认重置</button>
<div id="tipMsg" class="error-msg" style="display: none;"></div>
</form>
<div id="invalidBox" class="login-form" style="display:none; text-align:center;">
<p style="color:#e53e3e; margin-bottom:16px;">重置链接无效或已过期,请重新申请。</p>
<a href="/forgot_password.php" style="color:#667eea;">重新申请</a>
</div>
<div class="login-footer">
<p>&copy; <?php echo date('Y'); ?> Sea Network Technology Studio</p>
<?php if (defined('ICP_ENABLED') && ICP_ENABLED && defined('ICP_NUMBER') && ICP_NUMBER): ?>
<p><a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer"><?php echo htmlspecialchars(ICP_NUMBER); ?></a></p>
<?php endif; ?>
</div>
</div>
<script>
window.API_BASE_URL = '<?php echo API_BASE_URL; ?>';
const RESET_TOKEN = '<?php echo htmlspecialchars($token, ENT_QUOTES, 'UTF-8'); ?>';
function showTip(msg, isError) {
const tip = document.getElementById('tipMsg');
tip.textContent = msg;
tip.style.display = 'block';
tip.style.color = isError ? '' : '#38a169';
}
(async function verifyToken() {
if (!RESET_TOKEN) {
document.getElementById('loadingBox').style.display = 'none';
document.getElementById('invalidBox').style.display = 'block';
return;
}
try {
const response = await fetch(`${window.API_BASE_URL}/api/auth/reset-token/check?token=${encodeURIComponent(RESET_TOKEN)}`);
const data = await response.json();
const info = data && data.success ? data.data : null;
document.getElementById('loadingBox').style.display = 'none';
if (info && info.valid) {
document.getElementById('accountName').value =
(info.real_name || '') + '(' + info.username + ')';
document.getElementById('resetForm').style.display = 'block';
} else {
document.getElementById('invalidBox').style.display = 'block';
}
} catch (error) {
console.error('令牌校验失败:', error);
document.getElementById('loadingBox').style.display = 'none';
document.getElementById('invalidBox').style.display = 'block';
}
})();
document.getElementById('resetForm').addEventListener('submit', async (e) => {
e.preventDefault();
const newPassword = document.getElementById('newPassword').value;
const confirmPassword = document.getElementById('confirmPassword').value;
if (newPassword !== confirmPassword) {
showTip('两次输入的密码不一致', true);
return;
}
if (newPassword.length < 6 || newPassword.length > 20) {
showTip('密码长度需为6-20位', true);
return;
}
const btn = document.getElementById('submitBtn');
btn.disabled = true;
btn.textContent = '提交中...';
try {
const response = await fetch(`${window.API_BASE_URL}/api/auth/reset-password`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: RESET_TOKEN, new_password: newPassword })
});
const data = await response.json();
if (data.success) {
showTip(data.message || '密码重置成功', false);
setTimeout(() => { window.location.href = '/index.php'; }, 1800);
} else {
showTip(data.message || '重置失败', true);
btn.disabled = false;
btn.textContent = '确认重置';
}
} catch (error) {
console.error('重置密码失败:', error);
showTip('网络错误,请稍后重试', true);
btn.disabled = false;
btn.textContent = '确认重置';
}
});
</script>
</body>
</html>