Files
arcticnewone/app/components/common/LoginModal.vue
T
virtheart 337eb4f05a feat: 登录改为 Casdoor 统一身份认证(SSO),重建用户体系
- 移除内置密码注册/登录/改密/删号/头像,统一走 Casdoor OIDC 授权码
- 服务端 casdoor-nodejs-sdk:code 换 token + 证书公钥验签 + get-account 补齐资料
- 用户表重建为 provider+provider_id(Casdoor sub 为准),邮箱不再唯一
- 管理员由 Casdoor token 的 isAdmin/IsAdmin 字段或 admin 角色判定,删除角色切换接口
- 前端登录弹窗改为申统认证跳转,注册去 Casdoor;后台用户列表只读角色
- 会话沿用 an_session httpOnly Cookie,requireUser/requireAdmin 守卫保留
- 配置注入 deploy.sh/.env.example;新增 casdoor 单测,删除 password 单测
2026-08-09 00:18:47 +08:00

127 lines
3.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<Teleport to="body">
<Transition name="modal">
<div
v-if="authModal.isLoginOpen"
class="fixed inset-0 z-[100] flex items-center justify-center bg-black/50 backdrop-blur-sm px-4"
@click.self="closeModal"
>
<div
class="relative w-full max-w-md bg-white rounded-2xl shadow-2xl overflow-hidden"
@click.stop
>
<!-- 关闭按钮 -->
<button
@click="closeModal"
class="absolute top-4 right-4 w-8 h-8 flex items-center justify-center rounded-full hover:bg-gray-100 transition-colors z-10"
aria-label="Close"
>
<Icon name="ph:x" class="w-5 h-5 text-gray-600" />
</button>
<!-- 统一身份认证 -->
<div class="p-8">
<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>
<!-- 登录按钮:跳转 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 注册页 -->
<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>
</div>
</div>
</div>
</Transition>
</Teleport>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRoute } from '#app'
import { useI18n } from 'vue-i18n'
import { useAuthModalStore } from '~/stores/authModal'
import { getCasdoorSignupUrl } from '~/utils/casdoorClient'
const { t } = useI18n()
const route = useRoute()
const authModal = useAuthModalStore()
const isRedirecting = ref(false)
const signupUrl = getCasdoorSignupUrl()
const closeModal = () => {
if (!isRedirecting.value) {
authModal.closeAll()
}
}
// 打开时重置状态
watch(
() => authModal.isLoginOpen,
(open) => {
if (open) isRedirecting.value = false
},
)
const handleLogin = () => {
if (isRedirecting.value) return
isRedirecting.value = true
const next = route.fullPath
const target = next.startsWith('/') && !next.startsWith('//') ? next : '/'
const url = `/api/auth/casdoor-login?next=${encodeURIComponent(target)}`
window.location.assign(url)
}
// ESC 关闭
const handleKeydown = (e: KeyboardEvent) => {
if (e.key === 'Escape' && authModal.isLoginOpen) {
closeModal()
}
}
if (typeof window !== 'undefined') {
window.addEventListener('keydown', handleKeydown)
}
</script>
<style scoped>
.modal-enter-active,
.modal-leave-active {
transition: opacity 0.3s ease;
}
.modal-enter-from,
.modal-leave-to {
opacity: 0;
}
.modal-enter-active .relative,
.modal-leave-active .relative {
transition: transform 0.3s ease, opacity 0.3s ease;
}
.modal-enter-from .relative {
transform: scale(0.95) translateY(20px);
opacity: 0;
}
.modal-leave-to .relative {
transform: scale(0.95) translateY(20px);
opacity: 0;
}
</style>