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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,11 @@
<template>
<Page v-bind="$attrs">
<UserConfirmDialog
v-if="showPasswordDialog"
:visible.sync="showPasswordDialog"
@UserConfirmDone="verifyDone"
@UserConfirmCancel="exit"
/>
<div>
<el-row :gutter="20">
<el-col :md="14" :sm="24">
@ -20,28 +26,6 @@
/>
</el-col>
</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>
</Page>
</template>
@ -50,7 +34,7 @@
import Page from '@/layout/components/Page'
import DetailCard from '@/components/DetailCard'
import QuickActions from '@/components/QuickActions'
import Dialog from '@/components/Dialog'
import UserConfirmDialog from '@/components/UserConfirmDialog'
import { toSafeLocalDateStr } from '@/utils/common'
import store from '@/store'
@ -60,7 +44,7 @@ export default {
Page,
DetailCard,
QuickActions,
Dialog
UserConfirmDialog
},
props: {
object: {
@ -72,7 +56,6 @@ export default {
return {
url: `/api/v1/users/profile/`,
showPasswordDialog: false,
passwordInput: '',
currentEdit: '',
authQuickActions: [
{
@ -325,23 +308,19 @@ export default {
}
return backendList
},
passConfirm() {
this.$axios.post(
`/api/v1/authentication/password/verify/`, {
password: this.passwordInput
}
).then(res => {
if (!this.object[`is_${this.currentEdit}_bound`]) {
window.location.href = `/core/auth/${this.currentEdit}/qr/bind/?redirect_url=${this.$route.fullPath}`
} else {
this.$axios.post(`/api/v1/authentication/${this.currentEdit}/qr/unbind/`).then(res => {
this.$message.success(this.$t('common.updateSuccessMsg'))
this.$store.dispatch('users/getProfile')
})
}
})
this.passwordInput = ''
verifyDone() {
if (!this.object[`is_${this.currentEdit}_bound`]) {
window.location.href = `/core/auth/${this.currentEdit}/qr/bind/?redirect_url=${this.$route.fullPath}`
} else {
this.$axios.post(`/api/v1/authentication/${this.currentEdit}/qr/unbind/`).then(res => {
this.$message.success(this.$t('common.updateSuccessMsg'))
this.$store.dispatch('users/getProfile')
})
}
this.showPasswordDialog = false
},
exit() {
this.$emit('update:visible', false)
}
}
}