80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* API para eliminar un usuario
|
|
* Versión: 1.0
|
|
*/
|
|
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type, Authorization');
|
|
|
|
// Manejar preflight requests
|
|
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
|
exit(0);
|
|
}
|
|
|
|
try {
|
|
// Solo aceptar POST
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
throw new Exception('Método no permitido. Use POST.');
|
|
}
|
|
|
|
// Obtener datos del POST
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$user_id = isset($input['user_id']) ? intval($input['user_id']) : 0;
|
|
$debug = isset($_GET['debug']) && $_GET['debug'] === 'true';
|
|
|
|
if ($debug) {
|
|
error_log("=== DELETE USER DEBUG ===");
|
|
error_log("User ID: " . $user_id);
|
|
error_log("Input: " . json_encode($input));
|
|
}
|
|
|
|
// Validar parámetros
|
|
if ($user_id <= 0) {
|
|
throw new Exception('ID de usuario inválido');
|
|
}
|
|
|
|
// Por ahora, simular eliminación exitosa
|
|
// En el futuro, esto eliminaría el usuario de la base de datos
|
|
if ($debug) {
|
|
error_log("Simulando eliminación del usuario ID: " . $user_id);
|
|
}
|
|
|
|
// Simular un pequeño delay para realismo
|
|
usleep(500000); // 0.5 segundos
|
|
|
|
// Respuesta exitosa
|
|
$response = [
|
|
'success' => true,
|
|
'message' => 'Usuario eliminado correctamente',
|
|
'data' => [
|
|
'deleted_user_id' => $user_id,
|
|
'timestamp' => date('Y-m-d H:i:s')
|
|
],
|
|
'debug' => $debug ? [
|
|
'timestamp' => date('Y-m-d H:i:s'),
|
|
'simulated' => true,
|
|
'user_id' => $user_id
|
|
] : null
|
|
];
|
|
|
|
echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
|
|
} catch (Exception $e) {
|
|
$error_response = [
|
|
'success' => false,
|
|
'error' => $e->getMessage(),
|
|
'debug' => $debug ? [
|
|
'timestamp' => date('Y-m-d H:i:s'),
|
|
'file' => __FILE__,
|
|
'line' => $e->getLine(),
|
|
'trace' => $e->getTraceAsString()
|
|
] : null
|
|
];
|
|
|
|
http_response_code(500);
|
|
echo json_encode($error_response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
}
|
|
?>
|