{{ $t('commons.login.mfaTitle') }}
@@ -89,7 +89,15 @@
-
+
{{ $t('commons.button.verify') }}
@@ -233,6 +241,8 @@ const loginRules = reactive({
name: [{ required: true, message: i18n.global.t('commons.rule.username'), trigger: 'blur' }],
password: [{ required: true, message: i18n.global.t('commons.rule.password'), trigger: 'blur' }],
});
+
+const mfaButtonFocused = ref();
const mfaLoginForm = reactive({
name: '',
password: '',
@@ -266,41 +276,39 @@ const login = (formEl: FormInstance | undefined) => {
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) return;
- loading.value = true;
+ let requestLoginForm = {
+ name: loginForm.name,
+ password: loginForm.password,
+ captcha: loginForm.captcha,
+ captchaID: captcha.captchaID,
+ authMethod: '',
+ };
+ if (requestLoginForm.captcha == '') {
+ errCaptcha.value = true;
+ return;
+ }
+ if (loginForm.agreeLicense == false) {
+ errAgree.value = true;
+ return;
+ }
try {
- let requestLoginForm = {
- name: loginForm.name,
- password: loginForm.password,
- captcha: loginForm.captcha,
- captchaID: captcha.captchaID,
- authMethod: '',
- };
- if (requestLoginForm.captcha == '') {
- errCaptcha.value = true;
- return;
- }
- if (loginForm.agreeLicense == false) {
- errAgree.value = true;
- return;
- }
+ loading.value = true;
const res = await loginApi(requestLoginForm);
if (res.code === 406) {
if (res.message === 'ErrCaptchaCode') {
errCaptcha.value = true;
errAuthInfo.value = false;
- loginVerify();
}
if (res.message === 'ErrAuth') {
errCaptcha.value = false;
errAuthInfo.value = true;
- loginVerify();
}
+ loginVerify();
return;
}
if (res.data.mfaStatus === 'enable') {
mfaShow.value = true;
errMfaInfo.value = false;
- mfaLoginForm.secret = res.data.mfaSecret;
return;
}
globalStore.setLogStatus(true);
@@ -366,12 +374,16 @@ onMounted(() => {
document.onkeydown = (e: any) => {
e = window.event || e;
if (e.keyCode === 13) {
- if (loading.value) return;
- if (isFirst.value && !registerButtonFocused.value) {
- register(registerFormRef.value);
+ if (!mfaShow.value) {
+ if (isFirst.value && !registerButtonFocused.value) {
+ register(registerFormRef.value);
+ }
+ if (!isFirst.value && !loginButtonFocused.value) {
+ login(loginFormRef.value);
+ }
}
- if (!isFirst.value && !loginButtonFocused.value) {
- login(loginFormRef.value);
+ if (mfaShow.value && !mfaButtonFocused.value) {
+ mfaLogin();
}
}
};