<?php
require "../api.php";

$api = new mcServApi();

if (!$api->checkAuth()) {
    die('{"status":500, "error:"Unauthorized"}');
}

$db = $api->getDB();

$sql = "SELECT * FROM users";
$stmt = $db->query($sql);

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

$users= [];

foreach($result as $user_res) {
    $user["name"] = $user_res["username"];
    $user["mail"] = $user_res["mail"];

    $users[] = $user;
}

$json["status"] = 200;
$json["users"] = $users;

echo json_encode($json);
?>