Skip to content

Instantly share code, notes, and snippets.

@StipJey
Forked from minya92/Auth.js
Last active May 16, 2017 15:10
Show Gist options
  • Save StipJey/154f6716301da9ab81ce5f6404c1ce87 to your computer and use it in GitHub Desktop.
Save StipJey/154f6716301da9ab81ce5f6404c1ce87 to your computer and use it in GitHub Desktop.
/**
* 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