Files
ClassManager/frontend/admin/password.php
T
canglan 768ea281e0 v4.4 数据报表/操作日志/系统设置与月度分排行
1. 月度分排行:管理端首页支持总分/月度分切换与月份选择,新增排行榜导出CSV
2. 数据报表:新增考勤/作业统计页(日期范围、汇总与每人明细、CSV导出)
3. 操作日志:新增查看页(操作类型/操作人/日期筛选,分页)
4. 系统设置:密码策略可配置(长度/字符种类),全站改密与重置统一校验、前端提示同步;策略通过公开配置下发
5. 学期归档对比:查看归档时展示与上一学期的分数变化与名次升降
6. 历史记录导出支持按学生分表(每人一段,便于发家长)
7. 移动端适配:导航横向滚动、表格触控滚动、字号与弹窗优化
8. 版本升级至4.4(无数据库结构变更)
2026-10-09 15:00:32 +08:00

184 lines
6.7 KiB
PHP

<?php
/**
* 班级操行分管理系统 - 管理端修改密码
*
* 开发者: Canglan
* 联系方式: admin@sea-studio.top
* 版权归属: Sea Network Technology Studio
* 许可证: MIT License
*
* 版权所有 © Sea Network Technology Studio
*/
require_once __DIR__ . '/../config.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
header('Location: /index.php');
exit();
}
$page_title = '修改密码';
$role = current_group_name();
$bound_email = $_SESSION['email'] ?? '';
include __DIR__ . '/../includes/header.php';
?>
<?php include __DIR__ . '/../includes/nav.php'; ?>
<div class="container">
<div class="card">
<div class="card-title">修改密码</div>
<form id="passwordForm">
<div class="form-group">
<label>原密码 <span style="color:red;">*</span></label>
<input type="password" id="oldPassword" required>
</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 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>
<div class="form-group">
<label>新邮箱</label>
<input type="email" id="bindEmail" maxlength="100" placeholder="请输入要绑定的邮箱">
</div>
<div style="display:flex; gap:8px; flex-wrap:wrap;">
<button type="button" class="btn btn-secondary" onclick="sendBindEmailCode()">发送验证码</button>
</div>
<div class="form-group" style="margin-top:16px;">
<label>邮箱验证码</label>
<input type="text" id="emailCode" maxlength="6" inputmode="numeric" placeholder="请输入6位验证码">
</div>
<div style="display:flex; gap:8px; flex-wrap:wrap;">
<button type="button" class="btn btn-primary" onclick="confirmBindEmail()">确认绑定</button>
</div>
<hr style="border:none; border-top:1px solid var(--color-border-light); margin:18px 0;">
<div class="form-group">
<label>当前密码</label>
<input type="password" id="emailPassword" placeholder="解除绑定邮箱需验证当前密码">
</div>
<div>
<button type="button" class="btn btn-sm btn-outline-danger" onclick="unbindEmail()">解除绑定</button>
</div>
</div>
</div>
<script>
document.getElementById('passwordForm').addEventListener('submit', async (e) => {
e.preventDefault();
const oldPassword = document.getElementById('oldPassword').value;
const newPassword = document.getElementById('newPassword').value;
const confirmPassword = document.getElementById('confirmPassword').value;
if (newPassword !== confirmPassword) {
showToast('两次输入的新密码不一致', 'error');
return;
}
const policyError = validatePasswordByPolicy(newPassword);
if (policyError) {
showToast(policyError, 'error');
return;
}
const res = await apiPost('/api/auth/change-password', {
old_password: oldPassword,
new_password: newPassword
});
if (res && res.success) {
showToast('密码修改成功,请重新登录');
setTimeout(() => logout(), 1500);
} else {
showToast(res?.message || '密码修改失败', 'error');
}
});
async function sendBindEmailCode() {
const email = document.getElementById('bindEmail').value.trim();
if (!email) {
showToast('请输入要绑定的邮箱', 'warning');
return;
}
const res = await apiPost('/api/auth/email/send-code', {
email: email
});
if (res && res.success) {
showToast(res.message || '验证码已发送,请查收邮箱');
document.getElementById('emailCode').focus();
} else {
showToast(res?.message || '验证码发送失败', 'error');
}
}
async function confirmBindEmail() {
const email = document.getElementById('bindEmail').value.trim();
const code = document.getElementById('emailCode').value.trim();
if (!email) {
showToast('请输入要绑定的邮箱', 'warning');
return;
}
if (!code) {
showToast('请输入邮箱验证码', 'warning');
return;
}
const res = await apiPost('/api/auth/email/confirm', {
email: email,
code: code
});
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 = '';
document.getElementById('emailCode').value = '';
showToast(res.message || '邮箱绑定成功');
} else {
showToast(res?.message || '邮箱绑定失败', 'error');
}
}
async function unbindEmail() {
const password = document.getElementById('emailPassword').value;
if (!password) {
showToast('请输入当前密码', 'warning');
return;
}
if (!confirm('确定解除绑定邮箱吗?解除后将无法通过邮箱找回密码。')) {
return;
}
const res = await apiPost('/api/auth/email/unbind', {
password: password
});
if (res && res.success) {
document.getElementById('currentEmail').textContent = '未绑定';
document.getElementById('bindEmail').value = '';
document.getElementById('emailPassword').value = '';
document.getElementById('emailCode').value = '';
showToast(res.message || '邮箱已解除绑定');
} else {
showToast(res?.message || '解除绑定失败', 'error');
}
}
</script>
<?php include __DIR__ . '/../includes/footer.php'; ?>