import React from 'react'; import { makePostRequest } from 'utils/xhr'; import { setUserCookies } from 'utils/cookies'; 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) { event.preventDefault(); const name = event.target.name; const value = event.target.value; this.setState({[name]: value}); } loginToChannel (event) { event.preventDefault(); const params = `username=${this.state.name}&password=${this.state.password}`; const url = '/login'; const that = this; makePostRequest(url, params) .then(result => { setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId); that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId); }) .catch(error => { console.log('login error', error); if (error.message) { that.setState({'error': error.message}); } else { that.setState({'error': error}); } }); } render () { return (
); } } export default ChannelLoginForm;