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

1.修复可选多种验证方式的输入控件各种错误

2.实现记住用户名功能
上级 368b5931
......@@ -9,7 +9,8 @@ import { errors } from '../utils/error';
import config from '../utils/config';
import { getStore } from '../index';
const successAuthed = async (tokenId) => {
const successAuthed = async (tokenId, userName, remember) => {
await histories.pushHistory('userName', remember ? userName : '');
await setToken(tokenId);
const uInfo = await userInfo();
await setUser(uInfo.id, uInfo.name);
......@@ -86,13 +87,14 @@ export default {
},
},
effects: {
*init(ignored, { put }) {
*init(ignored, { put, call }) {
yield put({ type: 'setStatus', payload: 'login' });
yield put({ type: 'setUCACode', payload: '' });
yield put({ type: 'setAuthRequires', payload: [] });
const userName = yield call(histories.getLatest, 'userName');
yield put({ type: 'setUserName', payload: userName || '' });
},
*login({ payload: userName }, { call, put }) {
yield put({ type: 'setUserName', userName });
const { tokenId, remainedAuthRequirements } = yield call(login, {
type: 'userName',
data: userName,
......@@ -114,7 +116,7 @@ export default {
const { data } = yield call(authorize, yield call(requestCode, encrypt(tkId)));
yield put({ type: 'setUCACode', payload: data });
},
*auth({ payload: { password, uca } }, { call }) {
*auth({ payload: { userName, password, uca, remember } }, { call }) {
let response;
if (password) {
response = yield call(authorize, yield call(passValidate, password, encrypt(tkId)));
......@@ -140,47 +142,10 @@ export default {
throw errors.authFailed(data);
}
if (remainedAuthRequirements.requirements.length === 0) {
yield call(successAuthed, tkId);
yield call(successAuthed, tkId, userName, remember);
}
}
},
/* *login({ payload }, { call, put }) {
const loginRequest = {
type: 'userName',
data: payload.userName,
authRequest: yield call(validate, payload.password),
};
const result = yield call(login, loginRequest);
const { tokenId, authResponse, remainedAuthRequirements } = result;
if (authResponse.status !== 'authed' && authResponse.status !== 'skipped') {
throw errors.wrongPassword();
}
const { requirements } = remainedAuthRequirements;
if (requirements.length > 0) {
throw errors.unsupportedAuthType(requirements);
}
yield call(setToken, tokenId);
const uInfo = yield call(userInfo);
yield call(setUser, uInfo.id, uInfo.name);
const path = yield call(histories.getLatest, 'domain');
if (!path) {
yield put(routerRedux.push(fullPath('/domain')));
} else {
yield call(switchDomain, path);
const domain = yield call(currentDomain);
if (domain) {
yield call(setDomain, domain.name, path);
const latest = yield call(histories.getLatest, 'module');
if (latest && config.fastNavigationPage) {
yield put(routerRedux.push(fullPath('/fastNav')));
} else {
yield put(routerRedux.push(fullPath('/main')));
}
} else {
yield put(routerRedux.push(fullPath('/domain')));
}
}
},*/
},
subscriptions: {},
};
......@@ -26,10 +26,8 @@ class AuthInputs extends React.Component {
}
</Select>
{
React.cloneElement(data[this.state.index >= 0 ? this.state.index : 0].node,
React.cloneElement(data[this.state.index >= 0 ? this.state.index : 0].node(),
{
value: this.props.value,
onChange: this.props.onChange,
style: { width: '70%' },
})
}
......
......@@ -83,12 +83,12 @@ class LoginForm extends React.Component {
{
key: 'password',
label: '密码',
node: this.createPassword(focus),
node: () => this.createPassword(focus),
},
{
key: 'uca',
label: '证书',
node: this.createUCA(focus),
node: () => this.createUCA(focus),
},
]}
/>
......@@ -127,12 +127,21 @@ class LoginForm extends React.Component {
<Form.Item>
{
getFieldDecorator('userName', {
initialValue: this.props.login.userName,
rules: [{
required: true,
message: '请输入用户名。',
}],
})(
<Input autoFocus={!this.authFocus} onBlur={this.onUserBlur} prefix={<Icon type="user" />} placeholder="用户名" />,
<Input
autoFocus={!this.authFocus}
onBlur={this.onUserBlur}
prefix={<Icon type="user" />}
placeholder="用户名"
onChange={() => {
this.props.dispatch({ type: 'login/setStatus', payload: 'login' });
}}
/>,
)
}
</Form.Item>
......@@ -175,10 +184,4 @@ const mapStateToProps = ({ login, loading }) => {
};
};
export default connect(mapStateToProps)(Form.create({
onValuesChange: (props, values) => {
if (values.userName) {
props.dispatch({ type: 'login/setStatus', payload: 'login' });
}
},
})(LoginForm));
export default connect(mapStateToProps)(Form.create()(LoginForm));
......@@ -60,12 +60,18 @@ export async function hasDomain() {
return getDomain().then(result => !!result);
}
const normHistory = (history) => {
const normHistory = (history, size) => {
if (!history) {
history = {};
}
if (!history.size) {
history.size = 10;
if (size) {
history.size = size;
} else {
history.size = 10;
}
} else if (size && history.size !== size) {
history.size = size;
}
if (history.size < 1) {
history.size = 1;
......@@ -112,16 +118,15 @@ export const histories = {
},
async createHistory(name, size) {
let history = db.get(`history.${name}`).value();
history = normHistory(history);
history.size = size;
history = normHistory(history, size);
return db.set(`history.${name}`, history).write();
},
async destroyHistory(name) {
return db.unset(`history.${name}`).write();
},
async getHistory(name) {
async getHistory(name, size) {
let history = db.get(`history.${name}`).value();
history = normHistory(history);
history = normHistory(history, size);
if (history.empty) {
return [];
} else if (history.top > history.start) {
......@@ -130,9 +135,9 @@ export const histories = {
return [...history.data.slice(history.start, history.size), ...history.data.slice(0, history.top)];
}
},
async pushHistory(name, value) {
async pushHistory(name, value, size) {
let history = await db.get(`history.${name}`).value();
history = normHistory(history);
history = normHistory(history, size);
history.data[history.top] = value;
const nextPos = next(history.top, history.size);
if (!history.empty && history.start === history.top) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论