fix: mfa login. (#276)

pull/277/head
Ryan Wang 2020-12-26 20:53:38 +08:00 committed by GitHub
parent 8f70ffa5ab
commit 418f0e13ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 28 deletions

View File

@ -68,7 +68,7 @@
:loading="form.logging" :loading="form.logging"
type="primary" type="primary"
:block="true" :block="true"
@click="handleLoginClick" @click="form.needAuthCode ? handleLogin() : handleLoginClick()"
>{{ buttonName }}</a-button> >{{ buttonName }}</a-button>
</a-form-model-item> </a-form-model-item>
</a-form-model> </a-form-model>
@ -92,22 +92,22 @@ export default {
model: { model: {
authcode: null, authcode: null,
password: null, password: null,
username: null username: null,
}, },
rules: { rules: {
username: [{ required: true, message: '* 用户名/邮箱不能为空', trigger: ['change'] }], username: [{ required: true, message: '* 用户名/邮箱不能为空', trigger: ['change'] }],
password: [{ required: true, message: '* 密码不能为空', trigger: ['change'] }], password: [{ required: true, message: '* 密码不能为空', trigger: ['change'] }],
authcode: [{ validator: authcodeValidate, trigger: ['change'] }] authcode: [{ validator: authcodeValidate, trigger: ['change'] }],
}, },
needAuthCode: false, needAuthCode: false,
logging: false logging: false,
} },
} }
}, },
computed: { computed: {
buttonName() { buttonName() {
return this.form.needAuthCode ? '验证' : '登录' return this.form.needAuthCode ? '验证' : '登录'
} },
}, },
methods: { methods: {
...mapActions(['login', 'refreshUserCache', 'refreshOptionsCache']), ...mapActions(['login', 'refreshUserCache', 'refreshOptionsCache']),
@ -116,26 +116,22 @@ export default {
_this.$refs.loginForm.validate((valid) => { _this.$refs.loginForm.validate((valid) => {
if (valid) { if (valid) {
_this.form.logging = true _this.form.logging = true
if (_this.form.needAuthCode && _this.form.model.authcode) { adminApi
_this.handleLogin() .loginPreCheck(_this.form.model.username, _this.form.model.password)
} else { .then((response) => {
adminApi const data = response.data.data
.loginPreCheck(_this.form.model.username, _this.form.model.password) if (data && data.needMFACode) {
.then((response) => { _this.form.needAuthCode = true
const data = response.data.data _this.form.model.authcode = null
if (data && data.needMFACode) { } else {
_this.form.needAuthCode = true _this.handleLogin()
_this.form.model.authcode = null }
} else { })
_this.handleLogin() .finally(() => {
} setTimeout(() => {
}) _this.form.logging = false
.finally(() => { }, 300)
setTimeout(() => { })
_this.form.logging = false
}, 300)
})
}
} }
}) })
}, },
@ -156,7 +152,7 @@ export default {
}) })
} }
}) })
} },
} },
} }
</script> </script>