修复用户安全信息弹窗与会话校验
This commit is contained in:
1 parent
31ee54942a
commit
306af4b7b0
12 files changed
+295
-19
No files matched your search
@@ -6,6 +6,8 @@
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!busy"
|
||||
:show-close="!busy"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
class="recovery-code-dialog"
|
||||
@update:model-value="value => { if (!value) close() }"
|
||||
>
|
||||
|
||||
+38
-11
@@ -15,6 +15,10 @@ export const userExternalEmailDialogProps = {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
selfManaged: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
}
|
||||
|
||||
const verificationCodeLength = 8
|
||||
@@ -30,6 +34,21 @@ function assertSuccess(response, fallback) {
|
||||
return response
|
||||
}
|
||||
|
||||
export function externalEmailEndpoints(selfManaged) {
|
||||
if (selfManaged) {
|
||||
return {
|
||||
list: '/api/v1/security/external-email/list',
|
||||
change: '/api/v1/security/external-email/change',
|
||||
verify: '/api/v1/security/external-email/change/verify',
|
||||
}
|
||||
}
|
||||
return {
|
||||
list: '/api/v1/user/security/external-email/list',
|
||||
change: '/api/v1/user/security/external-email/change',
|
||||
verify: '/api/v1/user/security/external-email/verify',
|
||||
}
|
||||
}
|
||||
|
||||
export function useUserExternalEmailDialog(props, emit) {
|
||||
const form = reactive({ email: '', type: 'primary', code: '' })
|
||||
const challenge = reactive({ id: '', bindingId: 0, maskedEmail: '', expiresAt: '' })
|
||||
@@ -47,6 +66,7 @@ export function useUserExternalEmailDialog(props, emit) {
|
||||
set: value => emit('update:modelValue', value),
|
||||
})
|
||||
const busy = computed(() => sending.value || verifying.value)
|
||||
const endpoints = computed(() => externalEmailEndpoints(props.selfManaged))
|
||||
const hasChallenge = computed(() => Boolean(challenge.id && challenge.bindingId))
|
||||
const remainingSeconds = computed(() => {
|
||||
if (!challenge.expiresAt) return 0
|
||||
@@ -93,12 +113,13 @@ export function useUserExternalEmailDialog(props, emit) {
|
||||
if (!props.user?.ID) return false
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.get('/api/v1/user/security/external-email/list', {
|
||||
params: { id: props.user.ID },
|
||||
})
|
||||
const config = props.selfManaged ? undefined : { params: { id: props.user.ID } }
|
||||
const result = await http.get(endpoints.value.list, config)
|
||||
return assertSuccess(result, '读取外部邮箱失败')
|
||||
})
|
||||
const items = Array.isArray(response.data?.items) ? response.data.items : []
|
||||
const items = props.selfManaged
|
||||
? (Array.isArray(response.data) ? response.data : [])
|
||||
: (Array.isArray(response.data?.items) ? response.data.items : [])
|
||||
const primary = items.find(item => item.type === 'primary') || items[0]
|
||||
currentEmail.value = primary?.email || ''
|
||||
if (primary?.type) form.type = primary.type
|
||||
@@ -122,11 +143,12 @@ export function useUserExternalEmailDialog(props, emit) {
|
||||
clearMessages()
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.post('/api/v1/user/security/external-email/change', {
|
||||
user_id: props.user.ID,
|
||||
const payload = {
|
||||
email,
|
||||
type: form.type,
|
||||
})
|
||||
}
|
||||
if (!props.selfManaged) payload.user_id = props.user.ID
|
||||
const result = await http.post(endpoints.value.change, payload)
|
||||
return assertSuccess(result, '验证码发送失败')
|
||||
})
|
||||
if (!response.data?.challenge_id || !response.data?.binding_id) {
|
||||
@@ -169,13 +191,18 @@ export function useUserExternalEmailDialog(props, emit) {
|
||||
clearMessages()
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.post('/api/v1/user/security/external-email/verify', {
|
||||
user_id: props.user.ID,
|
||||
challenge_id: challenge.id,
|
||||
const payload = {
|
||||
binding_id: challenge.bindingId,
|
||||
email: form.email,
|
||||
code,
|
||||
})
|
||||
}
|
||||
if (props.selfManaged) {
|
||||
payload.id = challenge.id
|
||||
} else {
|
||||
payload.user_id = props.user.ID
|
||||
payload.challenge_id = challenge.id
|
||||
}
|
||||
const result = await http.post(endpoints.value.verify, payload)
|
||||
return assertSuccess(result, '外部邮箱验证失败')
|
||||
})
|
||||
emit('changed')
|
||||
|
||||
+3
-1
@@ -1,11 +1,13 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="编辑外部邮箱"
|
||||
:title="selfManaged ? '编辑我的外部邮箱' : '编辑外部邮箱'"
|
||||
width="min(520px, calc(100vw - 32px))"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!busy"
|
||||
:show-close="!busy"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
class="user-external-email-dialog"
|
||||
@update:model-value="value => { if (!value) close() }"
|
||||
>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {reactive, ref} from 'vue'
|
||||
import {computed, reactive, ref} from 'vue'
|
||||
|
||||
import lang from '../../../i18n/i18n';
|
||||
|
||||
@@ -8,6 +8,8 @@ import {ElNotification} from "element-plus";
|
||||
|
||||
import {Plus} from "@element-plus/icons-vue";
|
||||
|
||||
import {useGlobalStatusStore} from "@/stores/useGlobalStatusStore";
|
||||
|
||||
const roleOptions = {
|
||||
super_admin: { label: '超级管理员', type: 'danger' },
|
||||
admin: { label: '管理员', type: 'primary' },
|
||||
@@ -39,7 +41,23 @@ export function accountStatusMeta(disabled) {
|
||||
: { label: '正常', type: 'success' }
|
||||
}
|
||||
|
||||
export function isSameUser(selectedUser, currentUser) {
|
||||
const selectedID = Number(selectedUser?.ID || 0)
|
||||
const currentID = Number(currentUser?.id || 0)
|
||||
if (selectedID > 0 && currentID > 0) {
|
||||
return selectedID === currentID
|
||||
}
|
||||
return Boolean(selectedUser?.Account && currentUser?.account)
|
||||
&& selectedUser.Account === currentUser.account
|
||||
}
|
||||
|
||||
export function canManageRecoveryCode(user) {
|
||||
return Boolean(user?.ID) && user.Role !== 'super_admin'
|
||||
}
|
||||
|
||||
export function usePage() {
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
|
||||
const userList = reactive([])
|
||||
|
||||
const currentPage = ref(1)
|
||||
@@ -55,6 +73,10 @@ export function usePage() {
|
||||
const recoveryCodeDialogVisible = ref(false)
|
||||
|
||||
const externalEmailDialogVisible = ref(false)
|
||||
|
||||
const editingCurrentUser = computed(() => isSameUser(selectedUser.value, globalStatus.userInfos))
|
||||
|
||||
const recoveryCodeWebManaged = computed(() => canManageRecoveryCode(selectedUser.value))
|
||||
|
||||
const editUserInfo = reactive({
|
||||
"account": "",
|
||||
@@ -101,7 +123,7 @@ export function usePage() {
|
||||
}
|
||||
|
||||
const openRecoveryCodeDialog = function () {
|
||||
if (!selectedUser.value?.ID) return
|
||||
if (!recoveryCodeWebManaged.value) return
|
||||
recoveryCodeDialogVisible.value = true
|
||||
}
|
||||
|
||||
@@ -174,6 +196,8 @@ export function usePage() {
|
||||
editModel,
|
||||
editUserInfo,
|
||||
selectedUser,
|
||||
editingCurrentUser,
|
||||
recoveryCodeWebManaged,
|
||||
recoveryCodeDialogVisible,
|
||||
externalEmailDialogVisible,
|
||||
openRecoveryCodeDialog,
|
||||
|
||||
@@ -115,9 +115,17 @@
|
||||
<div class="security-edit-item">
|
||||
<div>
|
||||
<strong>安全码</strong>
|
||||
<span>{{ recoveryCodeMeta(selectedUser?.RecoveryCodeConfigured).label }}</span>
|
||||
<span v-if="recoveryCodeWebManaged">
|
||||
{{ recoveryCodeMeta(selectedUser?.RecoveryCodeConfigured).label }}
|
||||
</span>
|
||||
<span v-else>部署端管理</span>
|
||||
</div>
|
||||
<el-button @click="openRecoveryCodeDialog">管理安全码</el-button>
|
||||
<el-button
|
||||
:disabled="!recoveryCodeWebManaged"
|
||||
@click="openRecoveryCodeDialog"
|
||||
>
|
||||
{{ recoveryCodeWebManaged ? '管理安全码' : '仅支持本机管理' }}
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="security-edit-item">
|
||||
<div>
|
||||
@@ -164,6 +172,7 @@
|
||||
<UserExternalEmailDialog
|
||||
v-model="externalEmailDialogVisible"
|
||||
:user="selectedUser"
|
||||
:self-managed="editingCurrentUser"
|
||||
@changed="handleSecurityChanged"
|
||||
/>
|
||||
</div>
|
||||
@@ -188,6 +197,8 @@ const {
|
||||
editModel,
|
||||
editUserInfo,
|
||||
selectedUser,
|
||||
editingCurrentUser,
|
||||
recoveryCodeWebManaged,
|
||||
recoveryCodeDialogVisible,
|
||||
externalEmailDialogVisible,
|
||||
openRecoveryCodeDialog,
|
||||
|
||||
Reference in new issue
Block a user