Commit d9a6c62a authored by nanahira's avatar nanahira

use api to decide change username

parent ada5095c
......@@ -24,6 +24,6 @@ upload_to_minio:
tags:
- linux
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:
- 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 {
countdown: 0,
inCountdown: false, // Whether the countdown is active
};
componentDidMount() {
const { dispatch } = this.props;
dispatch({ type: 'auth/allowChangeUsername' });
}
onSubmit = (e) => {
const { form, dispatch, user: { id } } = this.props;
......@@ -78,7 +82,7 @@ class EmailForm extends React.Component {
};
render() {
const { form, dispatch, user, checkUsername, isUserNameExists, messages } = this.props;
const { form, dispatch, user, checkUsername, isUserNameExists, allowChangeUsername, messages } = this.props;
const { getFieldDecorator } = form;
const { id, username } = user;
const logoutNowText = this.props.messages.LogoutNow;
......@@ -144,7 +148,7 @@ class EmailForm extends React.Component {
<Form onSubmit={this.onSubmit}>
<FormItem {...usernameProps.fromItem}>
{getFieldDecorator('username', { ...usernameProps.decorator })(
<Input {...usernameProps.input} disabled/>,
<Input {...usernameProps.input} disabled={!allowChangeUsername} />,
)}
{
<div className="alert alert-warning" role="alert">{temporaryPromptText}</div>
......@@ -171,7 +175,7 @@ class EmailForm extends React.Component {
function mapStateToProps(state) {
const {
user: { user },
auth: { isUserNameExists, checkUsername },
auth: { isUserNameExists, checkUsername, allowChangeUsername },
common: { messages },
} = state;
return {
......@@ -179,6 +183,7 @@ function mapStateToProps(state) {
messages,
checkUsername,
isUserNameExists,
allowChangeUsername,
};
}
......
import { message } from 'antd';
import { routerRedux } from 'dva/router';
import { activate, checkUserExists, forgot, login, register, reset } from '../services/auth';
import { allowChangeUsername } from '../services/allow-change-username';
export default {
......@@ -18,6 +19,7 @@ export default {
isForgotSubmit: false,
isSpinSubmit: false,
isActivateSubmit: false,
allowChangeUsername: true,
register: {},
},
reducers: {
......@@ -286,6 +288,16 @@ export default {
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: {},
};
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