feat: 后台管理员独立账号体系,Casdoor 配置改为后台管理

- 新增 admin_users/admin_sessions 表与 adminAuth 工具(scrypt 密码 + 独立会话 Cookie)
- /admin/init 初始化首个管理员,未初始化时服务端/客户端双守卫引导
- 后台鉴权改为管理员会话,前台 Casdoor 用户一律普通用户、与后台解耦
- Casdoor 配置改存 settings 表并由「统一认证」页管理,移除全部 CASDOOR 环境变量
- 侧边栏增加统一认证/管理员入口与登出;LoginModal 感知 SSO 启用状态
- 补充 adminAuth 测试,重写 casdoor 测试,全部 23 项通过
This commit is contained in:
2026-08-09 02:01:14 +08:00
parent 337eb4f05a
commit 541e24c6f4
42 changed files with 1505 additions and 307 deletions
+27
View File
@@ -0,0 +1,27 @@
import { readBody, createError } from 'h3'
import { requireAdmin } from '../../utils/auth'
import { saveCasdoorConfig, validateCasdoorConfig, getCasdoorConfig } from '../../utils/casdoorConfig'
import { writeAudit } from '../../utils/audit'
/**
* 后台保存 Casdoor 认证配置(持久化到 settings 表)。
* 空字段表示「保留旧值」;enabled 显式传布尔。
*/
export default defineEventHandler(async (event) => {
requireAdmin(event)
const body = await readBody(event)
const patch = body?.config
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
throw createError({ statusCode: 400, message: '缺少配置内容', data: { code: 'VALIDATION_ERROR' } })
}
const errors = validateCasdoorConfig(patch)
if (errors.length) {
throw createError({ statusCode: 400, message: errors.join(';'), data: { code: 'VALIDATION_ERROR' } })
}
saveCasdoorConfig(patch)
writeAudit(event, 'update', 'casdoor-config')
return { ok: true, config: getCasdoorConfig() }
})