Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import {Button, FormGroup, FormControl, ControlLabel} from "react-bootstrap";
- import './login.css';
- export default class loginForm extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- username: '',
- password: '',
- answer:[],
- };
- this.handleSubmit = this.handleSubmit.bind(this);
- }
- async handleSubmit(event) {
- const jso = JSON.stringify({
- username: this.state.username,
- password: this.state.password
- })
- const response = await fetch("https://app.herokuapp.com/authentication", {
- method: 'POST',
- mode: 'cors',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- body: jso,
- })
- const json = await response.json()
- this.setState({answer:json});
- //check if user is authentificated
- alert("Server Answer : "+ this.state.answer.answer);
- if(this.state.answer.answer.localeCompare('true') == 0){
- this.props.app.setState({auth: true});
- sessionStorage.setItem('auth', true);
- }
- else if (this.state.username != ""){
- alert("INCORRECT USERNAME PASSWORD ");
- }
- }
- render() {
- return (<div className="Login">
- <form onSubmit={this.handleSubmit}>
- //part omitted because not relevant for this question
- <Button bsSize="small" color="primary" type="submit">
- Login
- </Button >
- </form>
- </div>)
- }
- }
Add Comment
Please, Sign In to add comment