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:
@@ -1,14 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 后台左侧导航栏:按「内容 / 数据 / 系统」分组,底部返回前台。
|
||||
* 后台左侧导航栏:按「内容 / 数据 / 系统」分组,底部显示当前管理员可退出。
|
||||
* 高亮当前路由;点击任意导航项时向父级发出 navigate 事件(移动端关闭侧栏)。
|
||||
*/
|
||||
import { useRoute } from '#app'
|
||||
import { useSiteSettings } from '~/composables/useSiteSettings'
|
||||
import { useAdminStore } from '~/stores/admin'
|
||||
|
||||
const route = useRoute()
|
||||
const emit = defineEmits<{ navigate: [] }>()
|
||||
const { settings } = useSiteSettings()
|
||||
const adminStore = useAdminStore()
|
||||
|
||||
const handleLogout = async () => {
|
||||
await adminStore.logout()
|
||||
emit('navigate')
|
||||
navigateTo('/admin/login')
|
||||
}
|
||||
|
||||
interface SidebarItem {
|
||||
to: string
|
||||
@@ -42,6 +50,8 @@ const groups: SidebarGroup[] = [
|
||||
{
|
||||
label: '系统',
|
||||
items: [
|
||||
{ to: '/admin/casdoor', label: '统一认证', icon: 'ph:sign-in' },
|
||||
{ to: '/admin/admins', label: '管理员', icon: 'ph:shield-check' },
|
||||
{ to: '/admin/uploads', label: '图片管理', icon: 'ph:image' },
|
||||
{ to: '/admin/audit', label: '操作日志', icon: 'ph:list-checks' },
|
||||
{ to: '/admin/settings', label: '站点设置', icon: 'ph:gear-six' },
|
||||
@@ -93,7 +103,18 @@ const isActive = (to: string) => route.path === to
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="p-3 border-t border-white/10 shrink-0">
|
||||
<div class="p-3 border-t border-white/10 shrink-0 space-y-1">
|
||||
<div class="flex items-center gap-3 px-3 py-2.5">
|
||||
<div
|
||||
class="w-8 h-8 rounded-full bg-white/10 text-white flex items-center justify-center font-bold text-xs flex-shrink-0"
|
||||
>
|
||||
{{ (adminStore.admin?.username || 'A').charAt(0).toUpperCase() }}
|
||||
</div>
|
||||
<div class="min-w-0 leading-tight">
|
||||
<p class="text-sm font-semibold text-white truncate">{{ adminStore.admin?.username || '管理员' }}</p>
|
||||
<p class="text-[11px] text-white/40">后台账号</p>
|
||||
</div>
|
||||
</div>
|
||||
<NuxtLink
|
||||
to="/"
|
||||
class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium text-white/70 hover:bg-white/10 hover:text-white transition-colors"
|
||||
@@ -102,6 +123,14 @@ const isActive = (to: string) => route.path === to
|
||||
<Icon name="ph:arrow-left" class="w-[18px] h-[18px]" />
|
||||
返回前台
|
||||
</NuxtLink>
|
||||
<button
|
||||
type="button"
|
||||
class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium text-white/70 hover:bg-white/10 hover:text-white transition-colors"
|
||||
@click="handleLogout"
|
||||
>
|
||||
<Icon name="ph:sign-out" class="w-[18px] h-[18px]" />
|
||||
退出登录
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user