支持通知凭据验证后查看并收紧账号权限
This commit is contained in:
1 parent
85feb38c5d
commit
a1dc20af85
9 files changed
+240
-29
No files matched your search
@@ -60,6 +60,51 @@
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.notification-credential {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
margin: 12px 0;
|
||||
border: 1px solid var(--el-border-color-light);
|
||||
border-radius: 8px;
|
||||
background: var(--el-fill-color-light);
|
||||
}
|
||||
|
||||
.notification-credential-label {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.notification-credential-code {
|
||||
flex: 1 1 320px;
|
||||
min-width: 0;
|
||||
font-size: 13px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.notification-credential-mask {
|
||||
letter-spacing: 2px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.notification-credential-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.notification-credential-actions :deep(.el-button + .el-button) {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.notification-countdown {
|
||||
color: var(--el-color-warning-dark-2);
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.notification-compact {
|
||||
gap: 10px;
|
||||
padding: 0;
|
||||
|
||||
@@ -20,12 +20,17 @@ export function usePage(props = {}) {
|
||||
const secretAccount = ref('')
|
||||
const secretVisible = ref(false)
|
||||
const seconds = ref(0)
|
||||
const verifyVisible = ref(false)
|
||||
const verifyPassword = ref('')
|
||||
let verifyTarget = null
|
||||
let secretSequence = 0
|
||||
let secretTimer = null
|
||||
let requestSequence = 0
|
||||
let accountsSequence = 0
|
||||
let disposed = false
|
||||
|
||||
const canManage = computed(() => manager.value && Boolean(status.value?.can_manage))
|
||||
const canReveal = computed(() => Boolean(status.value?.can_reveal))
|
||||
const stateText = computed(() => {
|
||||
if (!status.value?.enabled) return '未开启'
|
||||
if (!status.value.account_available) return '账号不可用'
|
||||
@@ -44,6 +49,7 @@ export function usePage(props = {}) {
|
||||
ElNotification({ title: '操作失败', message: cause?.message || '请稍后重试', type: 'error' })
|
||||
}
|
||||
const clearSecret = () => {
|
||||
secretSequence += 1
|
||||
if (secretTimer) clearInterval(secretTimer)
|
||||
secretTimer = null
|
||||
secret.value = ''
|
||||
@@ -52,6 +58,55 @@ export function usePage(props = {}) {
|
||||
secretVisible.value = false
|
||||
}
|
||||
|
||||
const clearVerification = () => {
|
||||
verifyPassword.value = ''
|
||||
verifyTarget = null
|
||||
verifyVisible.value = false
|
||||
}
|
||||
const showSecret = (code, account) => {
|
||||
clearSecret()
|
||||
if (!code || document.hidden) return
|
||||
secret.value = code
|
||||
secretAccount.value = account
|
||||
secretVisible.value = true
|
||||
const expiresAt = Date.now() + 60000
|
||||
seconds.value = 60
|
||||
secretTimer = setInterval(() => {
|
||||
seconds.value = Math.max(0, Math.ceil((expiresAt - Date.now()) / 1000))
|
||||
if (seconds.value === 0) clearSecret()
|
||||
}, 250)
|
||||
}
|
||||
const openVerify = () => {
|
||||
if (!canReveal.value || loading.value || submitting.value || dirty.value) return
|
||||
clearSecret()
|
||||
verifyPassword.value = ''
|
||||
verifyTarget = status.value
|
||||
verifyVisible.value = true
|
||||
}
|
||||
const verifyAndReveal = async () => {
|
||||
if (!verifyTarget || !verifyPassword.value || submitting.value || !canReveal.value) return
|
||||
const target = verifyTarget
|
||||
const sequence = ++secretSequence
|
||||
submitting.value = true
|
||||
try {
|
||||
const data = dataOf(await http.post('/api/v1/system/notification/credential/reveal', {
|
||||
user_id: target.user_id, version: target.version, password: verifyPassword.value
|
||||
}))
|
||||
if (disposed || sequence !== secretSequence || target.user_id !== status.value?.user_id) return
|
||||
clearVerification()
|
||||
showSecret(data.code, target.account)
|
||||
} catch (cause) { showError(cause) }
|
||||
finally {
|
||||
verifyPassword.value = ''
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
const hideOnBackground = () => {
|
||||
if (!document.hidden) return
|
||||
clearSecret()
|
||||
clearVerification()
|
||||
}
|
||||
|
||||
const loadStatus = async () => {
|
||||
const sequence = ++requestSequence
|
||||
loading.value = true
|
||||
@@ -103,6 +158,7 @@ export function usePage(props = {}) {
|
||||
}
|
||||
const refresh = async () => {
|
||||
if (!(await beforeLeave())) return
|
||||
clearSecret()
|
||||
await Promise.all([loadStatus(), loadAccounts()])
|
||||
}
|
||||
const save = async () => {
|
||||
@@ -135,19 +191,12 @@ export function usePage(props = {}) {
|
||||
confirmButtonText: '生成新凭据', cancelButtonText: '取消', type: 'warning'
|
||||
})
|
||||
submitting.value = true
|
||||
const sequence = ++secretSequence
|
||||
const data = dataOf(await requestWithRecentAuthentication(() => http.post('/api/v1/system/notification/credential', {
|
||||
user_id: target.user_id, version: target.version
|
||||
})))
|
||||
if (disposed) return
|
||||
clearSecret()
|
||||
secret.value = data.code
|
||||
secretAccount.value = target.account
|
||||
seconds.value = 60
|
||||
secretVisible.value = true
|
||||
secretTimer = setInterval(() => {
|
||||
seconds.value -= 1
|
||||
if (seconds.value <= 0) clearSecret()
|
||||
}, 1000)
|
||||
if (sequence === secretSequence) showSecret(data.code, target.account)
|
||||
await Promise.all([loadStatus(), loadAccounts()])
|
||||
} catch (cause) { showError(cause) }
|
||||
finally { submitting.value = false }
|
||||
@@ -160,12 +209,24 @@ export function usePage(props = {}) {
|
||||
} catch { showError(new Error('复制失败,请手动复制授权码')) }
|
||||
}
|
||||
|
||||
onMounted(() => { loadStatus(); loadAccounts() })
|
||||
onUnmounted(() => { disposed = true; requestSequence += 1; accountsSequence += 1; clearSecret() })
|
||||
onMounted(() => {
|
||||
loadStatus()
|
||||
loadAccounts()
|
||||
document.addEventListener('visibilitychange', hideOnBackground)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
disposed = true
|
||||
requestSequence += 1
|
||||
accountsSequence += 1
|
||||
clearSecret()
|
||||
clearVerification()
|
||||
document.removeEventListener('visibilitychange', hideOnBackground)
|
||||
})
|
||||
|
||||
return {
|
||||
manager, loading, submitting, error, status, accounts, page, total, form,
|
||||
secret, secretAccount, secretVisible, seconds, canManage, stateText, dirty,
|
||||
canReveal, verifyVisible, verifyPassword, openVerify, verifyAndReveal, clearVerification,
|
||||
loadAccounts, selectAccount, refresh, save, rotate, clearSecret, copySecret, beforeLeave
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
<el-alert
|
||||
v-if="!compact"
|
||||
title="默认关闭,逐账号授权"
|
||||
:description="manager ? '只有管理范围内的账号可以授权。管理员修改授权前需要身份确认;关闭时永久撤销旧凭据。' : '普通用户只能查看自己的状态和连接参数。需要开启或重置凭据时,请联系管理员。'"
|
||||
:description="manager ? '只有管理范围内的账号可以授权。管理员修改授权前需要身份确认;关闭时永久撤销旧凭据。' : '可查看自己的状态,并验证本人密码查看通知凭据。开启或重置凭据请联系管理员。'"
|
||||
type="info"
|
||||
show-icon
|
||||
:closable="false"
|
||||
@@ -54,6 +54,30 @@
|
||||
</div>
|
||||
<p v-if="!status.account_available" class="notification-warning">账号已禁用或尚未修改临时密码,不能生成或使用通知凭据。</p>
|
||||
|
||||
<div v-if="status.configured" class="notification-credential">
|
||||
<span class="notification-credential-label">通知发信凭据</span>
|
||||
<template v-if="secretVisible && secret">
|
||||
<code class="notification-credential-code">{{ secret }}</code>
|
||||
<div class="notification-credential-actions">
|
||||
<el-button size="small" type="primary" @click="copySecret">复制凭据</el-button>
|
||||
<el-button size="small" @click="clearSecret">隐藏</el-button>
|
||||
<span class="notification-countdown" role="status">{{ seconds }} 秒后自动隐藏</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="notification-credential-mask" aria-label="凭据已隐藏">••••••••••••••••</span>
|
||||
<el-button
|
||||
v-if="canReveal"
|
||||
size="small"
|
||||
type="primary"
|
||||
plain
|
||||
:disabled="submitting || loading || dirty"
|
||||
@click="openVerify"
|
||||
>安全验证查看明文</el-button>
|
||||
<span v-else class="notification-hint">旧凭据未保留密文,请联系管理员重新生成。</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="notification-columns">
|
||||
<el-form v-if="canManage" label-position="top" :disabled="submitting || loading" @submit.prevent="save">
|
||||
<el-form-item label="允许该账号通过 SMTP 发送系统通知">
|
||||
@@ -99,13 +123,34 @@
|
||||
<el-empty v-else-if="!loading && !error" description="尚未读取账号状态" />
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="secretVisible" title="通知发信凭据(仅显示一次)" width="min(560px, 92vw)" destroy-on-close @closed="clearSecret">
|
||||
<p>账号:{{ secretAccount }}。请安全保存并交付给该账号的使用者。</p>
|
||||
<el-alert :title="`${seconds} 秒后自动隐藏;关闭后无法再次查看,只能重新生成。`" type="warning" :closable="false" show-icon />
|
||||
<el-input :model-value="secret" readonly aria-label="新通知发信凭据" class="notification-secret" />
|
||||
<el-dialog
|
||||
v-model="verifyVisible"
|
||||
title="安全验证"
|
||||
width="min(420px, 92vw)"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!submitting"
|
||||
:show-close="!submitting"
|
||||
@closed="clearVerification"
|
||||
>
|
||||
<el-form label-position="top" @submit.prevent="verifyAndReveal">
|
||||
<el-form-item label="当前登录密码">
|
||||
<el-input
|
||||
v-model="verifyPassword"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
placeholder="请输入本人登录密码"
|
||||
:disabled="submitting"
|
||||
aria-label="当前登录密码"
|
||||
/>
|
||||
</el-form-item>
|
||||
<p class="notification-hint">验证后显示 60 秒,隐藏后可重新验证查看。</p>
|
||||
<button type="submit" hidden></button>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="copySecret">复制凭据</el-button>
|
||||
<el-button type="primary" @click="clearSecret">已保存,关闭</el-button>
|
||||
<el-button :disabled="submitting" @click="clearVerification">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" :disabled="!verifyPassword" @click="verifyAndReveal">验证并查看</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</section>
|
||||
@@ -122,6 +167,7 @@ const props = defineProps({
|
||||
const {
|
||||
manager, loading, submitting, error, status, accounts, page, total, form,
|
||||
secret, secretAccount, secretVisible, seconds, canManage, stateText, dirty,
|
||||
canReveal, verifyVisible, verifyPassword, openVerify, verifyAndReveal, clearVerification,
|
||||
loadAccounts, selectAccount, refresh, save, rotate, clearSecret, copySecret, beforeLeave
|
||||
} = usePage(props)
|
||||
|
||||
|
||||
Reference in new issue
Block a user