From 78c1d2cd3fb254ad95ac69ca463216c8901d65d9 Mon Sep 17 00:00:00 2001 From: Kai Senkowski Date: Wed, 3 Jul 2019 12:34:48 +0200 Subject: [PATCH] login fixed --- Frontend/src/components/Login.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Frontend/src/components/Login.js b/Frontend/src/components/Login.js index 0bf8488..f72eec3 100644 --- a/Frontend/src/components/Login.js +++ b/Frontend/src/components/Login.js @@ -32,15 +32,23 @@ class Login extends Component { // 123Abc!& login() { - fetch("/login", { method: "POST", body: JSON.stringify(this.state) }) - .then(function(response) { - if (response.status === 200) return response.json(); - else return response.statusText; - }) - .then(function(myJson) { - console.log(myJson); - //document.cookie = myJson; + if (this.state.username !== "" && this.state.password !== "") { + var formData = new URLSearchParams(); + formData.append("username", this.state.username); + formData.append("password", this.state.password); + fetch("https://local.tobi.one/eva/login", { + method: "POST", + body: formData, + headers: { + "content-type": "application/x-www-form-urlencoded;charset=UTF-8" + } + }).then(response => { + if (response.status === 200) { + console.log("Logged in!"); + this.props.history.push("/"); + } else console.log(response.statusText); }); + } } render() { @@ -71,7 +79,7 @@ class Login extends Component {