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
+37 -21
View File
@@ -24,26 +24,37 @@
<h2 class="text-2xl md:text-3xl font-bold text-black mb-2">{{ t('auth.login') }}</h2>
<p class="text-gray-600 mb-8">{{ t('auth.casdoorDescription') }}</p>
<p class="text-sm text-gray-500 mb-4">{{ t('auth.casdoorHint') }}</p>
<template v-if="ssoLoaded">
<!-- SSO 未启用 -->
<div v-if="!ssoConfig?.enabled" class="py-4 border border-gray-200 bg-gray-50 rounded-xl text-center">
<Icon name="ph:plug" class="w-6 h-6 text-gray-400 mx-auto mb-2" />
<p class="text-sm text-gray-600">{{ t('auth.ssoDisabled') }}</p>
</div>
<!-- 登录按钮:跳转 Casdoor,回跳当前页面 -->
<button
type="button"
:disabled="isRedirecting"
class="w-full py-3 rounded-xl font-semibold text-white transition-all duration-300 flex items-center justify-center gap-2 bg-black hover:bg-gray-800 shadow-lg hover:shadow-xl disabled:opacity-60 disabled:cursor-not-allowed"
@click="handleLogin"
>
<Icon name="ph:shield-check" class="w-5 h-5" />
<span>{{ isRedirecting ? t('auth.redirecting') : t('auth.loginWithCasdoor') }}</span>
</button>
<!-- 登录按钮:跳转 Casdoor,回跳当前页面 -->
<button
v-else
type="button"
:disabled="isRedirecting"
class="w-full py-3 rounded-xl font-semibold text-white transition-all duration-300 flex items-center justify-center gap-2 bg-black hover:bg-gray-800 shadow-lg hover:shadow-xl disabled:opacity-60 disabled:cursor-not-allowed"
@click="handleLogin"
>
<Icon name="ph:shield-check" class="w-5 h-5" />
<span>{{ isRedirecting ? t('auth.redirecting') : t('auth.loginWithCasdoor') }}</span>
</button>
<!-- 注册:前往 Casdoor 注册页 -->
<p class="mt-6 text-center text-sm text-gray-600">
{{ t('auth.noAccount') }}
<a :href="signupUrl" target="_blank" rel="noopener" class="text-black font-semibold hover:underline">
{{ t('auth.createAccount') }}
</a>
</p>
<!-- 注册:前往 SSO 注册页 -->
<p
v-if="ssoConfig?.enabled && signupUrl"
class="mt-6 text-center text-sm text-gray-600"
>
{{ t('auth.noAccount') }}
<a :href="signupUrl" target="_blank" rel="noopener" class="text-black font-semibold hover:underline">
{{ t('auth.createAccount') }}
</a>
</p>
</template>
<div v-else class="py-16 text-center text-sm text-gray-400">…</div>
</div>
</div>
</div>
@@ -52,18 +63,23 @@
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { computed, onMounted, ref, watch } from 'vue'
import { useRoute } from '#app'
import { useI18n } from 'vue-i18n'
import { useAuthModalStore } from '~/stores/authModal'
import { getCasdoorSignupUrl } from '~/utils/casdoorClient'
import { useCasdoorPublic, getCasdoorSignupUrl } from '~/utils/casdoorClient'
const { t } = useI18n()
const route = useRoute()
const authModal = useAuthModalStore()
const isRedirecting = ref(false)
const signupUrl = getCasdoorSignupUrl()
const { config: ssoConfig, loaded: ssoLoaded, load: loadSso } = useCasdoorPublic()
const signupUrl = computed(() => (ssoConfig.value ? getCasdoorSignupUrl(ssoConfig.value) : ''))
onMounted(() => {
loadSso()
})
const closeModal = () => {
if (!isRedirecting.value) {