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

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

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