NEZ-908 feat:用户编辑页面增加 2FA 配置选项

This commit is contained in:
zhangyu
2021-08-12 15:52:48 +08:00
parent 0e7cbe35b8
commit 0af7534bc7
7 changed files with 68 additions and 17 deletions

View File

@@ -721,7 +721,11 @@ const cn = {
confirmPinErr: '两次密码输入不一致', confirmPinErr: '两次密码输入不一致',
reinputPin: '请再次输入密码', reinputPin: '请再次输入密码',
notification: '通知', notification: '通知',
mobile: '电话' mobile: '电话',
disable: '关闭',
enableMfa: '开启',
forceEnable: '强制开启',
mfaTitle: 'Two-Factor Authentication'
}, },
roles: { roles: {
roles: '角色', roles: '角色',

View File

@@ -730,7 +730,11 @@ const en = {
confirmPinErr: 'The two passwords are inconsistent', confirmPinErr: 'The two passwords are inconsistent',
reinputPin: 'Enter password again', reinputPin: 'Enter password again',
notification: 'Notification', notification: 'Notification',
mobile: 'Mobile' mobile: 'Mobile',
disable: 'Disable',
enableMfa: 'EnableMfa',
forceEnable: 'ForceEnable',
mfaTitle: 'Two-Factor Authentication'
}, },
roles: { roles: {
roles: 'Role', roles: 'Role',

View File

@@ -164,10 +164,10 @@ export default {
this.$post('sys/login', this.loginData).then(res => { this.$post('sys/login', this.loginData).then(res => {
if (res.code == 200) { if (res.code == 200) {
// 登录成功记录用户名、token和lang // 登录成功记录用户名、token和lang
// res.data.authFlag = 1 // res.data.authFlag = 0
// res.data.authBind = 1 // res.data.authBind = 1
this.authToken = res.data.token this.authToken = res.data.token
sessionStorage.setItem('nz-token', this.authToken) sessionStorage.setItem('nz-token', res.data.token)
if (res.data.authFlag === 1) { if (res.data.authFlag === 1) {
if (res.data.authBind === 0) { if (res.data.authBind === 0) {
this.verifyShow = true this.verifyShow = true
@@ -176,8 +176,8 @@ export default {
this.dialogLoading = true this.dialogLoading = true
this.$post('mfa/genKey', { authToken: this.authToken }).then(res => { this.$post('mfa/genKey', { authToken: this.authToken }).then(res => {
this.$nextTick(() => { this.$nextTick(() => {
this.authToken = res.data.token this.authToken = res.data.authToken
sessionStorage.setItem('nz-token', this.authToken) // sessionStorage.setItem('nz-token', this.authToken)
this.authKey = res.data.authKey this.authKey = res.data.authKey
this.bindQRCode(res.data.otpauth) this.bindQRCode(res.data.otpauth)
}) })
@@ -208,12 +208,17 @@ export default {
authCode: this.loginData.authCode authCode: this.loginData.authCode
} }
this.$post('mfa/verify', params).then(res => { this.$post('mfa/verify', params).then(res => {
if (res.code === 200) {
res.data.token = res.data.authToken
sessionStorage.setItem('nz-username', this.loginData.username) sessionStorage.setItem('nz-username', this.loginData.username)
localStorage.setItem('nz-username', this.loginData.username) localStorage.setItem('nz-username', this.loginData.username)
localStorage.setItem('nz-prometheus-federation-enabled', res.data.prometheusFederationEnabled) localStorage.setItem('nz-prometheus-federation-enabled', res.data.prometheusFederationEnabled)
localStorage.setItem('nz-language', this.lang) localStorage.setItem('nz-language', this.lang)
this.$i18n.locale = this.lang this.$i18n.locale = this.lang
this.loginSuccess(res) this.loginSuccess(res)
} else {
this.authToken = res.data.authToken
}
}) })
}, },
changeLang (lang) { changeLang (lang) {

View File

@@ -29,6 +29,21 @@
<el-input id="account-input-pinChange" v-model="editUser.pinChange" maxlength="64" placeholder="" <el-input id="account-input-pinChange" v-model="editUser.pinChange" maxlength="64" placeholder=""
show-word-limit size="small" type="password"></el-input> show-word-limit size="small" type="password"></el-input>
</el-form-item> </el-form-item>
<!--mfaLevel-->
<el-form-item :label="$t('config.user.mfaTitle')" label-width="200px" prop="mfaTitle">
<el-select id="account-input-mfaLevel"
v-model="editUser.mfaLevel"
class="right-box__select"
clearable
collapse-tags
placeholder=""
popper-class="right-box-select-dropdown prevent-clickoutside"
size="small">
<template v-for="item in mfaLevelList">
<el-option :key="item.value" :label="item.label" :value="item.value"></el-option>
</template>
</el-select>
</el-form-item>
<!--email--> <!--email-->
<el-form-item label="E-mail" prop="email"> <el-form-item label="E-mail" prop="email">
<el-input id="account-input-email" v-model="editUser.email" maxlength="64" show-word-limit placeholder="" size="small" type="text"></el-input> <el-input id="account-input-email" v-model="editUser.email" maxlength="64" show-word-limit placeholder="" size="small" type="text"></el-input>
@@ -151,7 +166,12 @@ export default {
{ type: 'email', message: this.$t('validate.email') } { type: 'email', message: this.$t('validate.email') }
] ]
}, },
roles: [] roles: [],
mfaLevelList: [
{ value: 0, label: this.$t('config.user.disable') },
{ value: 1, label: this.$t('config.user.enableMfa') },
{ value: 2, label: this.$t('config.user.forceEnable') }
]
} }
}, },
watch: { watch: {

View File

@@ -34,7 +34,13 @@
<div class="col-resize-area"></div> <div class="col-resize-area"></div>
</template> </template>
<template slot-scope="scope" :column="item"> <template slot-scope="scope" :column="item">
<template v-if="item.prop === 'roles'"> <template v-if="item.prop === 'name'">
<div class="flex-align-center">
<span>{{scope.row[item.prop]}}</span>
<el-tag size="mini" v-if="mfaEnable || scope.row.mfaLevel > 0" style="margin-left: 5px">Mfa</el-tag>
</div>
</template>
<template v-else-if="item.prop === 'roles'">
<template v-if="scope.row[item.prop]"> <template v-if="scope.row[item.prop]">
{{scope.row[item.prop].map(t=>t.name).join(',')}} {{scope.row[item.prop].map(t=>t.name).join(',')}}
</template> </template>
@@ -135,7 +141,8 @@ export default {
show: true, show: true,
width: 100 width: 100
} }
] ],
mfaEnable: localStorage.getItem('nz-mfa-enable')
} }
}, },
methods: { methods: {
@@ -162,3 +169,9 @@ export default {
} }
} }
</script> </script>
<style scoped>
.flex-align-center{
display: flex;
align-items: center;
}
</style>

View File

@@ -72,7 +72,8 @@ export default {
roleIds: '', roleIds: '',
roles: [], roles: [],
lang: '', lang: '',
notifications: [] notifications: [],
mfaLevel: 0
}, },
tableId: 'userTable', tableId: 'userTable',
searchMsg: { // 给搜索框子组件传递的信息 searchMsg: { // 给搜索框子组件传递的信息
@@ -114,6 +115,9 @@ export default {
pin: '', pin: '',
pinChange: '' pinChange: ''
} }
if (!this.object.mfaLevel) {
this.object.mfaLevel = 0
}
this.rightBox.show = true this.rightBox.show = true
} }
}) })

View File

@@ -50,6 +50,7 @@ const user = {
localStorage.setItem('nz-sys-max-terminal-num', res.data.maxTerminalNum) localStorage.setItem('nz-sys-max-terminal-num', res.data.maxTerminalNum)
localStorage.setItem('nz-sys-asset-ping-switch', res.data.assetPingSwitch) localStorage.setItem('nz-sys-asset-ping-switch', res.data.assetPingSwitch)
localStorage.setItem('nz-unnsaved-change', res.data.unsavedChange) localStorage.setItem('nz-unnsaved-change', res.data.unsavedChange)
localStorage.setItem('nz-mfa-enable', res.data.mfaAuthEnable)
post('/sys/user/permissions', { token: res.data.token }).then(res => { post('/sys/user/permissions', { token: res.data.token }).then(res => {
const menuList = sortByOrderNum(res.data.menus) const menuList = sortByOrderNum(res.data.menus)
store.commit('setMenuList', menuList) store.commit('setMenuList', menuList)