feat(停用账号): 停用/删除即强制下线并点名成因——写入口、X-Auth-Reason 头、三面接线

- Java:AdminUserUpdateRequest 加 disabled 开关(不能停自己、归属门沿用既有闸),
  AccountExpiryService/AdminAuthSupport 抛停用/删除子类型,GlobalExceptionHandler 打
  X-Auth-Reason: disabled|deleted 响应头;业务码保持 401 不变,不惊动三个既有消费者
- 后台管理:用户页停用/解除停用按钮 + 已停用徽章;拦截器把成因随 &auth= 带给登录页,
  登录页分停用/删除两种文案;源码钉子棘轮基线按正路重生成
- 用户端:kick-handler 按 X-Auth-Reason 分支亮停用/删除标记(互斥清理),
  登录页两段专属文案且各自关自动登录;跳转目标仍是 /login?expired=1
- 反假绿:摘掉成因头注入实测 2/4 红(变异自证),还原等值后复跑回绿
This commit is contained in:
2026-10-09 16:35:35 +08:00
parent 3c2fd54e3e
commit 24a94428e8
25 changed files with 704 additions and 31 deletions
+11 -4
View File
@@ -17,12 +17,19 @@ export const http = axios.create({
timeout: 30_000,
})
function redirectToLogin(requestUrl?: string): void {
/** 会话失效成因(后端 X-Auth-Reason 头):disabled=已停用、deleted=已删除;其余 401 无成因。 */
function authReasonOf(headers: unknown): string {
const value = (headers as Record<string, unknown> | undefined)?.['x-auth-reason']
return value === 'disabled' || value === 'deleted' ? value : ''
}
function redirectToLogin(requestUrl?: string, reason = ''): void {
if (typeof window === 'undefined') return
// 已在登录页或失败请求即登录端点时不再跳转,避免登录页循环与吞掉登录失败反馈。
if (!shouldRedirectUnauthorized(window.location.pathname, requestUrl)) return
const target = loginRedirectTarget(window.location)
window.location.assign('/admin-vue/login?redirect=' + target)
// 成因随 query 带给登录页点名(停用/删除),登录页据此显示对应提示
window.location.assign('/admin-vue/login?redirect=' + target + (reason ? `&auth=${reason}` : ''))
}
/** 403 只在会话引导端点上才当"进不了后台"处理;其余端点的 403 交给页面自己把原因说出来。 */
@@ -47,7 +54,7 @@ http.interceptors.response.use(
if (isKicked(response.data)) {
redirectToLoginKicked()
} else if (isUnauthorized(response.data)) {
redirectToLogin(response.config?.url)
redirectToLogin(response.config?.url, authReasonOf(response.headers))
} else if (isForbidden(response.data)) {
redirectToLoginOnForbidden(response.config?.url)
}
@@ -57,7 +64,7 @@ http.interceptors.response.use(
if (isKicked(error?.response?.data)) {
redirectToLoginKicked()
} else if (error?.response?.status === 401 || isUnauthorized(error?.response?.data)) {
redirectToLogin(error?.config?.url)
redirectToLogin(error?.config?.url, authReasonOf(error?.response?.headers))
} else if (error?.response?.status === 403 || isForbidden(error?.response?.data)) {
redirectToLoginOnForbidden(error?.config?.url)
}
@@ -29,6 +29,8 @@ export function toAdminUserItem(raw: unknown): AdminUser | null {
if (creator) item.creatorUsername = creator
const expiresAt = text(r.expires_at)
if (expiresAt) item.expiresAt = expiresAt
const disabledAt = text(r.disabled_at)
if (disabledAt) item.disabledAt = disabledAt
const abbr = text(r.pinyin_abbr)
if (abbr) item.pinyinAbbr = abbr
return item
+9
View File
@@ -24,3 +24,12 @@ export async function deleteUser(uid: number): Promise<void> {
const { data } = await http.delete<unknown>(`/api/admin/user/${uid}`)
unwrap<unknown>(data)
}
/**
* 停用/解除停用:PUT /api/admin/user/{uid} 只带 disabled 开关(V155)。
* 停用是硬停点:该账号已发令牌在下一次请求就被拒(401),客户端与后台会被强制退出到登录页。
*/
export async function setUserDisabled(uid: number, disabled: boolean): Promise<void> {
const { data } = await http.put<unknown>(`/api/admin/user/${uid}`, { disabled })
unwrap<unknown>(data)
}