Files
ClassManager/frontend/reset_password.php
T
canglan dbf70f602e 静态资源加修改时间版本号,修复部署后浏览器缓存旧 JS 的问题
页面 JS/CSS 引用统一改为 asset_url()(附加 ?v=filemtime):
部署更新文件后浏览器自动拉取新版本,避免出现"新按钮点击无反应"等旧缓存现象。
2026-10-10 16:13:22 +08:00

158 lines
6.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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="<?php echo asset_url('/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 text-muted" style="text-align:center;">正在校验链接...</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 class="pwd-policy">密码长度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 class="text-danger" style="margin-bottom:16px;">重置链接无效或已过期,请重新申请。</p>
<a href="/forgot_password.php" class="link">重新申请</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 src="<?php echo asset_url('/assets/js/common.js'); ?>"></script>
<script>
window.API_BASE_URL = '<?php echo API_BASE_URL; ?>';
const RESET_TOKEN = '<?php echo htmlspecialchars($token, ENT_QUOTES, 'UTF-8'); ?>';
// 加载密码策略(公开配置)
fetch(window.API_BASE_URL + '/api/config/deduction-rules')
.then(function(r) { return r.json(); })
.then(function(resp) {
if (resp && resp.success && resp.data) {
window.PASSWORD_MIN_LENGTH = resp.data.PASSWORD_MIN_LENGTH;
window.PASSWORD_MAX_LENGTH = resp.data.PASSWORD_MAX_LENGTH;
window.PASSWORD_MIN_TYPES = resp.data.PASSWORD_MIN_TYPES;
document.querySelectorAll('.pwd-policy').forEach(function(el) {
el.textContent = describePasswordPolicy();
});
}
})
.catch(function() {});
function showTip(msg, isError) {
const tip = document.getElementById('tipMsg');
tip.textContent = msg;
tip.className = isError ? 'error-msg' : 'success-msg';
tip.style.display = 'block';
}
(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;
}
const policyError = validatePasswordByPolicy(newPassword);
if (policyError) {
showTip(policyError, 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>