2018-01-05 22:59:25 +01:00
|
|
|
import React from 'react';
|
2018-01-25 22:37:59 +01:00
|
|
|
import request from 'utils/request';
|
2018-01-05 22:59:25 +01:00
|
|
|
|
|
|
|
class ChannelLoginForm extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
error : null,
|
2018-01-11 20:41:12 +01:00
|
|
|
name : '',
|
|
|
|
password: '',
|
2018-01-05 22:59:25 +01:00
|
|
|
};
|
|
|
|
this.handleInput = this.handleInput.bind(this);
|
|
|
|
this.loginToChannel = this.loginToChannel.bind(this);
|
|
|
|
}
|
|
|
|
handleInput (event) {
|
|
|
|
const name = event.target.name;
|
|
|
|
const value = event.target.value;
|
|
|
|
this.setState({[name]: value});
|
|
|
|
}
|
|
|
|
loginToChannel (event) {
|
|
|
|
event.preventDefault();
|
2018-01-25 22:37:59 +01:00
|
|
|
const params = {
|
|
|
|
method : 'POST',
|
|
|
|
body : JSON.stringify({username: this.state.name, password: this.state.password}),
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}),
|
|
|
|
credentials: 'include',
|
|
|
|
}
|
|
|
|
request('login', params)
|
|
|
|
.then(({success, channelName, shortChannelId, channelClaimId, message}) => {
|
|
|
|
console.log('loginToChannel success:', success);
|
|
|
|
if (success) {
|
2018-02-07 00:05:31 +01:00
|
|
|
this.props.onChannelLogin(channelName, shortChannelId, channelClaimId);
|
2018-01-25 03:08:21 +01:00
|
|
|
} else {
|
2018-02-07 00:05:31 +01:00
|
|
|
this.setState({'error': message});
|
2018-01-25 03:08:21 +01:00
|
|
|
};
|
2018-01-06 00:11:45 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log('login error', error);
|
|
|
|
if (error.message) {
|
2018-02-07 00:05:31 +01:00
|
|
|
this.setState({'error': error.message});
|
2018-01-06 00:11:45 +01:00
|
|
|
} else {
|
2018-02-07 00:05:31 +01:00
|
|
|
this.setState({'error': error});
|
2018-01-06 00:11:45 +01:00
|
|
|
}
|
|
|
|
});
|
2018-01-05 22:59:25 +01:00
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<form id="channel-login-form">
|
|
|
|
<p id="login-error-display-element" className="info-message-placeholder info-message--failure">{this.state.error}</p>
|
|
|
|
<div className="row row--wide row--short">
|
|
|
|
<div className="column column--3 column--sml-10">
|
|
|
|
<label className="label" htmlFor="channel-login-name-input">Name:</label>
|
|
|
|
</div><div className="column column--6 column--sml-10">
|
|
|
|
<div className="input-text--primary flex-container--row flex-container--left-bottom">
|
|
|
|
<span>@</span>
|
|
|
|
<input type="text" id="channel-login-name-input" className="input-text" name="name" placeholder="Your Channel Name" value={this.state.channelName} onChange={this.handleInput}/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="row row--wide row--short">
|
|
|
|
<div className="column column--3 column--sml-10">
|
|
|
|
<label className="label" htmlFor="channel-login-password-input" >Password:</label>
|
|
|
|
</div><div className="column column--6 column--sml-10">
|
|
|
|
<div className="input-text--primary">
|
|
|
|
<input type="password" id="channel-login-password-input" name="password" className="input-text" placeholder="" value={this.state.channelPassword} onChange={this.handleInput}/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="row row--wide">
|
|
|
|
<button className="button--primary" onClick={this.loginToChannel}>Authenticate</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 19:49:57 +01:00
|
|
|
export default ChannelLoginForm;
|