Session implementiert
This commit is contained in:
parent
3c53460d20
commit
7e84260cb7
@ -1,3 +1,4 @@
|
|||||||
|
<?php session_start(); ?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -25,6 +25,9 @@ document.getElementById('btnCreate').addEventListener("click" , async (event) =>
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
|
const jsonData = await response.json();
|
||||||
|
console.log(jsonData);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Abschicken der Daten fehlerhaft!");
|
console.log("Abschicken der Daten fehlerhaft!");
|
||||||
}
|
}
|
||||||
@ -36,7 +39,7 @@ document.getElementById('btnLogin').addEventListener("click" , async (event) =>
|
|||||||
// if (document.getElementById('btnLogin') === "Login") {
|
// if (document.getElementById('btnLogin') === "Login") {
|
||||||
const formData = new FormData(document.getElementById('login-form'));
|
const formData = new FormData(document.getElementById('login-form'));
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const response = await fetch('php/signup.php', {
|
const response = await fetch('php/signup.php', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
body: formData
|
body: formData
|
||||||
@ -47,23 +50,26 @@ document.getElementById('btnLogin').addEventListener("click" , async (event) =>
|
|||||||
document.getElementById('login-status').innerHTML = jsonData.error.fontcolor("red");
|
document.getElementById('login-status').innerHTML = jsonData.error.fontcolor("red");
|
||||||
} else {
|
} else {
|
||||||
console.log(jsonData);
|
console.log(jsonData);
|
||||||
if (jsonData == 'true') {
|
document.getElementById('login-status').innerHTML = "Eingeloggt";
|
||||||
document.getElementById('toggle-login').innerHTML = "Logout";
|
location.replace('index2.htm');
|
||||||
document.getElementById('btnLogin').innerHTML = "Logout";
|
// if (jsonData == 'true') {
|
||||||
document.getElementById('exampleModalLabel').innerHTML = "Logout";
|
// document.getElementById('toggle-login').innerHTML = "Logout";
|
||||||
document.getElementById('login-status').innerHTML = "Erfolgreich eingeloggt";
|
// document.getElementById('btnLogin').innerHTML = "Logout";
|
||||||
}
|
// document.getElementById('exampleModalLabel').innerHTML = "Logout";
|
||||||
else {
|
// document.getElementById('login-status').innerHTML = "Erfolgreich eingeloggt";
|
||||||
document.getElementById('toggle-login').innerHTML = "Login";
|
// }
|
||||||
document.getElementById('btnLogin').innerHTML = "Login";
|
// else {
|
||||||
document.getElementById('exampleModalLabel').innerHTML = "Login";
|
// document.getElementById('toggle-login').innerHTML = "Login";
|
||||||
document.getElementById('login-status').innerHTML = "Erfolgreich ausgeloggt";
|
// document.getElementById('btnLogin').innerHTML = "Login";
|
||||||
}
|
// document.getElementById('exampleModalLabel').innerHTML = "Login";
|
||||||
|
// document.getElementById('login-status').innerHTML = "Erfolgreich ausgeloggt";
|
||||||
|
// }
|
||||||
// location.reload();
|
// location.reload();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
// }
|
||||||
console.log("Login Fehler");
|
// catch (e) {
|
||||||
}
|
// console.log("Login Fehler");
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -6,11 +6,21 @@
|
|||||||
$pswd = ($_POST['registerPassword']);
|
$pswd = ($_POST['registerPassword']);
|
||||||
$email = ($_POST['registerMail']);
|
$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 = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)");
|
||||||
$stmt->bind_param("sss", $name, $email, $pswd);
|
$stmt->bind_param("sss", $name, $email, $pswd);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
// }
|
echo json_encode("Dein Account wurde erfolgreich erstellt!");
|
||||||
|
} else {
|
||||||
|
echo json_encode("Der Benutzername ist leider schon vergeben!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,36 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
//<!--Login-->
|
//<!--Login-->
|
||||||
|
session_start();
|
||||||
require('../dbConnect.php');
|
require('../dbConnect.php');
|
||||||
|
|
||||||
|
|
||||||
$name = ($_POST['loginName']);
|
$name = ($_POST['loginName']);
|
||||||
$pswd = ($_POST['loginPassword']);
|
$pswd = ($_POST['loginPassword']);
|
||||||
|
// $pswd = md5($pswd);
|
||||||
|
|
||||||
try {
|
$stmt = $database->prepare("SELECT id FROM user WHERE '$name'=user AND password='$pswd'");
|
||||||
$stmt = $database->prepare("SELECT password FROM user WHERE '$name'=user");
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
$row = $result->fetch_assoc();
|
|
||||||
} catch (PDOException $e) {
|
if ($result->num_rows == 1) {
|
||||||
$e->getMessage();
|
$object = $result->fetch_object();
|
||||||
}
|
$_SESSION['user'] = $object->id;
|
||||||
if ($pswd == $row['password']) {
|
// header('Location: /index2.htm');
|
||||||
$stmt = $database->prepare("SELECT loggedin FROM user WHERE '$name'=user");
|
echo json_encode('Eingeloggt!');
|
||||||
$stmt->execute();
|
// $stmt = $database->prepare("SELECT loggedin FROM user WHERE '$name'=user");
|
||||||
$result = $stmt->get_result()->fetch_assoc();
|
// $stmt->execute();
|
||||||
if ($result['loggedin'] == 'false') {
|
// $result = $stmt->get_result()->fetch_assoc();
|
||||||
$stmt = $database->prepare("UPDATE `benutzer`.`user` SET `loggedin`='true' WHERE '$name'=user");
|
// if ($result['loggedin'] == 'false') {
|
||||||
$stmt->execute();
|
// $stmt = $database->prepare("UPDATE `benutzer`.`user` SET `loggedin`='true' WHERE '$name'=user");
|
||||||
$a = "true";
|
// $stmt->execute();
|
||||||
|
// $a = "true";
|
||||||
} else {
|
} else {
|
||||||
$stmt = $database->prepare("UPDATE `benutzer`.`user` SET `loggedin`='false' WHERE '$name'=user");
|
$a = array('error' => 'Einlogen fehlgeschlagen!');
|
||||||
$stmt->execute();
|
echo json_encode($a);
|
||||||
$a = "false";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode($a);
|
|
||||||
} else {
|
|
||||||
$a = array('error' => 'Einlogen fehlgeschlagen!' . $pswd . " " . $row['password']);
|
|
||||||
echo json_encode($a);
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user