首次登录改密弹窗改为按服务端标记判断,避免旧本地标记误弹
1. 学生端/管理端首次登录弹窗改为调用 /api/auth/me 校验 need_change_password,不再只依赖 localStorage 旧值 2. 学生端首次登录改密已改用 init-passwd(无需原密码)
This commit is contained in:
1 parent
db278188c6
commit
f624219cba
2 files changed
+27
-6
No files matched your search
@@ -131,9 +131,19 @@ $page_title = $page_title ?? '首页';
|
|||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
(function() {
|
(function() {
|
||||||
var user = (typeof getUserInfo === 'function') ? getUserInfo() : null;
|
// 以服务端标记为准判断是否首次登录(避免本地旧标记误弹)
|
||||||
if (!user || !user.need_change_password) return;
|
(async function() {
|
||||||
document.getElementById('initPasswordModal').style.display = 'flex';
|
var user = (typeof getUserInfo === 'function') ? getUserInfo() : null;
|
||||||
|
var need = user && user.need_change_password;
|
||||||
|
try {
|
||||||
|
var res = await apiGet('/api/auth/me');
|
||||||
|
if (res && res.success && res.data) {
|
||||||
|
need = !!res.data.need_change_password;
|
||||||
|
}
|
||||||
|
} catch (e) { /* 接口异常时退回本地标记 */ }
|
||||||
|
if (!need) return;
|
||||||
|
document.getElementById('initPasswordModal').style.display = 'flex';
|
||||||
|
})();
|
||||||
|
|
||||||
window.submitInitPassword = async function() {
|
window.submitInitPassword = async function() {
|
||||||
var p1 = document.getElementById('initNewPassword').value;
|
var p1 = document.getElementById('initNewPassword').value;
|
||||||
|
|||||||
@@ -497,9 +497,20 @@ include __DIR__ . '/../includes/header.php';
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 检查是否需要强制修改密码
|
// 检查是否需要强制修改密码(以服务端标记为准,避免本地旧标记误弹)
|
||||||
function checkForceChangePassword() {
|
async function checkForceChangePassword() {
|
||||||
const user = getUserInfo();
|
let user = getUserInfo();
|
||||||
|
try {
|
||||||
|
const res = await apiGet('/api/auth/me');
|
||||||
|
if (res && res.success && res.data) {
|
||||||
|
const stored = getUserInfo() || {};
|
||||||
|
stored.need_change_password = !!res.data.need_change_password;
|
||||||
|
try {
|
||||||
|
localStorage.setItem(window.USER_STORAGE_KEY || 'class_system_user', JSON.stringify(stored));
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
user = stored;
|
||||||
|
}
|
||||||
|
} catch (e) { /* 接口异常时退回本地标记 */ }
|
||||||
if (user && user.need_change_password) {
|
if (user && user.need_change_password) {
|
||||||
document.getElementById('forceChangePasswordModal').style.display = 'flex';
|
document.getElementById('forceChangePasswordModal').style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user