feat(X-Pack): 移动端登录增加 MFA 机制

This commit is contained in:
fit2cloud-chenyw 2024-12-20 10:47:52 +08:00 committed by xuwei-fit2cloud
parent 22f00fc849
commit ff88701431

View File

@ -35,6 +35,9 @@ const duringLogin = ref(false)
const xpackLoadFail = ref(false) const xpackLoadFail = ref(false)
const xpackInvalidPwd = ref() const xpackInvalidPwd = ref()
const mfaRef = ref()
const showMfa = ref(false)
const mfaData = ref({ enabled: false, ready: false, uid: '', origin: 0 })
const checkUsername = value => { const checkUsername = value => {
if (!value) { if (!value) {
@ -86,6 +89,12 @@ const invalidPwdCb = val => {
router.push({ path: '/index' }) router.push({ path: '/index' })
} }
} }
const closeMfa = () => {
showMfa.value = false
}
const mfaSuccess = () => {
router.push({ path: '/index' })
}
const onSubmit = async () => { const onSubmit = async () => {
if (!checkUsername(username.value) || !validatePwd(password.value)) { if (!checkUsername(username.value) || !validatePwd(password.value)) {
showToast({ showToast({
@ -104,7 +113,16 @@ const onSubmit = async () => {
duringLogin.value = true duringLogin.value = true
loginApi(param) loginApi(param)
.then(res => { .then(res => {
const { token, exp } = res.data const { token, exp, mfa } = res.data
showMfa.value = false
if (mfa?.enabled) {
for (const key in mfa) {
mfaData.value[key] = mfa[key]
}
showMfa.value = true
duringLogin.value = false
return
}
userStore.setToken(token) userStore.setToken(token)
userStore.setExp(exp) userStore.setExp(exp)
userStore.setTime(Date.now()) userStore.setTime(Date.now())
@ -194,6 +212,14 @@ const usernameEndValidate = ({ status, message }) => {
@load-fail="() => (xpackLoadFail = true)" @load-fail="() => (xpackLoadFail = true)"
@call-back="invalidPwdCb" @call-back="invalidPwdCb"
/> />
<XpackComponent
ref="mfaRef"
v-if="showMfa"
:mfa-data="mfaData"
jsname="L2NvbXBvbmVudC9sb2dpbi9NZmFTdGVw"
@close="closeMfa"
@success="mfaSuccess"
/>
</template> </template>
<style lang="less"> <style lang="less">