import React, { Component } from 'react'; import { Col, Row, Button, Form, FormGroup, Label, Input, Alert, } from 'reactstrap'; import { FaSignInAlt } from 'react-icons/fa'; import { Cookies } from 'react-cookie'; import API, { setAuthorization } 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) { const cookies = new Cookies(); const Authorization = `Basic ${new Buffer(`${this.state.email}:${this.state.password}`).toString('base64')}`; cookies.set('cfa_bo', Authorization); setAuthorization(Authorization); 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;