Commit d9a6c62a authored by nanahira's avatar nanahira

use api to decide change username

parent ada5095c
...@@ -24,6 +24,6 @@ upload_to_minio: ...@@ -24,6 +24,6 @@ upload_to_minio:
tags: tags:
- linux - linux
script: script:
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync dist/ s3://mycard/accounts - aws s3 --endpoint=https://minio.moenext.com:9000 sync dist/ s3://mycard/accounts
only: only:
- master - master
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -15,6 +15,10 @@ class EmailForm extends React.Component { ...@@ -15,6 +15,10 @@ class EmailForm extends React.Component {
countdown: 0, countdown: 0,
inCountdown: false, // Whether the countdown is active inCountdown: false, // Whether the countdown is active
}; };
componentDidMount() {
const { dispatch } = this.props;
dispatch({ type: 'auth/allowChangeUsername' });
}
onSubmit = (e) => { onSubmit = (e) => {
const { form, dispatch, user: { id } } = this.props; const { form, dispatch, user: { id } } = this.props;
...@@ -78,7 +82,7 @@ class EmailForm extends React.Component { ...@@ -78,7 +82,7 @@ class EmailForm extends React.Component {
}; };
render() { render() {
const { form, dispatch, user, checkUsername, isUserNameExists, messages } = this.props; const { form, dispatch, user, checkUsername, isUserNameExists, allowChangeUsername, messages } = this.props;
const { getFieldDecorator } = form; const { getFieldDecorator } = form;
const { id, username } = user; const { id, username } = user;
const logoutNowText = this.props.messages.LogoutNow; const logoutNowText = this.props.messages.LogoutNow;
...@@ -144,7 +148,7 @@ class EmailForm extends React.Component { ...@@ -144,7 +148,7 @@ class EmailForm extends React.Component {
<Form onSubmit={this.onSubmit}> <Form onSubmit={this.onSubmit}>
<FormItem {...usernameProps.fromItem}> <FormItem {...usernameProps.fromItem}>
{getFieldDecorator('username', { ...usernameProps.decorator })( {getFieldDecorator('username', { ...usernameProps.decorator })(
<Input {...usernameProps.input} disabled/>, <Input {...usernameProps.input} disabled={!allowChangeUsername} />,
)} )}
{ {
<div className="alert alert-warning" role="alert">{temporaryPromptText}</div> <div className="alert alert-warning" role="alert">{temporaryPromptText}</div>
...@@ -171,7 +175,7 @@ class EmailForm extends React.Component { ...@@ -171,7 +175,7 @@ class EmailForm extends React.Component {
function mapStateToProps(state) { function mapStateToProps(state) {
const { const {
user: { user }, user: { user },
auth: { isUserNameExists, checkUsername }, auth: { isUserNameExists, checkUsername, allowChangeUsername },
common: { messages }, common: { messages },
} = state; } = state;
return { return {
...@@ -179,6 +183,7 @@ function mapStateToProps(state) { ...@@ -179,6 +183,7 @@ function mapStateToProps(state) {
messages, messages,
checkUsername, checkUsername,
isUserNameExists, isUserNameExists,
allowChangeUsername,
}; };
} }
......
import { message } from 'antd'; import { message } from 'antd';
import { routerRedux } from 'dva/router'; import { routerRedux } from 'dva/router';
import { activate, checkUserExists, forgot, login, register, reset } from '../services/auth'; import { activate, checkUserExists, forgot, login, register, reset } from '../services/auth';
import { allowChangeUsername } from '../services/allow-change-username';
export default { export default {
...@@ -18,6 +19,7 @@ export default { ...@@ -18,6 +19,7 @@ export default {
isForgotSubmit: false, isForgotSubmit: false,
isSpinSubmit: false, isSpinSubmit: false,
isActivateSubmit: false, isActivateSubmit: false,
allowChangeUsername: true,
register: {}, register: {},
}, },
reducers: { reducers: {
...@@ -286,6 +288,16 @@ export default { ...@@ -286,6 +288,16 @@ export default {
message.error(messages[error.message] || error.message, 3); message.error(messages[error.message] || error.message, 3);
} }
}, },
*allowChangeUsername(_, { call, put }) {
try {
const { data } = yield call(allowChangeUsername);
if (data && typeof data.allow === 'boolean') {
yield put({ type: 'change', payload: { allowChangeUsername: data.allow } });
}
} catch (error) {
console.error(error);
}
},
}, },
subscriptions: {}, subscriptions: {},
}; };
import request from '../utils/request';
export async function allowChangeUsername() {
return request('/allowChangeUsername', {
method: 'GET',
});
}
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