feat(auth): 实现禁用用户拦截机制防止禁用用户访问
- 新增工具函数 isUserDisabled 判断用户是否被禁用 - 新增 blockDisabledUser 函数拦截禁用用户,清除登录态弹窗提示并跳转登录页 - UserContext 启动时异步校验用户状态,禁用则拦截并退出 - UserContext 的 refreshUser、syncFromStorage、loginUser 接口均增加禁用检查 - 登录相关 API 登录前校验用户状态,禁用时拒绝登录 - 登录页面保存登录态前校验,禁用用户弹窗提示阻断登录流程 - 用户状态定义:status 0 为正常,1 为禁用 - 新增用户管理页支持查询和管理用户状态 - 文档中补充用户状态与禁用机制说明及拦截层级介绍
This commit is contained in:
@@ -3,6 +3,7 @@ import Taro from '@tarojs/taro'
|
||||
import { View, Text, Input, Image } from '@tarojs/components'
|
||||
import { storeLogin } from '@/api/shop/shopStore'
|
||||
import { saveStorageByLoginUser } from '@/utils/server'
|
||||
import { isUserDisabled } from '@/utils/auth'
|
||||
import './index.scss'
|
||||
|
||||
const StoreLogin = () => {
|
||||
@@ -55,6 +56,19 @@ const StoreLogin = () => {
|
||||
if (res?.access_token) {
|
||||
const token = res.access_token
|
||||
const user = res.user
|
||||
|
||||
// 检查用户是否被禁用
|
||||
if (isUserDisabled(user)) {
|
||||
Taro.showModal({
|
||||
title: '账号已被禁用',
|
||||
content: '您的账号已被管理员禁用,暂时无法使用。如有疑问请联系管理员。',
|
||||
showCancel: false,
|
||||
confirmText: '我知道了',
|
||||
confirmColor: '#ee0a24',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
saveStorageByLoginUser(token, user)
|
||||
Taro.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => navigateAfterLogin(), 800)
|
||||
|
||||
Reference in New Issue
Block a user