made login synchronous
Wegen des async aufrufs des login php scripts konnte die session nicht richtig gesetzt werden, deshalb ist der login jetzt syncron. Die Registrierung ist weiterhin asyncron.
This commit is contained in:
parent
4cdc7dd21e
commit
359e30d7a4
11
index.php
11
index.php
@ -1,4 +1,8 @@
|
|||||||
<?php session_start(); ?>
|
<?php
|
||||||
|
if(!isset($_SESSION)){
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -15,10 +19,13 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<!-- Include the header-->
|
<!-- Include the header-->
|
||||||
<?php include('segments/_header.html'); ?>
|
<?php include('segments/_header.php'); ?>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<button id="btnCreateTan" type="button" class="btn btn-info">Erstelle Tan</button>
|
<button id="btnCreateTan" type="button" class="btn btn-info">Erstelle Tan</button>
|
||||||
|
<br><span> Session User: <?php echo $_SESSION['user']; ?> </span>
|
||||||
|
<button type="button" class="btn btn-info">Logout</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Zum testen der Daten die ueber die Modals reinkommen -->
|
<!-- Zum testen der Daten die ueber die Modals reinkommen -->
|
||||||
|
@ -21,7 +21,7 @@ async function getNewUniqueLink() {
|
|||||||
document.getElementById('btnCreate').addEventListener("click" , async (event) => {
|
document.getElementById('btnCreate').addEventListener("click" , async (event) => {
|
||||||
const formData = new FormData(document.getElementById('create-form'));
|
const formData = new FormData(document.getElementById('create-form'));
|
||||||
try {
|
try {
|
||||||
const response = await fetch('php/signin.php', {
|
const response = await fetch('php/signup.php', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
@ -32,44 +32,3 @@ document.getElementById('btnCreate').addEventListener("click" , async (event) =>
|
|||||||
console.log("Abschicken der Daten fehlerhaft!");
|
console.log("Abschicken der Daten fehlerhaft!");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
//<!--Login-->
|
|
||||||
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");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
})
|
|
||||||
|
@ -1,26 +1,37 @@
|
|||||||
<?php
|
<?php
|
||||||
//<!--Register-->
|
//<!--Login-->
|
||||||
require('../dbConnect.php');
|
if(isset($_POST['login-form'])){
|
||||||
|
session_start();
|
||||||
$name = ($_POST['registerName']);
|
require('dbConnect.php');
|
||||||
$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!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
$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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
@ -1,33 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
//<!--Login-->
|
//<!--Register-->
|
||||||
session_start();
|
|
||||||
require('../dbConnect.php');
|
require('../dbConnect.php');
|
||||||
|
|
||||||
|
$name = ($_POST['registerName']);
|
||||||
|
$pswd = ($_POST['registerPassword']);
|
||||||
|
$email = ($_POST['registerMail']);
|
||||||
|
|
||||||
$name = ($_POST['loginName']);
|
$search_user = $database->prepare("SELECT ID FROM user WHERE user='$name '");
|
||||||
$pswd = ($_POST['loginPassword']);
|
$search_user->execute();
|
||||||
// $pswd = md5($pswd);
|
$search_result = $search_user->get_result();
|
||||||
|
|
||||||
$stmt = $database->prepare("SELECT id FROM user WHERE '$name'=user AND password='$pswd'");
|
if ($search_result->num_rows == 0) {
|
||||||
$stmt->execute();
|
$pswd = md5($pswd);
|
||||||
$result = $stmt->get_result();
|
$stmt = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)");
|
||||||
|
$stmt->bind_param("sss", $name, $email, $pswd);
|
||||||
if ($result->num_rows == 1) {
|
$stmt->execute();
|
||||||
$object = $result->fetch_object();
|
$stmt->close();
|
||||||
$_SESSION['user'] = $object->id;
|
echo json_encode("Dein Account wurde erfolgreich erstellt!");
|
||||||
// header('Location: /index2.htm');
|
} else {
|
||||||
echo json_encode('Eingeloggt!');
|
echo json_encode("Der Benutzername ist leider schon vergeben!");
|
||||||
// $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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
?>
|
||||||
|
@ -49,6 +49,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<!-- Modal login-->
|
<!-- Modal login-->
|
||||||
|
<?php require("php/signin.php") ?>
|
||||||
|
|
||||||
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
@ -118,7 +120,7 @@
|
|||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text" id="inputGroup-sizing-sm">EmailAdress</span>
|
<span class="input-group-text" id="inputGroup-sizing-sm">EmailAdress</span>
|
||||||
</div>
|
</div>
|
||||||
<input type="password" class="form-control" name="registerMail" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
|
<input type="text" class="form-control" name="registerMail" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
|
||||||
</div>
|
</div>
|
||||||
╭∩╮(ಠಠ)╭∩╮
|
╭∩╮(ಠಠ)╭∩╮
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user