-
-
Save StipJey/154f6716301da9ab81ce5f6404c1ce87 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: '' | |
}; | |
this.updateLogin = this.updateLogin.bind(this); | |
this.updatePass = this.updatePass.bind(this); | |
this.login = this.login.bind(this); | |
} | |
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={this.updateLogin} | |
/> | |
<FieldGroup | |
id="password" | |
type="password" | |
label="Парль" | |
value={this.state.password} | |
onChange={this.updatePass} | |
/> | |
</form> | |
<Button bsStyle="primary" onClick={this.login} >Войти</Button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment