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>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -15,10 +19,13 @@
|
||||
|
||||
<body>
|
||||
<!-- Include the header-->
|
||||
<?php include('segments/_header.html'); ?>
|
||||
<?php include('segments/_header.php'); ?>
|
||||
|
||||
<div id="content">
|
||||
<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>
|
||||
|
||||
<!-- Zum testen der Daten die ueber die Modals reinkommen -->
|
||||
|
@ -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!");
|
||||
}
|
||||
})
|
||||
|
||||
//<!--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
|
||||
//<!--Register-->
|
||||
require('../dbConnect.php');
|
||||
//<!--Login-->
|
||||
if(isset($_POST['login-form'])){
|
||||
session_start();
|
||||
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) {
|
||||
$name = ($_POST['loginName']);
|
||||
$pswd = ($_POST['loginPassword']);
|
||||
$pswd = md5($pswd);
|
||||
$stmt = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)");
|
||||
$stmt->bind_param("sss", $name, $email, $pswd);
|
||||
|
||||
$stmt = $database->prepare("SELECT id FROM user WHERE '$name'=user AND password='$pswd'");
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
echo json_encode("Dein Account wurde erfolgreich erstellt!");
|
||||
$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 {
|
||||
echo json_encode("Der Benutzername ist leider schon vergeben!");
|
||||
//$a = array('error' => 'Einlogen fehlgeschlagen!');
|
||||
//echo json_encode($a);
|
||||
echo "Einloggen fehlgeschlagen";
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
}
|
||||
?>
|
||||
|
@ -1,33 +1,26 @@
|
||||
<?php
|
||||
//<!--Login-->
|
||||
session_start();
|
||||
//<!--Register-->
|
||||
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'");
|
||||
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();
|
||||
$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";
|
||||
$stmt->close();
|
||||
echo json_encode("Dein Account wurde erfolgreich erstellt!");
|
||||
} else {
|
||||
$a = array('error' => 'Einlogen fehlgeschlagen!');
|
||||
echo json_encode($a);
|
||||
echo json_encode("Der Benutzername ist leider schon vergeben!");
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
?>
|
||||
|
@ -49,6 +49,8 @@
|
||||
</div>
|
||||
</nav>
|
||||
<!-- 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-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
@ -118,7 +120,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="inputGroup-sizing-sm">EmailAdress</span>
|
||||
</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>
|
Loading…
Reference in New Issue
Block a user