diff --git a/js/contentloader.js b/js/contentloader.js index c541829..f6698b7 100644 --- a/js/contentloader.js +++ b/js/contentloader.js @@ -16,3 +16,54 @@ async function getNewUniqueLink() { } } + +// +document.getElementById('btnCreate').addEventListener("click" , async (event) => { + const formData = new FormData(document.getElementById('create-form')); + try { + const response = await fetch('php/signin.php', { + method: 'post', + body: formData + }); + } catch (e) { + console.log("Abschicken der Daten fehlerhaft!"); + } +}) + +// +document.getElementById('btnLogin').addEventListener("click" , async (event) => { + event.preventDefault(); + // if (document.getElementById('btnLogin') === "Login") { + const formData = new FormData(document.getElementById('login-form')); + + try { + const response = await fetch('php/signup.php', { + method: 'post', + body: formData + }); + const jsonData = await response.json(); + if (typeof jsonData.error !== 'undefined') { + console.log(jsonData); + document.getElementById('login-status').innerHTML = jsonData.error.fontcolor("red"); + } else { + console.log(jsonData); + if (jsonData == 'true') { + document.getElementById('toggle-login').innerHTML = "Logout"; + document.getElementById('btnLogin').innerHTML = "Logout"; + document.getElementById('exampleModalLabel').innerHTML = "Logout"; + document.getElementById('login-status').innerHTML = "Erfolgreich eingeloggt"; + } + else { + document.getElementById('toggle-login').innerHTML = "Login"; + document.getElementById('btnLogin').innerHTML = "Login"; + document.getElementById('exampleModalLabel').innerHTML = "Login"; + document.getElementById('login-status').innerHTML = "Erfolgreich ausgeloggt"; + } + // location.reload(); + } + } catch (e) { + console.log("Login Fehler"); + } + // } + +}) diff --git a/php/login.php b/php/login.php deleted file mode 100644 index 2cb3a58..0000000 --- a/php/login.php +++ /dev/null @@ -1,22 +0,0 @@ -real_escape_string($_POST['registerName']); - $pswd = $database->real_escape_string($_POST['registerPassword']); - $email = $database->real_escape_string($_POST['registerMail']); - - - $abfrage = "SELECT password WHERE $name=user"; - if ($pswd == $abfrage) { - // code.. - echo "HI"; - } - // if ($abfrage == "") { - $stmt = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)"); - $stmt->bind_param("sss", $name, $email, $pswd); - $stmt->execute(); - $stmt->close(); - // } - - ?> diff --git a/php/signin.php b/php/signin.php new file mode 100644 index 0000000..10551e8 --- /dev/null +++ b/php/signin.php @@ -0,0 +1,16 @@ + + require('../dbConnect.php'); + + $name = ($_POST['registerName']); + $pswd = ($_POST['registerPassword']); + $email = ($_POST['registerMail']); + + // if ($abfrage == "") { + $stmt = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)"); + $stmt->bind_param("sss", $name, $email, $pswd); + $stmt->execute(); + $stmt->close(); + // } + + ?> diff --git a/php/signup.php b/php/signup.php new file mode 100644 index 0000000..546e511 --- /dev/null +++ b/php/signup.php @@ -0,0 +1,36 @@ + + require('../dbConnect.php'); + + $name = ($_POST['loginName']); + $pswd = ($_POST['loginPassword']); + + try { + $stmt = $database->prepare("SELECT password FROM user WHERE '$name'=user"); + $stmt->execute(); + $result = $stmt->get_result(); + $row = $result->fetch_assoc(); + } catch (PDOException $e) { + $e->getMessage(); + } + if ($pswd == $row['password']) { + $stmt = $database->prepare("SELECT loggedin FROM user WHERE '$name'=user"); + $stmt->execute(); + $result = $stmt->get_result()->fetch_assoc(); + if ($result['loggedin'] == 'false') { + $stmt = $database->prepare("UPDATE `benutzer`.`user` SET `loggedin`='true' WHERE '$name'=user"); + $stmt->execute(); + $a = "true"; + } else { + $stmt = $database->prepare("UPDATE `benutzer`.`user` SET `loggedin`='false' WHERE '$name'=user"); + $stmt->execute(); + $a = "false"; + } + + echo json_encode($a); + } else { + $a = array('error' => 'Einlogen fehlgeschlagen!' . $pswd . " " . $row['password']); + echo json_encode($a); + } + +?> diff --git a/segments/_entryForm.php b/segments/_entryForm.php index 7bd8d50..db05cc6 100644 --- a/segments/_entryForm.php +++ b/segments/_entryForm.php @@ -219,7 +219,7 @@ function consumeTan($tanID) { - + diff --git a/segments/_header.html b/segments/_header.html index f10e2d1..e33476c 100644 --- a/segments/_header.html +++ b/segments/_header.html @@ -36,7 +36,7 @@
@@ -121,7 +124,7 @@