<?php

// Function to check if the email and password match the data in the JSON file
function checkLogin($email, $password) {
    // Path to the JSON file
    $loginDataPath = '../../database/login/login.json';

    // Check if the file exists
    if (!file_exists($loginDataPath)) {
        return json_encode(array('message' => 'Login data not found.'));
    }

    // Read the JSON file
    $loginData = file_get_contents($loginDataPath);

    // Decode the JSON data into a PHP array
    $loginDataArray = json_decode($loginData, true);

    // Check if email and password match
    if ($email === $loginDataArray['login_email'] && $password === $loginDataArray['password']) {
        return json_encode(array('message' => 'Login successful!'));
    } else {
        return json_encode(array('message' => 'Invalid email or password.'));
    }
}

// Get email and password from the POST request (assuming these are sent as JSON)
$requestData = json_decode(file_get_contents('php://input'), true);

// Check if email and password are provided
if (isset($requestData['email']) && isset($requestData['password'])) {
    // Call the checkLogin function
    echo checkLogin($requestData['email'], $requestData['password']);
} else {
    echo json_encode(array('message' => 'Please provide both email and password.'));
}

?>
