import React from 'react'; import request from 'utils/request'; class ChannelLoginForm extends React.Component { constructor (props) { super(props); this.state = { error : null, name : '', password: '', }; 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(); 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) { this.props.onChannelLogin(channelName, shortChannelId, channelClaimId); } else { this.setState({'error': message}); }; }) .catch(error => { console.log('login error', error); if (error.message) { this.setState({'error': error.message}); } else { this.setState({'error': error}); } }); } render () { return (
); } } export default ChannelLoginForm;