integrated EVERYTHING!

This commit is contained in:
StockiP
2022-05-12 18:48:58 +02:00
parent 8e91e4a8f6
commit f1185ade0c
18 changed files with 424 additions and 27 deletions

45
logic/loginLogic.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/config/sessionStart.php');
include($_SERVER['DOCUMENT_ROOT'] . '/logic/testinput.php');
$data = json_decode(file_get_contents('php://input'));
$username = testinput($data->email);
$passwordUnhashed = testinput($data->password);
loginUser($username, $passwordUnhashed);
function loginUser($username, $passwordUnhashed)
{
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
$sql = "SELECT `username`, `password`, `role` FROM `user` WHERE `username` = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($username, $password, $role);
if ($stmt->num_rows == 1) {
$stmt->fetch();
if (password_verify($passwordUnhashed, $password)) {
$response = "success";
$_SESSION['username'] = $username;
$_SESSION['role'] = $role;
$_SESSION['loggedIn'] = true;
} else {
$response = "failure";
}
} else {
$response = "failure";
}
$stmt->close();
$db->close();
echo $response;
}
?>