fix: ukey 登录联调修改

develop
时启龙 2024-08-26 16:42:26 +08:00
parent 42951cc395
commit cbfa87d1b1
3 changed files with 53 additions and 63 deletions

View File

@ -1,15 +1,7 @@
import request from 'utils/request' import request from 'utils/request'
export function getLoginRandom(ngxCookie) { export function getLoginRandom(ngxCookie) {
return request.get( return request.get('/sms/v1/trx/randomstr', { params: { ngxCookie } })
'/sms/v1/trx/getRandomStr',
{},
{
headers: {
ngxCookie
}
}
)
} }
export function trxLogin(params) { export function trxLogin(params) {

View File

@ -10,58 +10,57 @@ const actions = {
Login({ commit }, password) { Login({ commit }, password) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// 调用 ukey 获取 clientHello // 调用 ukey 获取 clientHello
getClientHello(password).then( getClientHello(password).then(checkRes => {
checkRes => { if (checkRes.result !== 0) {
if (checkRes.result !== 0) { Cookies.remove('ngx_cookie')
Cookies.remove('ngx_cookie') ElMessage({ message: checkRes.message, type: 'error' })
ElMessage({ message: checkRes.message, type: 'error' }) resolve({
return Promise.reject(new Error(checkRes.message)) success: false
} })
const clientHello = checkRes.clientHello
Cookies.set('ngx_cookie', clientHello)
// 调用天融信单点登录获取 serverHello
getLoginRandom(clientHello).then(
randomRes => {
if (!randomRes.success) {
ElMessage({ message: randomRes.message, type: 'error' })
return Promise.reject(new Error(randomRes.message))
}
let serverHello = randomRes.data
// 调用 ukey 获取 ClientAuth
getClientAuth(password, serverHello, clientHello).then(
authRes => {
// 暂未用到
const ClientAuth = authRes.clientAuth
trxLogin({
clientHello,
serverHello
}).then(
tokenRes => {
if (!tokenRes.success) {
ElMessage({ message: tokenRes.message, type: 'error' })
return Promise.reject(new Error(tokenRes.message))
}
resolve(tokenRes)
},
err => {
reject(err)
}
)
},
err => {
reject(err)
}
)
},
err => {
reject(err)
}
)
},
err => {
reject(err)
} }
) const clientHello = checkRes.clientHello
Cookies.set('ngx_cookie', clientHello)
// 调用天融信单点登录获取 serverHello
getLoginRandom(clientHello)
.then(randomRes => {
if (!randomRes.success) {
resolve({
success: false
})
}
let serverHello = randomRes.data
// 调用 ukey 获取 ClientAuth
getClientAuth(password, serverHello, clientHello)
.then(authRes => {
// 暂未用到
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const ClientAuth = authRes.clientAuth
if (authRes.result !== 0) {
ElMessage({ message: authRes.message, type: 'error' })
resolve({
success: false
})
}
trxLogin({
clientHello,
serverHello
}).then(tokenRes => {
if (!tokenRes.success) {
resolve({
success: false
})
}
resolve(tokenRes)
})
})
.catch(err => {
reject(err)
})
})
.catch(err => {
reject(err)
})
})
}) })
}, },
// 退出系统 // 退出系统

View File

@ -142,13 +142,12 @@ async function handleUkeyLogin() {
loginFormRef.value.validate(async valid => { loginFormRef.value.validate(async valid => {
if (valid) { if (valid) {
loading.value = true loading.value = true
const res = await store.dispatch('ukey/Login', loginForm.ukeyPassword).catch(res => console.log(res)) const res = await store.dispatch('ukey/Login', loginForm.ukeyPassword).finally(() => (loading.value = false))
if (res.success) { if (res && res.success) {
// ukey // ukey
setUkeyPassword(loginForm.ukeyPassword) setUkeyPassword(loginForm.ukeyPassword)
goLogin(res.data) goLogin(res.data)
} }
loading.value = false
} }
}) })
} }