42 lines
1.4 KiB
PHP
Executable File
42 lines
1.4 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
|
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
|
require_once __DIR__ . '/../../../shared/database/connection.php';
|
|
|
|
// Verificar autenticación
|
|
$userData = JWTAuth::authenticate();
|
|
if (!$userData) {
|
|
jsonResponse(['success' => false, 'error' => 'No autenticado'], 401);
|
|
}
|
|
|
|
// Verificar permiso
|
|
if (!hasPermission('manage_recipients', 'discord')) {
|
|
jsonResponse(['success' => false, 'error' => 'No tienes permiso para crear destinatarios de Discord.'], 403);
|
|
}
|
|
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$nombre = trim($input['nombre'] ?? '');
|
|
$discord_id = trim($input['discord_id'] ?? '');
|
|
$tipo = trim($input['tipo'] ?? 'canal');
|
|
|
|
if (empty($nombre) || empty($discord_id)) {
|
|
jsonResponse(['success' => false, 'error' => 'Faltan datos'], 400);
|
|
}
|
|
|
|
try {
|
|
$db = getDB();
|
|
$stmt = $db->prepare("
|
|
INSERT INTO destinatarios_discord (nombre, discord_id, tipo, activo)
|
|
VALUES (?, ?, ?, 1)
|
|
");
|
|
$stmt->execute([$nombre, $discord_id, $tipo]);
|
|
|
|
jsonResponse(['success' => true]);
|
|
} catch (PDOException $e) {
|
|
if ($e->getCode() == 23000) {
|
|
jsonResponse(['success' => false, 'error' => 'Este ID de Discord ya está registrado'], 409);
|
|
}
|
|
jsonResponse(['success' => false, 'error' => $e->getMessage()], 500);
|
|
}
|