import React, { Component } from 'react'; import { Col, Row, Button, Form, FormGroup, Label, Input, Alert, } from 'reactstrap'; import API, { setDefaults } from './Api'; class Login extends Component { constructor(props) { super(props); this.signIn = this.signIn.bind(this); this.handleChange = this.handleChange.bind(this); this.state = { email: '', password: '', message: '', }; } signIn(event) { event.preventDefault(); // Let's stop this event. event.stopPropagation(); // Really this time. API.post('login', {}, { auth: { username: this.state.email, password: this.state.password, }, }) .then((response) => { if (response.status === 200) { setDefaults({ Authorization: `Basic ${new Buffer(`${this.state.email}:${this.state.password}`).toString('base64')}`, }); this.setState({ message: '' }); this.props.history.push('/categories'); } else { this.setState({ message: 'Mot de passe erroné !' }); } }) .catch(() => { this.setState({ message: 'Mot de passe erroné !' }); }); } handleChange(event) { const target = event.target; const value = target.type === 'checkbox' ? target.checked : target.value; const name = target.name; this.setState({ [name]: value, }); } render() { return (

RodiVert :: Interface de saisie

RodiVert
{this.state.message !== '' ? ( {this.state.message} ) : (null)}
); } } export default Login;