541e24c6f4
- 新增 admin_users/admin_sessions 表与 adminAuth 工具(scrypt 密码 + 独立会话 Cookie) - /admin/init 初始化首个管理员,未初始化时服务端/客户端双守卫引导 - 后台鉴权改为管理员会话,前台 Casdoor 用户一律普通用户、与后台解耦 - Casdoor 配置改存 settings 表并由「统一认证」页管理,移除全部 CASDOOR 环境变量 - 侧边栏增加统一认证/管理员入口与登出;LoginModal 感知 SSO 启用状态 - 补充 adminAuth 测试,重写 casdoor 测试,全部 23 项通过
61 lines
2.1 KiB
Vue
61 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* 后台管理员登录页(/admin/login):
|
|
* 独立于前台 Casdoor 认证,使用 admin_users 表账号登录。
|
|
*/
|
|
import { ref } from 'vue'
|
|
import { navigateTo } from '#app'
|
|
import { useAdminStore } from '~/stores/admin'
|
|
import { useToastStore } from '~/stores/toast'
|
|
|
|
definePageMeta({ layout: 'login' })
|
|
|
|
useHead({ title: '后台登录' })
|
|
|
|
const adminStore = useAdminStore()
|
|
const toast = useToastStore()
|
|
|
|
const username = ref('')
|
|
const password = ref('')
|
|
const submitting = ref(false)
|
|
|
|
const submit = async () => {
|
|
if (!username.value.trim() || !password.value) return
|
|
submitting.value = true
|
|
try {
|
|
const res = await adminStore.login(username.value.trim(), password.value)
|
|
if (res.success) {
|
|
toast.success('欢迎回来')
|
|
await navigateTo('/admin')
|
|
} else {
|
|
toast.error('用户名或密码错误')
|
|
}
|
|
} finally {
|
|
submitting.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="min-h-screen flex items-center justify-center px-4 py-12">
|
|
<div class="w-full max-w-md">
|
|
<div class="text-center mb-8">
|
|
<div class="mx-auto w-12 h-12 rounded-full bg-black text-white flex items-center justify-center font-bold text-xl mb-4">A</div>
|
|
<h1 class="text-2xl font-bold text-black">后台登录</h1>
|
|
<p class="mt-2 text-sm text-gray-500">请使用后台管理员账号登录</p>
|
|
</div>
|
|
|
|
<form class="bg-white rounded-2xl border border-gray-100 shadow-sm p-6 space-y-4" @submit.prevent="submit">
|
|
<AdminInput v-model="username" label="用户名" placeholder="管理员用户名" autocomplete="username" />
|
|
<AdminInput v-model="password" label="密码" type="password" placeholder="登录密码" autocomplete="current-password" />
|
|
<AdminButton type="submit" block :loading="submitting">
|
|
{{ submitting ? '登录中…' : '登录' }}
|
|
</AdminButton>
|
|
</form>
|
|
|
|
<p class="mt-6 text-center text-sm text-gray-400">
|
|
<NuxtLink to="/" class="hover:text-gray-600">← 返回前台</NuxtLink>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</template> |