<?php
header("Content-Type: application/json");
	require('dbcon.php');
   
$data = json_decode(file_get_contents("php://input"), true);
$rawInput = file_get_contents("php://input");

file_put_contents("log.txt", $rawInput . PHP_EOL, FILE_APPEND);
if (isset($data['emailOrPhone'])) {
    $emailOrPhone = $data['emailOrPhone'];
} else {
    $emailOrPhone = '';
}


if (!$emailOrPhone) {
  echo json_encode(["success" => false, "message" => "No identifier given"]);
  exit;
}

// Example: get user from DB
$stmt = $pdo->prepare("SELECT *FROM users WHERE email = '$emailOrPhone' OR phone = '$emailOrPhone'");
$stmt->execute([$emailOrPhone, $emailOrPhone]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

if ($user) {
  echo json_encode(["success" => true, "user" => $user]);
} else {
  echo json_encode(["success" => false, "message" => "User not found"]);
}
?>