This commit is contained in:
the_kellner 2018-06-11 18:18:17 +02:00
commit 4e34f8180c
6 changed files with 110 additions and 26 deletions

View File

@ -16,3 +16,54 @@ async function getNewUniqueLink() {
}
}
//<!--Register-->
document.getElementById('btnCreate').addEventListener("click" , async (event) => {
const formData = new FormData(document.getElementById('create-form'));
try {
const response = await fetch('php/signin.php', {
method: 'post',
body: formData
});
} catch (e) {
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);
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");
}
// }
})

View File

@ -1,22 +0,0 @@
<?php
require('../dbConnect.php');
$name = $database->real_escape_string($_POST['registerName']);
$pswd = $database->real_escape_string($_POST['registerPassword']);
$email = $database->real_escape_string($_POST['registerMail']);
$abfrage = "SELECT password WHERE $name=user";
if ($pswd == $abfrage) {
// code..
echo "HI";
}
// if ($abfrage == "") {
$stmt = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)");
$stmt->bind_param("sss", $name, $email, $pswd);
$stmt->execute();
$stmt->close();
// }
?>

16
php/signin.php Normal file
View File

@ -0,0 +1,16 @@
<?php
//<!--Register-->
require('../dbConnect.php');
$name = ($_POST['registerName']);
$pswd = ($_POST['registerPassword']);
$email = ($_POST['registerMail']);
// if ($abfrage == "") {
$stmt = $database->prepare("INSERT INTO user(user, email, password) VALUES (?,?,?)");
$stmt->bind_param("sss", $name, $email, $pswd);
$stmt->execute();
$stmt->close();
// }
?>

36
php/signup.php Normal file
View File

@ -0,0 +1,36 @@
<?php
//<!--Login-->
require('../dbConnect.php');
$name = ($_POST['loginName']);
$pswd = ($_POST['loginPassword']);
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";
} else {
$stmt = $database->prepare("UPDATE `benutzer`.`user` SET `loggedin`='false' WHERE '$name'=user");
$stmt->execute();
$a = "false";
}
echo json_encode($a);
} else {
$a = array('error' => 'Einlogen fehlgeschlagen!' . $pswd . " " . $row['password']);
echo json_encode($a);
}
?>

View File

@ -219,7 +219,7 @@ function consumeTan($tanID) {
<button id="btnAbsenden" type="submit" class="btn btn-primary">Absenden</button>
</div>
</fo+rm>
</form>
</div>
</div>
</div> <!-- Ende container entry form -->

View File

@ -36,7 +36,7 @@
<form class="form-inline my-2 my-lg-0">
<div class="btn-group" role="group" aria-label="Basic example">
<!-- Button trigger modal Login -->
<button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#login">
<button id="toggle-login" type="button" class="btn btn-secondary" data-toggle="modal" data-target="#login">
Login
</button>
@ -75,10 +75,13 @@
</div>
<input type="password" class="form-control" name="loginPassword" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
</div>
<div id="login-status">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button id="login" type="submit" class="btn btn-primary">Login</button>
<button id="btnLogin" type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
@ -121,7 +124,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button id="create" type="submit" class="btn btn-primary">Create Account</button>
<button id="btnCreate" type="submit" class="btn btn-primary">Create Account</button>
</div>
</form>
</div>