initial commit

This commit is contained in:
Sergey Svinolobov
2024-06-24 16:02:24 -04:00
parent eea090518d
commit 2ccb8f55fe
10 changed files with 681 additions and 1 deletions

35
auth.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$data = json_decode(file_get_contents('php://input'), true);
$username = $data['username'];
$password = $data['password'];
function authenticate($username, $password) {
$url = 'http://localhost:7000/auth';
$data = json_encode(array("username" => $username, "password" => $password));
$options = array(
'http' => array(
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => $data,
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);
return $response['authenticated'];
}
$isAuthenticated = authenticate($username, $password);
if ($isAuthenticated) {
$_SESSION['authenticated'] = true;
echo json_encode(['authenticated' => true]);
} else {
$_SESSION['authenticated'] = false;
echo json_encode(['authenticated' => false]);
}
?>