From e56f1dd371611d9da4a810d06d2ca8a73793c81a Mon Sep 17 00:00:00 2001 From: Alexeer Date: Tue, 6 May 2025 15:31:13 -0600 Subject: [PATCH] x --- app/controllers/registro.php | 102 +++++++++++++++----------------- views/registro/form.php | 111 ++++++++++++++++------------------- 2 files changed, 97 insertions(+), 116 deletions(-) diff --git a/app/controllers/registro.php b/app/controllers/registro.php index ac4be81..dda825f 100644 --- a/app/controllers/registro.php +++ b/app/controllers/registro.php @@ -23,74 +23,64 @@ loadEnv(); function enviar() { - // Validar reCAPTCHA - $captchaResponse = $_POST['g-recaptcha-response'] ?? ''; + // Validar reCAPTCHA + $captchaResponse = $_POST['g-recaptcha-response'] ?? ''; - if (!$captchaResponse) { - die("❌ Debes completar el reCAPTCHA."); - } + if (!$captchaResponse) { + die("❌ Debes completar el reCAPTCHA."); + } - $secretKey = $_ENV['RECAPTCHA_SECRET']; + $secretKey = $_ENV['RECAPTCHA_SECRET']; - $verifyUrl = "https://www.google.com/recaptcha/api/siteverify"; - $data = [ - 'secret' => $secretKey, - 'response' => $captchaResponse - ]; + $verifyUrl = "https://www.google.com/recaptcha/api/siteverify"; + $data = [ + 'secret' => $secretKey, + 'response' => $captchaResponse + ]; - $options = [ - 'http' => [ - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", - 'method' => 'POST', - 'content' => http_build_query($data) - ] - ]; - $context = stream_context_create($options); - $result = file_get_contents($verifyUrl, false, $context); - $response = json_decode($result); + $options = [ + 'http' => [ + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => http_build_query($data) + ] + ]; - if (!$response->success) { - die("❌ Error de verificación reCAPTCHA."); - } + $context = stream_context_create($options); + $result = file_get_contents($verifyUrl, false, $context); + $response = json_decode($result); + if (!$response->success) { + die("❌ Error de verificación reCAPTCHA."); + } + $conn = getConnection(); - $conn = getConnection(); + $empresa = encrypt(trim($_POST['company_name'] ?? '')); + $rfc = strtoupper(encrypt(trim($_POST['rfc'] ?? ''))); + $email = trim($_POST['email'] ?? ''); + $telefono = trim($_POST['phone'] ?? ''); + $archivo = $_FILES['opinion_file']; - $empresa = encrypt($_POST['company_name'] ?? ''); - $rfc = encrypt($_POST['rfc'] ?? ''); - $email = $_POST['email'] ?? ''; - $telefono = $_POST['phone'] ?? ''; - $archivo = $_FILES['opinion_file']; + // Validar RFC (12 o 13 caracteres con formato correcto) + if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/', strtoupper($_POST['rfc'] ?? ''))) { + die("❌ El RFC no tiene un formato válido."); + } - // Validar RFC - if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/i', $_POST['rfc'] ?? '')) { - die("RFC inválido. Debe seguir el formato oficial."); - } + // Validar email (solo minúsculas, sin caracteres especiales fuera del estándar) + if (!preg_match('/^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/', $email)) { + die("❌ No es una dirección de correo válida."); + } - // Validar el Email (minúsculas + dominio @empresa.com) - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { - die("No es una dirección de correo válida."); - } - if (!preg_match('/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/', $email)) { - die("No es una dirección de correo."); - } + // Validar teléfono (formato nacional: 3 dígitos + espacio + 7 dígitos) + if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) { + die("❌ El número de teléfono no tiene un formato válido. Ejemplo: 123 4567890"); + } - // Validar el Teléfono: debe tener formato 3 dígitos + espacio + 7 dígitos - if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) { - die("El teléfono debe tener el formato 3 dígitos, espacio, 7 dígitos (ej. 123 4567890)."); - } - - // También podemos validar que tenga exactamente 10 dígitos sin espacios - $soloDigitos = str_replace(' ', '', $telefono); - if (!ctype_digit($soloDigitos) || strlen($soloDigitos) !== 10) { - die("El teléfono debe contener exactamente 10 dígitos numéricos."); - } - - // Validar archivo - if ($archivo['error'] !== 0 || pathinfo($archivo['name'], PATHINFO_EXTENSION) !== 'pdf') { - die("Archivo inválido. Solo se permiten PDFs."); - } + // Validar archivo + if ($archivo['error'] !== 0 || pathinfo($archivo['name'], PATHINFO_EXTENSION) !== 'pdf') { + die("❌ Archivo inválido. Solo se permiten PDFs."); + } // Guardar archivo diff --git a/views/registro/form.php b/views/registro/form.php index 921980c..17ad415 100644 --- a/views/registro/form.php +++ b/views/registro/form.php @@ -18,6 +18,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5') ?> + <?= htmlspecialchars($siglas) ?> | Registro de Importador @@ -67,7 +68,8 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5') font-weight: 500; } - .form-control, .form-select { + .form-control, + .form-select { border-radius: 6px; } @@ -89,6 +91,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5') } + @@ -119,7 +122,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
- +
@@ -157,86 +160,73 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
- - - -
- - -