|
|
@@ -33,15 +33,15 @@ class LoginInput extends Component {
|
|
|
login_password: '',
|
|
|
loginStatus: '',
|
|
|
loginOnce: true,
|
|
|
- usernameTip: false
|
|
|
+ usernameTip: false,
|
|
|
+ login_success: false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
login = () => {
|
|
|
let _this = this;
|
|
|
// let loginUrl = `http://localhost:8999/login`;
|
|
|
-
|
|
|
- if (this.state.login_username !== '' && this.state.login_password !== '' ) {
|
|
|
+ if (this.state.login_username !== '' && this.state.login_password !== '') {
|
|
|
axios.post(loginUrl, {
|
|
|
'user-name': this.state.login_username,
|
|
|
password: this.state.login_password
|
|
|
@@ -54,15 +54,18 @@ class LoginInput extends Component {
|
|
|
});
|
|
|
setCookie("user_id", res.data);
|
|
|
_this.props.getUserId(res.data);
|
|
|
- request(graphqlUrl, GET_USER, {id: res.data}).then(data => {
|
|
|
- if (this._isMounted) {
|
|
|
- this.setState({
|
|
|
- avatar: data.user_by_id.avatar,
|
|
|
- nickname: data.user_by_id.nickname
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
+
|
|
|
+ _this.props.history.push({
|
|
|
+ pathname: '/'
|
|
|
+ });
|
|
|
+
|
|
|
+ // request(graphqlUrl, GET_USER, {id: res.data}).then(data => {
|
|
|
+ // _this.setState({
|
|
|
+ // avatar: data.user_by_id.avatar,
|
|
|
+ // nickname: data.user_by_id.nickname
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // )
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
_this.setState({
|
|
|
@@ -84,7 +87,8 @@ class LoginInput extends Component {
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
- <span style={{marginRight: 20,color: '#1385e5'}} className='login-title'><b><FormattedMessage id="register"/>:</b></span>
|
|
|
+ <span style={{marginRight: 20, color: '#1385e5'}}
|
|
|
+ className='login-title'><b><FormattedMessage id="register"/>:</b></span>
|
|
|
<div style={{marginTop: 15}}>
|
|
|
<span className='login-item'><FormattedMessage id="username"/>: </span>
|
|
|
<Input
|
|
|
@@ -126,54 +130,54 @@ class LoginInput extends Component {
|
|
|
/>
|
|
|
</div>
|
|
|
<Button type='primary'
|
|
|
- style={{margin:'10px 0'}}
|
|
|
+ style={{margin: '10px 0'}}
|
|
|
onClick={() => {
|
|
|
- request(graphqlUrl, SEARCH_USER, {username: this.state.register_username}).then(data => {
|
|
|
- if (data.user_by_props.length === 0) {
|
|
|
- let id = idGen('user');
|
|
|
- let _this = this;
|
|
|
- create_user({
|
|
|
- variables: {
|
|
|
- id,
|
|
|
- email: '',
|
|
|
- updatedAt: '',
|
|
|
- password: '',
|
|
|
- telephone: '',
|
|
|
- nickname: this.state.register_nickname,
|
|
|
- username: this.state.register_username,
|
|
|
- createdAt: new Date().getTime(),
|
|
|
- openid: '',
|
|
|
- avatar: ''
|
|
|
- }
|
|
|
- });
|
|
|
- axios.post(registerUrl,
|
|
|
- {
|
|
|
- 'user-id': id,
|
|
|
- password: this.state.register_password,
|
|
|
- token: 'WXgraphql4Io'
|
|
|
- })
|
|
|
- .then(function (response) {
|
|
|
- if (response.status === 200)
|
|
|
- _this.setState({
|
|
|
- hasRegister: true
|
|
|
+ request(graphqlUrl, SEARCH_USER, {username: this.state.register_username}).then(data => {
|
|
|
+ if (data.user_by_props.length === 0) {
|
|
|
+ let id = idGen('user');
|
|
|
+ let _this = this;
|
|
|
+ create_user({
|
|
|
+ variables: {
|
|
|
+ id,
|
|
|
+ email: '',
|
|
|
+ updatedAt: '',
|
|
|
+ password: '',
|
|
|
+ telephone: '',
|
|
|
+ nickname: this.state.register_nickname,
|
|
|
+ username: this.state.register_username,
|
|
|
+ createdAt: new Date().getTime(),
|
|
|
+ openid: '',
|
|
|
+ avatar: ''
|
|
|
+ }
|
|
|
+ });
|
|
|
+ axios.post(registerUrl,
|
|
|
+ {
|
|
|
+ 'user-id': id,
|
|
|
+ password: this.state.register_password,
|
|
|
+ token: 'WXgraphql4Io'
|
|
|
})
|
|
|
- })
|
|
|
- .catch(function (error) {
|
|
|
- console.log(error);
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.setState({
|
|
|
- usernameTip: true
|
|
|
+ .then(function (response) {
|
|
|
+ if (response.status === 200)
|
|
|
+ _this.setState({
|
|
|
+ hasRegister: true
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .catch(function (error) {
|
|
|
+ console.log(error);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setState({
|
|
|
+ usernameTip: true
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ this.setState({
|
|
|
+ usernameTip: false
|
|
|
+ });
|
|
|
+ }, 1500)
|
|
|
+ }
|
|
|
});
|
|
|
- setTimeout(() => {
|
|
|
- this.setState({
|
|
|
- usernameTip: false
|
|
|
- });
|
|
|
- }, 1500)
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
- }}>ok</Button>
|
|
|
+ }}>ok</Button>
|
|
|
</div>
|
|
|
);
|
|
|
}}
|
|
|
@@ -190,11 +194,11 @@ class LoginInput extends Component {
|
|
|
if (res.data !== '') {
|
|
|
setCookie("user_id", res.data);
|
|
|
_this.setState({
|
|
|
- userID: res.data,
|
|
|
- hasLogin: true,
|
|
|
- loginOnce: false,
|
|
|
- loginStatus: 'logined'
|
|
|
- }, () => {
|
|
|
+ userID: res.data,
|
|
|
+ hasLogin: true,
|
|
|
+ loginOnce: false,
|
|
|
+ loginStatus: 'logined'
|
|
|
+ }, () => {
|
|
|
request(graphqlUrl, GET_USER, {id: res.data}).then(data => {
|
|
|
if (this._isMounted) {
|
|
|
this.setState({
|
|
|
@@ -228,7 +232,8 @@ class LoginInput extends Component {
|
|
|
''
|
|
|
:
|
|
|
<div>
|
|
|
- <span style={{marginRight: 20,color: '#1385e5'}} className='login-title'><b><FormattedMessage id="login"/>:</b></span>
|
|
|
+ <span style={{marginRight: 20, color: '#1385e5'}}
|
|
|
+ className='login-title'><b><FormattedMessage id="login"/>:</b></span>
|
|
|
<div style={{marginTop: 10}}>
|
|
|
<span className='login-item'><FormattedMessage id="username"/>: </span>
|
|
|
<Input
|
|
|
@@ -252,12 +257,12 @@ class LoginInput extends Component {
|
|
|
/>
|
|
|
</div>
|
|
|
<Button type='primary'
|
|
|
- style={{margin:'10px 0'}}
|
|
|
+ style={{margin: '10px 0'}}
|
|
|
onClick={() => {
|
|
|
- this.setState({
|
|
|
- hasLogin: true
|
|
|
- })
|
|
|
- }}>ok</Button>
|
|
|
+ this.setState({
|
|
|
+ hasLogin: true
|
|
|
+ })
|
|
|
+ }}>ok</Button>
|
|
|
</div>
|
|
|
}
|
|
|
{
|
|
|
@@ -292,14 +297,14 @@ class LoginInput extends Component {
|
|
|
<div>
|
|
|
<span style={{marginRight: '10px'}}><FormattedMessage id="login failed"/></span>
|
|
|
<Button
|
|
|
- style={{margin:'10px 0'}}
|
|
|
+ style={{margin: '10px 0'}}
|
|
|
onClick={() => {
|
|
|
- this.setState({
|
|
|
- hasLogin: false,
|
|
|
- loginStatus: '',
|
|
|
- loginOnce: true
|
|
|
- })
|
|
|
- }}><FormattedMessage id="relogin"/></Button>
|
|
|
+ this.setState({
|
|
|
+ hasLogin: false,
|
|
|
+ loginStatus: '',
|
|
|
+ loginOnce: true
|
|
|
+ })
|
|
|
+ }}><FormattedMessage id="relogin"/></Button>
|
|
|
</div>
|
|
|
:
|
|
|
''
|