+
Session User:
+
+
diff --git a/js/contentloader.js b/js/contentloader.js
index c84ea4f..ca2f63b 100644
--- a/js/contentloader.js
+++ b/js/contentloader.js
@@ -21,7 +21,7 @@ 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', {
+ const response = await fetch('php/signup.php', {
method: 'post',
body: formData
});
@@ -32,44 +32,3 @@ document.getElementById('btnCreate').addEventListener("click" , async (event) =>
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);
- 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");
- // }
- // }
-
-})
diff --git a/php/signin.php b/php/signin.php
index 3fcc839..2da14f4 100644
--- a/php/signin.php
+++ b/php/signin.php
@@ -1,26 +1,37 @@
- require('../dbConnect.php');
-
- $name = ($_POST['registerName']);
- $pswd = ($_POST['registerPassword']);
- $email = ($_POST['registerMail']);
-
- $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!");
- }
+ //
+if(isset($_POST['login-form'])){
+ session_start();
+ require('dbConnect.php');
+ $name = ($_POST['loginName']);
+ $pswd = ($_POST['loginPassword']);
+ $pswd = md5($pswd);
- ?>
+ $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;
+ //$rueckgabe = array('html' => "Eingeloggt", 'id' => $object->id, 'session' => session_id());
+ // header('Location: /index2.htm');
+ //echo json_encode('Eingeloggt!');
+ //echo json_encode($rueckgabe);
+ // $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";
+ echo "Einloggen erfolgreich";
+ } else {
+ //$a = array('error' => 'Einlogen fehlgeschlagen!');
+ //echo json_encode($a);
+ echo "Einloggen fehlgeschlagen";
+ }
+}
+?>
diff --git a/php/signup.php b/php/signup.php
index 319880d..3fcc839 100644
--- a/php/signup.php
+++ b/php/signup.php
@@ -1,33 +1,26 @@
- session_start();
+ //
require('../dbConnect.php');
+ $name = ($_POST['registerName']);
+ $pswd = ($_POST['registerPassword']);
+ $email = ($_POST['registerMail']);
- $name = ($_POST['loginName']);
- $pswd = ($_POST['loginPassword']);
- // $pswd = md5($pswd);
+ $search_user = $database->prepare("SELECT ID FROM user WHERE user='$name '");
+ $search_user->execute();
+ $search_result = $search_user->get_result();
- $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 {
- $a = array('error' => 'Einlogen fehlgeschlagen!');
- echo json_encode($a);
- }
+ 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/segments/_header.html b/segments/_header.php
similarity index 97%
rename from segments/_header.html
rename to segments/_header.php
index e33476c..dce7ec7 100644
--- a/segments/_header.html
+++ b/segments/_header.php
@@ -49,6 +49,8 @@
+
+