diff --git a/src/components/account/LoginForm.jsx b/src/components/account/LoginForm.jsx index ec171b8..03b2ec2 100644 --- a/src/components/account/LoginForm.jsx +++ b/src/components/account/LoginForm.jsx @@ -2,6 +2,7 @@ import React, { Component } from 'react' import { PropTypes, connect } from '../../family' import { login } from '../../actions/account' import { Link } from 'react-router-dom' +import { serve } from '../../config' import Mock from 'mockjs' import './LoginForm.css' @@ -16,6 +17,8 @@ const mockUser = process.env.NODE_ENV === 'development' password: '' }) +mockUser.captchaId = Date.now() + // 展示组件 class LoginForm extends Component { static contextTypes = { @@ -44,14 +47,19 @@ class LoginForm extends Component { this.setState({ password: e.target.value })} className='form-control' placeholder='Password' required /> +
+ + this.setState({ captcha: e.target.value })} className='form-control' placeholder='验证码' required /> + this.setState({ captchaId: Date.now() })} alt="captcha"/> +
注册
- {this.props.auth.errMsg && + {this.props.auth.message &&
- {this.props.auth.errMsg} + {this.props.auth.message}
} diff --git a/src/relatives/AccountRelative.js b/src/relatives/AccountRelative.js index 78ea41b..809d113 100644 --- a/src/relatives/AccountRelative.js +++ b/src/relatives/AccountRelative.js @@ -14,7 +14,7 @@ export default { case AccountAction.fetchLoginInfoFailed().type: return {} case AccountAction.loginFailed().type: - return { errMsg: '登陆错误,账户或密码错误。' } + return { message: action.message } default: return state } @@ -68,11 +68,11 @@ export default { * [AccountAction.login().type] (action) { try { const user = yield call(AccountService.login, action.user) - if (user) { + if (user && user.id) { yield put(AccountAction.loginSucceeded(user)) if (action.onResolved) action.onResolved() - } else { - yield put(AccountAction.loginFailed()) + } else if (user && user.errMsg) { + yield put(AccountAction.loginFailed(user.errMsg)) } } catch (e) { console.error(e.message) diff --git a/src/relatives/services/Account.js b/src/relatives/services/Account.js index 2ced477..23de3e0 100644 --- a/src/relatives/services/Account.js +++ b/src/relatives/services/Account.js @@ -20,11 +20,11 @@ export default { .then(json => json.data) }, // 用户登陆 - login ({ email, password }) { + login ({ email, password, captcha }) { return fetch(`${serve}/account/login`, { ...CREDENTIALS, method: 'POST', - body: JSON.stringify({ email, password }), + body: JSON.stringify({ email, password, captcha }), headers: { 'Content-Type': 'application/json' } }) .then(res => res.json())