perf: 统一校验当前用户api

This commit is contained in:
feng626 2022-06-06 22:11:09 +08:00
parent 1cb10902d5
commit 68d97242cc
10 changed files with 131 additions and 134 deletions

View File

@ -1,8 +1,8 @@
<template> <template>
<div> <div>
<MFAVerifyDialog <UserConfirmDialog
@MFAVerifyDone="getAuthInfo" @UserConfirmDone="getAuthInfo"
@MFAVerifyCancel="exit" @UserConfirmCancel="exit"
/> />
<Dialog <Dialog
:title="dialogTitle" :title="dialogTitle"
@ -36,12 +36,12 @@
<script> <script>
import Dialog from '@/components/Dialog' import Dialog from '@/components/Dialog'
import MFAVerifyDialog from '@/components/MFAVerifyDialog' import UserConfirmDialog from '@/components/UserConfirmDialog'
export default { export default {
name: 'ShowSecretInfo', name: 'ShowSecretInfo',
components: { components: {
Dialog, Dialog,
MFAVerifyDialog UserConfirmDialog
}, },
props: { props: {
account: { account: {

View File

@ -1,8 +1,8 @@
<template> <template>
<div> <div>
<MFAVerifyDialog <UserConfirmDialog
@MFAVerifyDone="getAuthInfo" @UserConfirmDone="getAuthInfo"
@MFAVerifyCancel="exit" @UserConfirmCancel="exit"
/> />
<Dialog <Dialog
:title="dialogTitle" :title="dialogTitle"
@ -33,12 +33,12 @@
<script> <script>
import Dialog from '@/components/Dialog' import Dialog from '@/components/Dialog'
import MFAVerifyDialog from '@/components/MFAVerifyDialog' import UserConfirmDialog from '@/components/UserConfirmDialog'
export default { export default {
name: 'ShowSecretInfo', name: 'ShowSecretInfo',
components: { components: {
Dialog, Dialog,
MFAVerifyDialog UserConfirmDialog
}, },
props: { props: {
account: { account: {

View File

@ -1,9 +1,9 @@
<template> <template>
<div> <div>
<MFAVerifyDialog <UserConfirmDialog
v-if="mfaDialogShow" v-if="mfaDialogShow"
@MFAVerifyDone="showExportDialog" @UserConfirmDone="showExportDialog"
@MFAVerifyCancel="handleExportCancel" @UserConfirmCancel="handleExportCancel"
/> />
<Dialog <Dialog
v-if="exportDialogShow" v-if="exportDialogShow"
@ -31,7 +31,7 @@
<script> <script>
import Dialog from '@/components/Dialog' import Dialog from '@/components/Dialog'
import MFAVerifyDialog from '@/components/MFAVerifyDialog' import UserConfirmDialog from '@/components/UserConfirmDialog'
import { createSourceIdCache } from '@/api/common' import { createSourceIdCache } from '@/api/common'
import * as queryUtil from '@/components/DataTable/compenents/el-data-table/utils/query' import * as queryUtil from '@/components/DataTable/compenents/el-data-table/utils/query'
@ -39,7 +39,7 @@ export default {
name: 'ExportDialog', name: 'ExportDialog',
components: { components: {
Dialog, Dialog,
MFAVerifyDialog UserConfirmDialog
}, },
props: { props: {
selectedRows: { selectedRows: {

View File

@ -1,77 +0,0 @@
<template>
<Dialog
:title="$t('common.MFAVerify')"
:width="'50'"
:show-confirm="false"
:show-cancel="false"
:visible.sync="visible"
:destroy-on-close="true"
v-bind="$attrs"
v-on="$listeners"
>
<el-row :gutter="20">
<el-col :md="4" :sm="24">
<div style="line-height: 34px;text-align: center">MFA</div>
</el-col>
<el-col :md="14" :sm="24">
<el-input v-model="MFAToken" />
<span class="help-tips help-block">{{ $t('common.MFARequireForSecurity') }}</span>
</el-col>
<el-col :md="4" :sm="24">
<el-button size="mini" type="primary" style="line-height:20px " @click="verifyMFA">
{{ this.$t('common.Confirm') }}
</el-button>
</el-col>
</el-row>
</Dialog>
</template>
<script>
import Dialog from '@/components/Dialog'
export default {
name: 'MFAVerifyDialog',
components: {
Dialog
},
data() {
return {
MFAToken: '',
visible: false
}
},
watch: {
visible(val) {
if (!val) {
this.$emit('MFAVerifyCancel', true)
}
}
},
mounted() {
this.$axios.get('/api/v1/authentication/otp/verify/', { disableFlashErrorMsg: true }).then(() => {
this.$emit('MFAVerifyDone', true)
}).catch(err => {
this.$log.debug('Verify otp code error: ', err)
this.visible = true
})
},
methods: {
verifyMFA() {
if (this.MFAToken.length !== 6) {
return this.$message.error(this.$tc('common.MFAErrorMsg'))
}
this.$axios.post(
`/api/v1/authentication/otp/verify/`, {
code: this.MFAToken
}
).then(res => {
this.$emit('MFAVerifyDone', true)
})
}
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,92 @@
<template>
<Dialog
:title="$t('common.CurrentUserVerify')"
:width="'50'"
:show-confirm="false"
:show-cancel="false"
:visible.sync="visible"
:destroy-on-close="true"
v-bind="$attrs"
v-on="$listeners"
>
<el-row :gutter="20">
<el-col :md="4" :sm="24">
<div style="line-height: 34px;text-align: center">{{ Label }}</div>
</el-col>
<el-col :md="14" :sm="24">
<el-input v-model="SecretKey" />
<span class="help-tips help-block">{{ HelpText }}</span>
</el-col>
<el-col :md="4" :sm="24">
<el-button size="mini" type="primary" style="line-height:20px " @click="userConfirm">
{{ this.$t('common.Confirm') }}
</el-button>
</el-col>
</el-row>
</Dialog>
</template>
<script>
import Dialog from '@/components/Dialog'
export default {
name: 'UserConfirmDialog',
components: {
Dialog
},
data() {
return {
Label: '',
HelpText: '',
ConfirmType: '',
SecretKey: '',
visible: false
}
},
watch: {
visible(val) {
if (!val) {
this.$emit('UserConfirmCancel', true)
}
}
},
mounted() {
this.$axios.get('/api/v1/authentication/confirm/', { disableFlashErrorMsg: true }).then(() => {
this.$emit('UserConfirmDone', true)
}).catch(err => {
this.$log.debug('Verify otp code error: ', err)
const backends = err.response.data.backends
backends.sort((a, b) => b.level - a.level)
this.ConfirmType = backends[0].name
if (this.ConfirmType === 'relogin') {
return this.$message.error(this.$t('auth.ReLogin'))
} else if (this.ConfirmType === 'mfa') {
this.Label = 'MFA'
this.HelpText = this.$t('common.MFARequireForSecurity')
} else if (this.ConfirmType === 'password') {
this.Label = this.$t('setting.password')
this.HelpText = this.$t('common.PasswordRequireForSecurity')
}
this.visible = true
})
},
methods: {
userConfirm() {
if (this.ConfirmType === 'mfa' && this.SecretKey.length !== 6) {
return this.$message.error(this.$tc('common.MFAErrorMsg'))
}
this.$axios.post(
`/api/v1/authentication/confirm/`, {
confirm_type: this.ConfirmType,
secret_key: this.SecretKey
}
).then(res => {
this.$emit('UserConfirmDone', true)
})
}
}
}
</script>
<style scoped>
</style>

View File

@ -25,6 +25,6 @@ export { default as UploadField } from './FormFields/UploadField'
export { default as AccountListTable } from './AccountListTable/index' export { default as AccountListTable } from './AccountListTable/index'
export { default as AppAccountListTable } from './AppAccountListTable' export { default as AppAccountListTable } from './AppAccountListTable'
export { default as AssetRelationCard } from './AssetRelationCard' export { default as AssetRelationCard } from './AssetRelationCard'
export { default as MFAVerifyDialog } from './MFAVerifyDialog' export { default as UserConfirmDialog } from './UserConfirmDialog'
export { default as Announcement } from './Announcement' export { default as Announcement } from './Announcement'
export { default as CronTab } from './CronTab' export { default as CronTab } from './CronTab'

View File

@ -268,6 +268,7 @@
"Database": "Database", "Database": "Database",
"Params": "Params", "Params": "Params",
"MFAVerify": "Verify MFA", "MFAVerify": "Verify MFA",
"CurrentUserVerify": "Verify Current User",
"ViewSecret": "View secret", "ViewSecret": "View secret",
"ConnectWebSocketError": "Connect Websocket failed", "ConnectWebSocketError": "Connect Websocket failed",
"Nothing": "Nothing", "Nothing": "Nothing",

View File

@ -276,6 +276,7 @@
"DateUpdated": "更新日", "DateUpdated": "更新日",
"ApprovaLevel": "承認情報", "ApprovaLevel": "承認情報",
"MFAVerify": "MFAの検証", "MFAVerify": "MFAの検証",
"CurrentUserVerify": "現在のユーザー検証",
"ViewSecret": "パスワードの確認", "ViewSecret": "パスワードの確認",
"ConnectWebSocketError": "Webソケット接続に失敗しました", "ConnectWebSocketError": "Webソケット接続に失敗しました",
"Action": "アクション", "Action": "アクション",

View File

@ -277,6 +277,7 @@
"DateUpdated": "更新日期", "DateUpdated": "更新日期",
"ApprovaLevel": "审批信息", "ApprovaLevel": "审批信息",
"MFAVerify": "验证 MFA", "MFAVerify": "验证 MFA",
"CurrentUserVerify": "验证当前用户",
"ViewSecret": "查看密码", "ViewSecret": "查看密码",
"ConnectWebSocketError": "连接 WebSocket 失败", "ConnectWebSocketError": "连接 WebSocket 失败",
"Action": "动作", "Action": "动作",

View File

@ -1,5 +1,11 @@
<template> <template>
<Page v-bind="$attrs"> <Page v-bind="$attrs">
<UserConfirmDialog
v-if="showPasswordDialog"
:visible.sync="showPasswordDialog"
@UserConfirmDone="verifyDone"
@UserConfirmCancel="exit"
/>
<div> <div>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :md="14" :sm="24"> <el-col :md="14" :sm="24">
@ -20,28 +26,6 @@
/> />
</el-col> </el-col>
</el-row> </el-row>
<Dialog
width="50"
top="20vh"
:title="this.$t('common.PasswordConfirm')"
:visible.sync="showPasswordDialog"
:show-confirm="false"
:show-cancel="false"
:destroy-on-close="true"
>
<el-row :gutter="20">
<el-col :md="4" :sm="24">
<div style="line-height: 34px">{{ $t('assets.Password') }}</div>
</el-col>
<el-col :md="14" :sm="24">
<el-input v-model="passwordInput" type="password" />
<span class="help-tips help-block">{{ $t('common.PasswordRequireForSecurity') }}</span>
</el-col>
<el-col :md="4" :sm="24">
<el-button size="mini" type="primary" style="line-height:20px " @click="passConfirm">{{ this.$t('common.Confirm') }}</el-button>
</el-col>
</el-row>
</Dialog>
</div> </div>
</Page> </Page>
</template> </template>
@ -50,7 +34,7 @@
import Page from '@/layout/components/Page' import Page from '@/layout/components/Page'
import DetailCard from '@/components/DetailCard' import DetailCard from '@/components/DetailCard'
import QuickActions from '@/components/QuickActions' import QuickActions from '@/components/QuickActions'
import Dialog from '@/components/Dialog' import UserConfirmDialog from '@/components/UserConfirmDialog'
import { toSafeLocalDateStr } from '@/utils/common' import { toSafeLocalDateStr } from '@/utils/common'
import store from '@/store' import store from '@/store'
@ -60,7 +44,7 @@ export default {
Page, Page,
DetailCard, DetailCard,
QuickActions, QuickActions,
Dialog UserConfirmDialog
}, },
props: { props: {
object: { object: {
@ -72,7 +56,6 @@ export default {
return { return {
url: `/api/v1/users/profile/`, url: `/api/v1/users/profile/`,
showPasswordDialog: false, showPasswordDialog: false,
passwordInput: '',
currentEdit: '', currentEdit: '',
authQuickActions: [ authQuickActions: [
{ {
@ -325,12 +308,7 @@ export default {
} }
return backendList return backendList
}, },
passConfirm() { verifyDone() {
this.$axios.post(
`/api/v1/authentication/password/verify/`, {
password: this.passwordInput
}
).then(res => {
if (!this.object[`is_${this.currentEdit}_bound`]) { if (!this.object[`is_${this.currentEdit}_bound`]) {
window.location.href = `/core/auth/${this.currentEdit}/qr/bind/?redirect_url=${this.$route.fullPath}` window.location.href = `/core/auth/${this.currentEdit}/qr/bind/?redirect_url=${this.$route.fullPath}`
} else { } else {
@ -339,9 +317,10 @@ export default {
this.$store.dispatch('users/getProfile') this.$store.dispatch('users/getProfile')
}) })
} }
})
this.passwordInput = ''
this.showPasswordDialog = false this.showPasswordDialog = false
},
exit() {
this.$emit('update:visible', false)
} }
} }
} }