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' })
return Promise.reject(new Error(checkRes.message)) resolve({
success: false
})
} }
const clientHello = checkRes.clientHello const clientHello = checkRes.clientHello
Cookies.set('ngx_cookie', clientHello) Cookies.set('ngx_cookie', clientHello)
// 调用天融信单点登录获取 serverHello // 调用天融信单点登录获取 serverHello
getLoginRandom(clientHello).then( getLoginRandom(clientHello)
randomRes => { .then(randomRes => {
if (!randomRes.success) { if (!randomRes.success) {
ElMessage({ message: randomRes.message, type: 'error' }) resolve({
return Promise.reject(new Error(randomRes.message)) success: false
})
} }
let serverHello = randomRes.data let serverHello = randomRes.data
// 调用 ukey 获取 ClientAuth // 调用 ukey 获取 ClientAuth
getClientAuth(password, serverHello, clientHello).then( getClientAuth(password, serverHello, clientHello)
authRes => { .then(authRes => {
// 暂未用到 // 暂未用到
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const ClientAuth = authRes.clientAuth const ClientAuth = authRes.clientAuth
if (authRes.result !== 0) {
ElMessage({ message: authRes.message, type: 'error' })
resolve({
success: false
})
}
trxLogin({ trxLogin({
clientHello, clientHello,
serverHello serverHello
}).then( }).then(tokenRes => {
tokenRes => {
if (!tokenRes.success) { if (!tokenRes.success) {
ElMessage({ message: tokenRes.message, type: 'error' }) resolve({
return Promise.reject(new Error(tokenRes.message)) success: false
})
} }
resolve(tokenRes) resolve(tokenRes)
}, })
err => { })
.catch(err => {
reject(err) reject(err)
} })
) })
}, .catch(err => {
err => {
reject(err) reject(err)
} })
) })
},
err => {
reject(err)
}
)
},
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
} }
}) })
} }