Commit 6059db29 authored by 2breakegg's avatar 2breakegg

lint

parents 900bf08f 044b5655
import { Form, Input } from 'antd';
import React from 'react';
import { connect } from 'react-redux';
import SubmitButton from './SubmitButton';
import styles from './EmailForm.css';
import {connect} from 'react-redux'
import { Form, Input, Icon, Button } from 'antd'
const FormItem = Form.Item;
import SubmitButton from './SubmitButton'
const formItemLayout = {
labelCol: { span: 4 },
wrapperCol: { span: 15 },
};
}
class EmailForm extends React.Component {
onUpdateEmail = (e) => {
const { form, dispatch, data: { id } } = this.props;
onSubmit = (e) => {
const { form, dispatch, data: {id} } = this.props
e && e.preventDefault();
form.validateFieldsAndScroll((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
const { email, password } = values
const { email, password } = values;
dispatch({ type: 'user/updateEmail', payload: { email, password, user_id: id } });
dispatch({type: "user/updateAccount", payload: { email, password, user_id: id }})
}
});
};
}
render() {
render(){
const { form, dispatch, data, checkEmail, isEmailExists } = this.props;
const { getFieldDecorator } = form;
const { id, email } = data;
const {form, dispatch, data, checkEmail, isEmailExists} = this.props
const {getFieldDecorator} = form
const {id, email} = data
const emailProps = {
fromItem: {
label: 'email',
label: "email",
hasFeedback: true,
validateStatus: checkEmail,
help: isEmailExists ? 'email exists' : '',
...formItemLayout
},
decorator: {
initialValue: email,
initialValue: email
},
input: {
placeholder: 'email',
},
};
placeholder: "email"
}
}
const passwordProps = {
fromItem: {
label: 'passwrod',
...formItemLayout,
label: "passwrod",
...formItemLayout
},
decorator: {
rules: [
{ required: true, message: '密码至少为8-24位', pattern: /^.{8,24}$/ },
],
{ required: true, message: '密码至少为8-24位', pattern: /^.{8,24}$/ }
]
},
input: {
placeholder: 'password',
type: 'password',
},
};
placeholder: "password",
type: 'password'
}
}
return (
<Form onSubmit={this.onUpdateEmail}>
<Form onSubmit={this.onSubmit}>
<FormItem {...emailProps.fromItem}>
{getFieldDecorator(`email`, { ...emailProps.decorator })(
<Input
{...emailProps.input}
onBlur={() => dispatch({ type: 'auth/checkEmail', payload: { ...form.getFieldsValue(), id } })}/>,
{getFieldDecorator(`email`, {...emailProps.decorator})(
<Input
{...emailProps.input}
onBlur = {() => dispatch({type: 'auth/checkEmail', payload: { ...form.getFieldsValue(), id} })}/>
)}
</FormItem>
<FormItem {...passwordProps.fromItem}>
{getFieldDecorator('password', { ...passwordProps.decorator })(
<Input {...passwordProps.input} />,
{getFieldDecorator(`password`, {...passwordProps.decorator})(
<Input {...passwordProps.input} />
)}
</FormItem>
......@@ -92,19 +92,20 @@ class EmailForm extends React.Component {
}
function mapStateToProps(state) {
function mapStateToProps(state, props) {
const {
user: { data },
auth: { isEmailExists, checkEmail },
} = state;
user: {data},
auth: {isEmailExists, checkEmail}
} = state
return {
data,
checkEmail,
isEmailExists,
isEmailExists
};
}
const WrapperEmailForm = Form.create()(EmailForm);
const WrapperEmailForm = Form.create()(EmailForm)
export default connect(mapStateToProps)(WrapperEmailForm);
import { Form, Input } from 'antd';
import React from 'react';
import { connect } from 'react-redux';
import SubmitButton from './SubmitButton';
import styles from './EmailForm.css';
import {connect} from 'react-redux'
import { Form, Input, Icon, Button } from 'antd'
const FormItem = Form.Item;
import SubmitButton from './SubmitButton'
const formItemLayout = {
labelCol: { span: 4 },
wrapperCol: { span: 15 },
};
}
class EmailForm extends React.Component {
checkPassword = (rule, value, callback) => {
const form = this.props.form;
if (value && value !== form.getFieldValue('new_password')) {
callback('两次密码输入不符');
} else {
callback();
}
}
checkConfirm = (rule, value, callback) => {
const form = this.props.form;
if (value) {
form.validateFields(['confirm'], { force: true });
}
callback();
}
onSubmit = (e) => {
const { form, dispatch, data: { id } } = this.props;
const { form, dispatch, data: {id} } = this.props
e && e.preventDefault();
form.validateFieldsAndScroll((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
const { new_password, password } = values
const { email, password } = values;
dispatch({ type: 'user/updateEmail', payload: { email, password, user_id: id } });
dispatch({type: "user/updateAccount", payload: { new_password, password, user_id: id }})
}
});
};
checkConfirm = (rule, value, callback) => {
const form = this.props.form;
if (value) {
form.validateFields(['confirm'], { force: true });
}
callback();
};
checkPassword = (rule, value, callback) => {
const form = this.props.form;
if (value && value !== form.getFieldValue('new_password')) {
callback('两次密码输入不符');
} else {
callback();
}
};
}
render() {
render(){
const { form } = this.props;
const { getFieldDecorator } = form;
const {form } = this.props
const {getFieldDecorator} = form
const passwordProps = {
fromItem: {
label: 'passwrod',
label: "passwrod",
...formItemLayout
},
decorator: {
rules: [
{ required: true, message: '密码至少为8-24位', pattern: /^.{8,24}$/ },
{ validator: this.checkConfirm },
],
{ validator: this.checkConfirm }
]
},
input: {
placeholder: 'password',
type: 'password',
},
};
placeholder: "password",
type: 'password'
}
}
const confirmProps = {
fromItem: {
label: 'comfirm',
label: "comfirm",
...formItemLayout
},
decorator: {
rules: [
{ required: true, message: '密码至少为8-24位', pattern: /^.{8,24}$/ },
{ validator: this.checkPassword },
],
{ required: true, message: '密码至少为8-24位', pattern: /^.{8,24}$/},
{ validator: this.checkPassword}
]
},
input: {
placeholder: 'confirm',
type: 'password',
},
};
placeholder: "confirm",
type: 'password'
}
}
return (
<Form onSubmit={this.onSubmit}>
<Form onSubmit={this.onSubmit}>
<FormItem {...passwordProps.fromItem} label="old password">
{getFieldDecorator(`old_password`, { ...passwordProps.decorator })(
<Input {...passwordProps.input} />,
{getFieldDecorator(`password`, {...passwordProps.decorator})(
<Input {...passwordProps.input} />
)}
</FormItem>
<FormItem {...passwordProps.fromItem} label="new password">
{getFieldDecorator(`new_password`, { ...passwordProps.decorator })(
<Input {...passwordProps.input} />,
{getFieldDecorator(`new_password`, {...passwordProps.decorator})(
<Input {...passwordProps.input} />
)}
</FormItem>
<FormItem {...confirmProps.fromItem}>
{getFieldDecorator(`confirm`, { ...confirmProps.decorator })(
<Input {...confirmProps.input} />,
{getFieldDecorator(`confirm`, {...confirmProps.decorator})(
<Input {...confirmProps.input} />
)}
</FormItem>
......@@ -113,16 +113,18 @@ class EmailForm extends React.Component {
}
function mapStateToProps(state, props) {
const {
user: { data },
} = state;
user: {data}
} = state
return {
data,
};
}
const WrapperEmailForm = Form.create()(EmailForm);
const WrapperEmailForm = Form.create()(EmailForm)
export default connect(mapStateToProps)(WrapperEmailForm);
import React from 'react';
import styles from './SendEmail.css';
function SendEmail() {
return (
<div className={styles.normal}>
Component: SendEmail
</div>
);
}
export default SendEmail;
import dva from 'dva';
import { browserHistory } from 'dva/router';
import ReactDOM from 'react-dom';
import { addLocaleData, IntlProvider } from 'react-intl';
import en from 'react-intl/locale-data/en';
import zh from 'react-intl/locale-data/zh';
import localeData from '../i18n.json';
import { browserHistory } from 'dva/router'
import { message } from 'antd'
import './index.css';
import { IntlProvider, addLocaleData } from 'react-intl';
// 1. Initialize
const app = dva({
history: browserHistory,
onError: (error, dispatch) => {
message.destroy();
message.error(error.message);
},
history: browserHistory
});
......@@ -35,6 +37,9 @@ app.model(require('./models/common'));
app.router(require('./router'));
// 5. Start
import en from 'react-intl/locale-data/en'
import zh from 'react-intl/locale-data/zh'
import localeData from '../i18n.json'
addLocaleData([...en, ...zh]);
......
import { message } from 'antd';
import { activate, checkUserExists, forgot, login, register, reset } from '../services/auth';
import { login, forgot, register, reset, activate, checkUserExists } from '../services/auth'
import { message } from 'antd'
export default {
......@@ -8,13 +8,15 @@ export default {
activateState: false,
checkEmail: '',
checkUsername: '',
isSendEmailActive: false,
isEmailExists: false,
isUserNameExists: false,
isRegisterSubmit: false,
isLoginSubmit: false,
isForgotSubmit: false,
isSpinSubmit: false,
register: {},
isActivateSubmit: false,
register: {}
},
reducers: {
change(state, action) {
......@@ -100,111 +102,105 @@ export default {
forgotSuccess(state, action) {
return {
...state, ...{
isForgotSubmit: false,
isForgotSubmit: false
}
};
}
},
forgotFail(state, action) {
return {
...state, ...{
isForgotSubmit: false,
isForgotSubmit: false
}
};
}
},
reset(state, action) {
return {
...state, ...{
isResetSubmit: true,
isResetSubmit: true
}
};
}
},
resetSuccess(state, action) {
return {
...state, ...{
isResetSubmit: false,
isResetSubmit: false
}
};
}
},
resetFail(state, action) {
return {
...state, ...{
isResetSubmit: false,
isResetSubmit: false
}
};
}
},
},
effects: {
*activate({ payload }, { call, put }) {
const { data } = yield call(activate, payload);
if (data) {
yield put({ type: 'check', payload: { activateState: false } });
}
const { data } = yield call(activate, payload)
},
*checkEmail({ payload }, { call, put }) {
const { data } = yield call(checkUserExists, payload);
const { data } = yield call(checkUserExists, payload)
if (data) {
yield put({ type: 'check', payload: { isEmailExists: true, checkEmail: 'warning' } });
if(data) {
yield put({ type: 'check', payload: { isEmailExists: true , checkEmail: 'warning'}})
} else {
yield put({ type: 'check', payload: { isEmailExists: false, checkEmail: 'success' } });
yield put({ type: 'check', payload: { isEmailExists: false , checkEmail: 'success'}})
}
},
*checkUsername({ payload }, { call, put }) {
const { data } = yield call(checkUserExists, payload);
const { data } = yield call(checkUserExists, payload)
if (data) {
yield put({ type: 'check', payload: { isUserNameExists: true, checkUsername: 'warning' } });
if(data) {
yield put({ type: 'check', payload: { isUserNameExists: true , checkUsername: 'warning'}})
} else {
yield put({ type: 'check', payload: { isUserNameExists: false, checkUsername: 'success' } });
yield put({ type: 'check', payload: { isUserNameExists: false , checkUsername: 'success'}})
}
},
*login({ payload }, { call, put }) {
const { data } = yield call(login, payload);
const {data} = yield call(login, payload)
if (data) {
yield put({ type: 'loginSuccess' });
yield put({ type: 'user/loginSuccess', payload: { data } });
message.info('登录成功');
} else {
yield put({ type: 'loginFail' });
message.error('登陆失败');
}
if(data){
yield put({ type: 'loginSuccess' })
yield put({ type: 'user/loginSuccess', payload: { data } })
message.info("登录成功")
} else {
yield put({ type: 'loginFail' })
message.error("登陆失败")
}
},
*forgot({ payload }, { call, put }) {
const { data } = yield call(forgot, payload);
const { data } = yield call(forgot, payload)
if (data) {
yield put({ type: 'forgotSuccess' });
message.info('已发送密码重置邮件');
} else {
yield put({ type: 'forgotFail' });
message.error('密码重置邮件发送失败');
}
if(data){
yield put({ type: 'forgotSuccess' })
message.info("已发送密码重置邮件")
}else {
yield put({ type: 'forgotFail' })
message.error("密码重置邮件发送失败")
}
},
*register({ payload }, { call, put }) {
const { data } = yield call(register, payload);
const {data} = yield call(register, payload)
if (data) {
yield put({ type: 'registerSuccess' });
message.info('注册成功');
} else {
yield put({ type: 'registerFail' });
message.error('注册失败');
}
if(data) {
yield put({ type: 'registerSuccess'})
message.info("注册成功")
} else {
yield put({ type: 'registerFail' })
message.error("注册失败")
}
},
*reset({ payload }, { call, put }) {
const { data } = yield call(reset, payload);
const { data } = yield call(reset, payload)
if (data) {
yield put({ type: 'resetSuccess' });
message.info('重置成功');
} else {
yield put({ type: 'resetFail' });
message.error('重置失败');
}
if(data){
yield put({ type: 'resetSuccess' })
message.info("重置成功")
}else{
yield put({ type: 'resetFail' })
message.error("重置失败")
}
},
},
subscriptions: {},
......
import { message } from 'antd';
import { routerRedux } from 'dva/router';
import { updateAccount, updateProfile } from '../services/user';
import { routerRedux } from 'dva/router'
import { updateProfile, updateAccount } from '../services/user'
import { message } from 'antd'
export default {
namespace: 'user',
state: {
data: {},
isUpdateSubmit: false,
isUpdateSubmit: false
},
reducers: {
loginFromStorage(state, action) {
return {
...state, ...action.payload
};
}
},
loginSuccess(state, action) {
return {
...state, ...action.payload
};
}
},
updateProfile(state, action) {
return {
...state, ...{
isUpdateSubmit: true,
isUpdateSubmit: true
}
};
}
},
updateProfileSuccess(state, action) {
return {
...state, ...action.payload, ...{
isUpdateSubmit: false,
isUpdateSubmit: false
}
};
}
},
updateProfileFail(state, action) {
return {
...state, ...{
isUpdateSubmit: false,
isUpdateSubmit: false
}
};
}
},
updateAccount(state, action) {
return {
...state, ...{
isUpdateSubmit: true,
isUpdateSubmit: true
}
};
}
},
updateAccountSuccess(state, action) {
return {
...state, ...action.payload, ...{
isUpdateSubmit: false,
isUpdateSubmit: false
}
};
}
},
updateAccountFail(state, action) {
return {
...state, ...{
isUpdateSubmit: false,
isUpdateSubmit: false
}
};
}
},
},
effects: {
*loginSuccess({ payload }, { call, put }) {
localStorage.setItem('user', JSON.stringify(payload.data));
localStorage.setItem("user", JSON.stringify(payload.data))
yield put(routerRedux.replace('/profiles'));
yield put(routerRedux.replace("/profiles"))
},
*preLogin({ payload }, { call, put }) {
let user = localStorage.getItem('user');
let user = localStorage.getItem("user")
if (!user) {
yield put(routerRedux.replace('/login'));
if(!user){
yield put(routerRedux.replace("/login"))
}
yield put({ type: 'loginFromStorage', payload: { data: JSON.parse(user) } });
yield put({type: 'loginFromStorage', payload: { data: JSON.parse(user) }})
},
*updateProfile({ payload }, { call, put }) {
let { data } = yield call(updateProfile, payload);
if (data) {
yield put({ type: 'updateProfileSuccess', payload: { data } });
message.info('更新成功');
} else {
yield put({ type: 'updateProfileFail' });
message.error('更新失败');
}
let { data } = yield call(updateProfile, payload )
if(data){
yield put({ type: 'updateProfileSuccess', payload: { data } })
message.info("更新成功")
}else {
yield put({ type: 'updateProfileFail' })
message.error("更新失败")
}
},
*updateAccount({ payload }, { call, put }) {
try {
let { data } = yield call(updateAccount, payload )
let { data } = yield call(updateAccount, payload);
if (data) {
yield put({ type: 'updateAccountSuccess', payload: { data } });
message.info('更新成功');
} else {
yield put({ type: 'updateAccountFail' });
message.error('更新失败');
if(data){
yield put({ type: 'updateAccountSuccess', payload: { data } })
message.info("更新成功")
}
} catch (error) {
yield put({ type: 'updateAccountFail' })
message.error(error.message)
}
},
},
subscriptions: {
setup({ dispatch, history }) {
return history.listen(({ pathname, query }) => {
if (pathname == '/profiles') {
dispatch({ type: 'preLogin', payload: query });
return history.listen(({ pathname, query}) => {
if(pathname == '/profiles') {
dispatch({ type: 'preLogin', payload: query})
}
});
},
})
}
},
};
......@@ -5,12 +5,19 @@ function parseJSON(response) {
return response.json();
}
function checkStatus(response) {
async function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
}
const error = new Error(response.statusText);
let message
try {
message = (await response.json())["message"]
} catch (error) {
message = response.statusText
}
const error = new Error(message);
error.response = response;
throw error;
}
......@@ -23,16 +30,16 @@ function checkStatus(response) {
* @return {object} An object containing either "data" or "err"
*/
export default function request(url, options) {
url = `${config.apiRoot}${url}`;
if (options && !options.headers && (options.method == 'POST' || options.method == 'PATCH')) {
url = `${config.apiRoot}${url}`
if(options && !options.headers && (options.method == 'POST' || options.method == 'PATCH')) {
options.headers = {
'content-type': 'application/json',
};
"content-type": "application/json"
}
}
console.log(options);
console.log(options)
return fetch(url, options)
.then(checkStatus)
.then(parseJSON)
.then(data => ({ data }))
.catch(err => ({ err }));
};
// .catch(err => ({ err }));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment