提交 56540934 authored 作者: vipcxj's avatar vipcxj

修正关于uca登录的bug

上级 aa0a8707
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Input, Spin } from 'antd'; import { Input, Spin } from 'antd';
import { debounce } from 'lodash';
import { getCert, init, sign } from '../../utils/uca'; import { getCert, init, sign } from '../../utils/uca';
class UCA extends Component { class UCA extends Component {
...@@ -34,23 +33,30 @@ class UCA extends Component { ...@@ -34,23 +33,30 @@ class UCA extends Component {
onChange = (value) => { onChange = (value) => {
if (this.state.ready && this.props.onChange) { if (this.state.ready && this.props.onChange) {
if (value) { this.props.onChange(this.valueToObj(value));
if (this.props.data) { }
this.props.onChange(sign(value, this.props.data)); };
} else { objToValue = (obj) => {
this.props.onChange(getCert(value)); return obj ? obj.input : '';
} };
} valueToObj = (value) => {
if (!value) {
return value;
}
if (this.props.data) {
return sign(value, this.props.data);
} else {
return getCert(value);
} }
}; };
render() { render() {
const onChange = (e) => { const onChange = (e) => {
return debounce(this.onChange, 300)(e.target.value); return this.onChange(e.target.value);
}; };
const { loading, ...rest } = this.props; const { loading, value, ...rest } = this.props;
return ( return (
<Spin spinning={!this.state.ready && loading} size="small"> <Spin spinning={!this.state.ready || loading} size="small">
<Input {...rest} onChange={onChange} type="password" /> <Input {...rest} disabled={!this.state.ready || loading} value={this.objToValue(value)} onChange={onChange} />
</Spin> </Spin>
); );
} }
......
...@@ -111,8 +111,8 @@ export default { ...@@ -111,8 +111,8 @@ export default {
yield put({ type: 'setStatus', payload: 'auth' }); yield put({ type: 'setStatus', payload: 'auth' });
}, },
*requestUCACode(ignored, { call, put }) { *requestUCACode(ignored, { call, put }) {
const code = yield call(authorize, yield call(requestCode, encrypt(tkId))); const { data } = yield call(authorize, yield call(requestCode, encrypt(tkId)));
yield put({ type: 'setUCACode', payload: code }); yield put({ type: 'setUCACode', payload: data });
}, },
*auth({ payload: { password, uca } }, { call }) { *auth({ payload: { password, uca } }, { call }) {
let response; let response;
...@@ -122,9 +122,9 @@ export default { ...@@ -122,9 +122,9 @@ export default {
response = yield call(authorize, yield call(ucaValidate, uca, encrypt(tkId))); response = yield call(authorize, yield call(ucaValidate, uca, encrypt(tkId)));
} }
if (response) { if (response) {
const { status, remainedAuthRequirements } = response; const { status, remainedAuthRequirements, data } = response;
if (status !== 'authed' && status !== 'skipped') { if (status !== 'authed' && status !== 'skipped') {
throw errors.authFailed(); throw errors.authFailed(data);
} }
if (remainedAuthRequirements.requirements.length === 0) { if (remainedAuthRequirements.requirements.length === 0) {
yield call(successAuthed, tkId); yield call(successAuthed, tkId);
......
...@@ -2,5 +2,5 @@ import post from '../utils/post'; ...@@ -2,5 +2,5 @@ import post from '../utils/post';
import config from '../utils/config'; import config from '../utils/config';
export const bindCert = async (uid, cert) => { export const bindCert = async (uid, cert) => {
return post(`${config.apiContextPath}/api/uca/admin/cert`, { uid, cert: encodeURIComponent(cert) }); return post(`${config.apiContextPath}/api/uca/admin/cert`, { uid, cert });
}; };
...@@ -84,9 +84,9 @@ export const errors = { ...@@ -84,9 +84,9 @@ export const errors = {
code: errorCodes.wrong_password, code: errorCodes.wrong_password,
msg: '密码错误!', msg: '密码错误!',
}), }),
authFailed: () => createError({ authFailed: msg => createError({
code: errorCodes.auth_failed, code: errorCodes.auth_failed,
msg: '登录验证失败!', msg: `登录验证失败!${msg}`,
}), }),
unsupportedAuthType: (...types) => createError({ unsupportedAuthType: (...types) => createError({
code: errorCodes.unsupported_auth_type, code: errorCodes.unsupported_auth_type,
......
...@@ -37,6 +37,7 @@ export const getCert = (password) => { ...@@ -37,6 +37,7 @@ export const getCert = (password) => {
if (!safeEngine) { if (!safeEngine) {
return { return {
status: 1, status: 1,
input: password,
error: '未安装USB证书控件。', error: '未安装USB证书控件。',
}; };
} }
...@@ -44,6 +45,7 @@ export const getCert = (password) => { ...@@ -44,6 +45,7 @@ export const getCert = (password) => {
if (safeEngine.ErrorCode !== 0) { if (safeEngine.ErrorCode !== 0) {
return { return {
status: safeEngine.ErrorCode, status: safeEngine.ErrorCode,
input: password,
error: 'USB-KEY初始化失败,请确认USB-KEY是否插入或密码是否正确。', error: 'USB-KEY初始化失败,请确认USB-KEY是否插入或密码是否正确。',
}; };
} }
...@@ -52,12 +54,14 @@ export const getCert = (password) => { ...@@ -52,12 +54,14 @@ export const getCert = (password) => {
if (safeEngine.ErrorCode !== 0) { if (safeEngine.ErrorCode !== 0) {
return { return {
status: safeEngine.ErrorCode, status: safeEngine.ErrorCode,
input: password,
error: `获取个人证书错误,错误代码为:${safeEngine.ErrorCode}。`, error: `获取个人证书错误,错误代码为:${safeEngine.ErrorCode}。`,
}; };
} }
const res = { const res = {
status: 0, status: 0,
cert, cert,
input: password,
}; };
const deadTime = safeEngine.SEH_GetCertValidDate(cert); const deadTime = safeEngine.SEH_GetCertValidDate(cert);
res.deadTime = parseInt(deadTime, 10); res.deadTime = parseInt(deadTime, 10);
...@@ -77,7 +81,7 @@ export const getCert = (password) => { ...@@ -77,7 +81,7 @@ export const getCert = (password) => {
* 签名 * 签名
* @param password usb-key的密钥 * @param password usb-key的密钥
* @param data 需要签名的数据,从服务端获取 * @param data 需要签名的数据,从服务端获取
* @return {{[cert]: string, [deadTime]: number, [signed]: string, status: number, [error]: string}} * @return {{input: string, [cert]: string, [deadTime]: number, [signed]: string, status: number, [error]: string}}
*/ */
export const sign = (password, data) => { export const sign = (password, data) => {
if (bowser.msie || bowser.msedge) { if (bowser.msie || bowser.msedge) {
...@@ -85,6 +89,7 @@ export const sign = (password, data) => { ...@@ -85,6 +89,7 @@ export const sign = (password, data) => {
if (!safeEngine) { if (!safeEngine) {
return { return {
status: 1, status: 1,
input: password,
error: '未安装USB证书控件。', error: '未安装USB证书控件。',
}; };
} }
...@@ -92,6 +97,7 @@ export const sign = (password, data) => { ...@@ -92,6 +97,7 @@ export const sign = (password, data) => {
if (safeEngine.ErrorCode !== 0) { if (safeEngine.ErrorCode !== 0) {
return { return {
status: safeEngine.ErrorCode, status: safeEngine.ErrorCode,
input: password,
error: 'USB-KEY初始化失败,请确认USB-KEY是否插入或密码是否正确。', error: 'USB-KEY初始化失败,请确认USB-KEY是否插入或密码是否正确。',
}; };
} }
...@@ -100,16 +106,18 @@ export const sign = (password, data) => { ...@@ -100,16 +106,18 @@ export const sign = (password, data) => {
if (safeEngine.ErrorCode !== 0) { if (safeEngine.ErrorCode !== 0) {
return { return {
status: safeEngine.ErrorCode, status: safeEngine.ErrorCode,
input: password,
error: `获取个人证书错误,错误代码为:${safeEngine.ErrorCode}。`, error: `获取个人证书错误,错误代码为:${safeEngine.ErrorCode}。`,
}; };
} }
const res = { cert, status: 0 }; const res = { cert, status: 0, input: password };
const deadTime = safeEngine.SEH_GetCertValidDate(cert); const deadTime = safeEngine.SEH_GetCertValidDate(cert);
res.deadTime = parseInt(deadTime, 10); res.deadTime = parseInt(deadTime, 10);
const signed = safeEngine.SEH_SignData(data, 3); const signed = safeEngine.SEH_SignData(data, 3);
if (safeEngine.ErrorCode !== 0) { if (safeEngine.ErrorCode !== 0) {
return { return {
status: safeEngine.ErrorCode, status: safeEngine.ErrorCode,
input: password,
error: `数字签名失败,错误代码为:${safeEngine.ErrorCode}。`, error: `数字签名失败,错误代码为:${safeEngine.ErrorCode}。`,
}; };
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论