Created
May 16, 2017 15:01
-
-
Save minya92/7b9abbbd4fd472cc1ea2b4a9e60c02e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by lapsh on 16.05.2017. | |
*/ | |
import React, { Component } from 'react'; | |
import { FormGroup, ControlLabel, FormControl, HelpBlock, Button} from 'react-bootstrap'; | |
function FieldGroup({ id, label, help, ...props }) { | |
return ( | |
<FormGroup controlId={id}> | |
<ControlLabel>{label}</ControlLabel> | |
<FormControl {...props} /> | |
{help && <HelpBlock>{help}</HelpBlock>} | |
</FormGroup> | |
); | |
} | |
export class Reg extends Component { | |
render() { | |
return ( | |
<div> | |
<h1> | |
Reg | |
</h1> | |
</div> | |
); | |
} | |
} | |
export class Login extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
login: '', | |
password: '' | |
}; | |
} | |
login(){ | |
console.log('Login: ', this.state); | |
fetch('http://localhost:3333/api/Trainers/login', { | |
method: 'POST', | |
headers: { | |
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8" | |
}, | |
body: 'email='+this.state.login+'&password='+this.state.password | |
}) | |
.then(function(res){ | |
return res.json() | |
}) | |
.then(function (data) { | |
console.log('Request succeeded with JSON response', data); | |
}) | |
.catch(function (error) { | |
console.log('Request failed', error); | |
}); | |
} | |
componentDidMount() { | |
} | |
updateLogin(evt) { | |
this.setState({ | |
login: evt.target.value | |
}); | |
} | |
updatePass(evt) { | |
this.setState({ | |
password: evt.target.value | |
}); | |
} | |
render() { | |
return ( | |
<div> | |
<h1> Авторизация </h1> | |
<form> | |
<FieldGroup | |
id="login" | |
type="email" | |
label="Email" | |
placeholder="Ваш Email" | |
value={this.state.login} | |
onChange={evt => this.updateLogin(evt)} | |
/> | |
<FieldGroup | |
id="password" | |
type="password" | |
label="Парль" | |
value={this.state.password} | |
onChange={evt => this.updatePass(evt)} | |
/> | |
</form> | |
<Button bsStyle="primary" onClick={evt => this.login()} >Войти</Button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment