强制超级管理员配置安全验证并保护本机密码重置
This commit is contained in:
1 parent
f1be78e866
commit
b6786a0c2c
38 files changed
+1128
-135
No files matched your search
@@ -29,11 +29,11 @@ watch(
|
||||
<div v-else id="main">
|
||||
<HomeHeader v-if="!standalonePages.includes(pageName)"/>
|
||||
<div id="content">
|
||||
<div id="aside" v-if="!standalonePages.includes(pageName)">
|
||||
<div id="aside" v-if="!standalonePages.includes(pageName) && !globalStatus.userInfos.securitySetupRequired">
|
||||
<HomeAside/>
|
||||
</div>
|
||||
<el-drawer
|
||||
v-if="!standalonePages.includes(pageName)"
|
||||
v-if="!standalonePages.includes(pageName) && !globalStatus.userInfos.securitySetupRequired"
|
||||
v-model="globalStatus.mobileDrawerVisible"
|
||||
direction="ltr"
|
||||
size="243px"
|
||||
@@ -49,7 +49,7 @@ watch(
|
||||
'recovery-fit': pageName === 'forgot-password'
|
||||
}"
|
||||
>
|
||||
<RouterView v-slot="{ Component }">
|
||||
<RouterView v-if="!globalStatus.userInfos.securitySetupRequired || standalonePages.includes(pageName)" v-slot="{ Component }">
|
||||
<transition name="page-fade" mode="out-in">
|
||||
<component :is="Component" />
|
||||
</transition>
|
||||
|
||||
@@ -58,6 +58,7 @@ export function usePage() {
|
||||
{ key: 'sender-filter', label: '黑白名单', hint: '发件人信任与拦截', icon: Checked, component: SenderFilterManagement, capability: 'user.read' },
|
||||
{ key: 'logs', label: '日志', hint: '操作、收发信与运行记录', icon: Document, component: LogSettings, capability: 'audit.read' },
|
||||
].filter(item => {
|
||||
if (globalStatus.userInfos?.securitySetupRequired && item.key !== 'security') return false
|
||||
// 日志数据范围由服务端强制过滤;菜单只决定入口是否可见。
|
||||
return globalStatus.hasCapability(item.capability) ||
|
||||
(item.key === 'plugins' && globalStatus.hasCapability('plugin.read_global'))
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ElMessageBox, ElNotification } from 'element-plus'
|
||||
|
||||
import lang from '../../../i18n/i18n'
|
||||
import { http } from '@/utils/axios'
|
||||
import { requestWithRecentAuthentication } from '@/utils/recentAuthentication'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
import { normalizeCreationOptions, serializeCredential, webAuthnSupported } from '@/utils/webauthn'
|
||||
|
||||
@@ -21,13 +22,13 @@ export function usePage() {
|
||||
}
|
||||
options.push({ value: 'password', label: lang.modify_pwd })
|
||||
options.push({ value: 'question', label: '密保问题' })
|
||||
if (!isSuperAdmin.value) {
|
||||
options.push({ value: 'recovery', label: '安全码' })
|
||||
}
|
||||
options.push({ value: 'recovery', label: '安全码' })
|
||||
options.push({ value: 'external-email', label: '外部安全邮箱' })
|
||||
options.push({ value: 'totp', label: '手机动态码' })
|
||||
options.push({ value: 'webauthn', label: '安全密钥' })
|
||||
return options
|
||||
return globalStatus.userInfos.securitySetupRequired
|
||||
? options.filter(item => ['recovery', 'external-email', 'totp'].includes(item.value))
|
||||
: options
|
||||
})
|
||||
const selectedSection = computed({
|
||||
get: () => globalStatus.securityActiveSection,
|
||||
@@ -87,6 +88,7 @@ export function usePage() {
|
||||
}
|
||||
|
||||
const loadCredentials = async () => {
|
||||
if (globalStatus.userInfos.securitySetupRequired) return
|
||||
if (!supported || !webAuthnEnabled.value) return
|
||||
credentialsLoading.value = true
|
||||
try {
|
||||
@@ -107,9 +109,7 @@ export function usePage() {
|
||||
http.get('/api/v1/security/credentials/question'),
|
||||
http.get('/api/v1/security/external-email/list'),
|
||||
]
|
||||
if (!isSuperAdmin.value) {
|
||||
requests.push(http.get('/api/v1/security/credentials/recovery-codes'))
|
||||
}
|
||||
requests.push(http.get('/api/v1/security/credentials/recovery-codes'))
|
||||
const [question, external, recovery] = await Promise.all(requests)
|
||||
if (question.errorNo === 0 && question.data) {
|
||||
securityQuestion.configured = Boolean(question.data.configured)
|
||||
@@ -131,6 +131,7 @@ export function usePage() {
|
||||
const response = await http.get('/api/v1/security/external-email/list')
|
||||
if (response.errorNo !== 0) throw new Error(response.errorMsg || '读取外部邮箱失败')
|
||||
externalEmails.value = Array.isArray(response.data) ? response.data : []
|
||||
await globalStatus.refresh()
|
||||
return true
|
||||
} catch (error) {
|
||||
notify(error?.message || '读取外部邮箱失败')
|
||||
@@ -214,10 +215,11 @@ export function usePage() {
|
||||
const generateRecoveryCodes = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm('生成新恢复码会撤销当前仍有效的恢复码,请确认已准备好安全保存。', '生成离线恢复码', { type: 'warning' })
|
||||
const res = await http.post('/api/v1/security/credentials/recovery-codes/generate', { count: 10 })
|
||||
const res = await requestWithRecentAuthentication(() => http.post('/api/v1/security/credentials/recovery-codes/generate', { count: 10 }))
|
||||
if (res.errorNo !== 0 || !Array.isArray(res.data?.codes)) throw new Error(res.errorMsg || '离线恢复码生成失败')
|
||||
generatedCodes.value = res.data.codes
|
||||
recoveryConfigured.value = true
|
||||
await globalStatus.refresh()
|
||||
notify('恢复码已生成,请仅保存这一次显示的内容', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '离线恢复码生成失败')
|
||||
@@ -227,10 +229,11 @@ export function usePage() {
|
||||
const revokeRecoveryCodes = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm('撤销后现有离线恢复码将立即失效,是否继续?', '撤销离线恢复码', { type: 'warning' })
|
||||
const res = await http.post('/api/v1/security/credentials/recovery-codes/revoke', {})
|
||||
const res = await requestWithRecentAuthentication(() => http.post('/api/v1/security/credentials/recovery-codes/revoke', {}))
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '撤销恢复码失败')
|
||||
recoveryConfigured.value = false
|
||||
generatedCodes.value = []
|
||||
await globalStatus.refresh()
|
||||
notify('离线恢复码已撤销', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '撤销恢复码失败')
|
||||
@@ -252,6 +255,7 @@ export function usePage() {
|
||||
const res = await http.post('/api/v1/security/external-email/disable', { id: item.id })
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '外部邮箱停用失败')
|
||||
await loadSecurityData()
|
||||
await globalStatus.refresh()
|
||||
notify('外部邮箱已停用', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '外部邮箱停用失败')
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
</section>
|
||||
|
||||
<el-divider v-if="selectedSection === 'recovery'" class="settings-divider" />
|
||||
<section v-if="selectedSection === 'recovery' && !isSuperAdmin" class="security-section">
|
||||
<section v-if="selectedSection === 'recovery'" class="security-section">
|
||||
<div class="settings-header security-key-header">
|
||||
<div><h3>安全码</h3><p class="settings-desc">安全码只在生成时显示一次,请妥善保存。</p></div>
|
||||
<div class="section-actions"><el-button type="primary" @click="generateRecoveryCodes">生成新恢复码</el-button><el-button v-if="recoveryConfigured" type="danger" plain @click="revokeRecoveryCodes">撤销</el-button></div>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import QRCode from 'qrcode'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { http } from '@/utils/axios'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
import { isRecentAuthenticationCancelled, requestWithRecentAuthentication } from '@/utils/recentAuthentication'
|
||||
|
||||
export function useTOTPSettings() {
|
||||
@@ -49,6 +50,7 @@ export function useTOTPSettings() {
|
||||
} else {
|
||||
clearEnrollment()
|
||||
await load()
|
||||
if (action !== 'cancel') await useGlobalStatusStore().refresh()
|
||||
if (action !== 'cancel') ElMessage.success(action === 'confirm' ? '手机动态码已启用' : '手机动态码已关闭')
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -6,23 +6,35 @@ export function usePage() {
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
const required = computed(() => globalStatus.userInfos.securitySetupRequired === true)
|
||||
const visible = computed(() => globalStatus.isLogin
|
||||
&& globalStatus.userInfos.showSecuritySetupPrompt === true
|
||||
&& !(required.value && globalStatus.settingsDrawerVisible)
|
||||
&& !globalStatus.userInfos.must_change_password)
|
||||
const isSuperAdmin = computed(() => globalStatus.role === 'super_admin')
|
||||
const options = computed(() => {
|
||||
const items = []
|
||||
if (!isSuperAdmin.value && !globalStatus.userInfos.recoveryCodesConfigured) {
|
||||
if (!globalStatus.userInfos.recoveryCodesConfigured) {
|
||||
items.push({ key: 'recovery', title: '安全码', description: '生成安全码并妥善保存。' })
|
||||
}
|
||||
if (!globalStatus.userInfos.externalEmailConfigured) {
|
||||
items.push({ key: 'external-email', title: '外部邮箱', description: '绑定邮箱并完成验证。' })
|
||||
}
|
||||
if (isSuperAdmin.value && !globalStatus.userInfos.totpConfigured) {
|
||||
items.push({ key: 'totp', title: '手机动态码', description: '使用手机验证器完成绑定。' })
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
||||
const acknowledge = async section => {
|
||||
if (saving.value) return
|
||||
if (required.value) {
|
||||
if (!section) return
|
||||
globalStatus.securityActiveSection = section
|
||||
globalStatus.settingsActiveTab = 'security'
|
||||
globalStatus.settingsDrawerVisible = true
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
error.value = ''
|
||||
const account = globalStatus.userInfos.account
|
||||
@@ -44,5 +56,19 @@ export function usePage() {
|
||||
}
|
||||
}
|
||||
|
||||
return { visible, isSuperAdmin, options, saving, error, acknowledge }
|
||||
const logout = async () => {
|
||||
if (saving.value) return
|
||||
saving.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await http.post('/api/v1/logout', {})
|
||||
if (result.errorNo !== 0) throw new Error(result.errorMsg || '注销失败,请重试')
|
||||
location.reload()
|
||||
} catch (failure) {
|
||||
error.value = failure?.message || '注销失败,请重试'
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { visible, isSuperAdmin, required, options, saving, error, acknowledge, logout }
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
:show-close="false"
|
||||
class="security-setup-dialog"
|
||||
>
|
||||
<p class="setup-description">{{ isSuperAdmin ? '请绑定外部邮箱。未完成前,每次登录都会提醒。' : '请设置安全码并绑定外部邮箱。未完成前,每次登录都会提醒。' }}</p>
|
||||
<p class="setup-description">{{ isSuperAdmin ? '请至少启用一种安全验证后继续。' : '请设置安全码并绑定外部邮箱。未完成前,每次登录都会提醒。' }}</p>
|
||||
<div class="setup-options">
|
||||
<section v-for="item in options" :key="item.key" class="setup-option">
|
||||
<div>
|
||||
@@ -20,7 +20,8 @@
|
||||
</div>
|
||||
<el-alert v-if="error" :title="error" type="error" :closable="false" show-icon />
|
||||
<template #footer>
|
||||
<el-button :loading="saving" @click="acknowledge()">我知道了</el-button>
|
||||
<el-button v-if="required" :icon="SwitchButton" :loading="saving" @click="logout">注销</el-button>
|
||||
<el-button v-if="!required" :loading="saving" @click="acknowledge()">我知道了</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="acknowledge(options[0]?.key)">去设置</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -28,8 +29,9 @@
|
||||
|
||||
<script setup>
|
||||
import { usePage } from './SecuritySetupPrompt.js'
|
||||
import { SwitchButton } from '@element-plus/icons-vue'
|
||||
|
||||
const { visible, isSuperAdmin, options, saving, error, acknowledge } = usePage()
|
||||
const { visible, isSuperAdmin, required, options, saving, error, acknowledge, logout } = usePage()
|
||||
</script>
|
||||
|
||||
<style scoped src="./SecuritySetupPrompt.css"></style>
|
||||
Reference in new issue
Block a user