diff --git a/index.php b/index.php index ea405c7..5e01c87 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,4 @@ + diff --git a/js/contentloader.js b/js/contentloader.js index f6698b7..c84ea4f 100644 --- a/js/contentloader.js +++ b/js/contentloader.js @@ -25,6 +25,9 @@ document.getElementById('btnCreate').addEventListener("click" , async (event) => method: 'post', body: formData }); + const jsonData = await response.json(); + console.log(jsonData); + } catch (e) { console.log("Abschicken der Daten fehlerhaft!"); } @@ -36,7 +39,7 @@ document.getElementById('btnLogin').addEventListener("click" , async (event) => // if (document.getElementById('btnLogin') === "Login") { const formData = new FormData(document.getElementById('login-form')); - try { + // try { const response = await fetch('php/signup.php', { method: 'post', body: formData @@ -47,23 +50,26 @@ document.getElementById('btnLogin').addEventListener("click" , async (event) => 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"; - } + document.getElementById('login-status').innerHTML = "Eingeloggt"; + location.replace('index2.htm'); + // 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"); - } + // } + // catch (e) { + // console.log("Login Fehler"); + // } // } }) diff --git a/php/signin.php b/php/signin.php index 10551e8..3fcc839 100644 --- a/php/signin.php +++ b/php/signin.php @@ -6,11 +6,21 @@ $pswd = ($_POST['registerPassword']); $email = ($_POST['registerMail']); - // if ($abfrage == "") { + $search_user = $database->prepare("SELECT ID FROM user WHERE user='$name '"); + $search_user->execute(); + $search_result = $search_user->get_result(); + + if ($search_result->num_rows == 0) { + $pswd = md5($pswd); $stmt = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)"); $stmt->bind_param("sss", $name, $email, $pswd); $stmt->execute(); $stmt->close(); - // } + echo json_encode("Dein Account wurde erfolgreich erstellt!"); + } else { + echo json_encode("Der Benutzername ist leider schon vergeben!"); + } + + ?> diff --git a/php/signup.php b/php/signup.php index 546e511..319880d 100644 --- a/php/signup.php +++ b/php/signup.php @@ -1,36 +1,33 @@ + session_start(); require('../dbConnect.php'); + $name = ($_POST['loginName']); $pswd = ($_POST['loginPassword']); + // $pswd = md5($pswd); - 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"; + $stmt = $database->prepare("SELECT id FROM user WHERE '$name'=user AND password='$pswd'"); + $stmt->execute(); + $result = $stmt->get_result(); + + if ($result->num_rows == 1) { + $object = $result->fetch_object(); + $_SESSION['user'] = $object->id; + // header('Location: /index2.htm'); + echo json_encode('Eingeloggt!'); + // $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"; + $a = array('error' => 'Einlogen fehlgeschlagen!'); + echo json_encode($a); } - echo json_encode($a); - } else { - $a = array('error' => 'Einlogen fehlgeschlagen!' . $pswd . " " . $row['password']); - echo json_encode($a); - } ?>