Commit e39e7760 authored by Arnolds's avatar Arnolds
Browse files

Validated presence of required fields in secret-api.php and adjusted...

Validated presence of required fields in secret-api.php and adjusted conditionals for clearer request handling.
parent 4ef86b21
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -30,9 +30,9 @@ $collection = $db->secrets;

$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'POST') {
if ($method === 'POST' && isset($_POST['secret'])) {
    $data = json_decode(file_get_contents('php://input'), true);
    if (!isset($data['secret'])) {
    if ($data['secret']) {
        http_response_code(400);
        echo json_encode(['error' => '<p class="mb-0">Hmm... noslēpuma lauciņš ir tukšs. Bez tā šī ir tikai "Glabātuve", nevis "Noslēpumu glabātuve" 😅.</p>']);
        exit;
@@ -65,7 +65,7 @@ if ($method === 'POST') {

    echo json_encode(['id' => $id]);

} else if ($method === 'GET') {
} else if ($method === 'POST' && isset($_GET['retrieve'])) {
    $id = $_GET['id'] ?? null;
    if (!$id) {
        http_response_code(400);