Files
ClassManager/frontend/admin/password.php
T
canglan ed3189096d 权限组全自定义、月度分独立、绑定邮箱免密与样式统一
1. 权限组:去掉锁定/预置限制,所有组可编辑/删除/分配;管理员新增/编辑可选任意组;管理员列表不再显示锁定徽标
2. 个人查询:月度分独立计算(当月净得分,与基础分无关),总分=基础分+加分-减分
3. 绑定邮箱:发送验证码与确认绑定不再需要密码(解绑仍需密码)
4. 权限组编辑UI:权限项按 学生/操行分/教务/系统管理 分区,支持全选/清空,上限两行布局,弹窗加宽
5. 样式统一:颜色变量化(硬编码色值清零)、check-grid/check-item 统一复选框网格、cell-wrap、subject-status 全局化、success-msg
6. 旧库升级期兼容保留(登录/权限降级、待升级提示)
7. 文档同步更新
2026-09-18 09:56:39 +08:00

183 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>密码长度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;
}
if (newPassword.length < 6 || newPassword.length > 20) {
showToast('密码长度需为6-20位', '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'; ?>