x
This commit is contained in:
@@ -23,74 +23,64 @@ loadEnv();
|
|||||||
|
|
||||||
|
|
||||||
function enviar() {
|
function enviar() {
|
||||||
// Validar reCAPTCHA
|
// Validar reCAPTCHA
|
||||||
$captchaResponse = $_POST['g-recaptcha-response'] ?? '';
|
$captchaResponse = $_POST['g-recaptcha-response'] ?? '';
|
||||||
|
|
||||||
if (!$captchaResponse) {
|
if (!$captchaResponse) {
|
||||||
die("❌ Debes completar el reCAPTCHA.");
|
die("❌ Debes completar el reCAPTCHA.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$secretKey = $_ENV['RECAPTCHA_SECRET'];
|
$secretKey = $_ENV['RECAPTCHA_SECRET'];
|
||||||
|
|
||||||
$verifyUrl = "https://www.google.com/recaptcha/api/siteverify";
|
$verifyUrl = "https://www.google.com/recaptcha/api/siteverify";
|
||||||
$data = [
|
$data = [
|
||||||
'secret' => $secretKey,
|
'secret' => $secretKey,
|
||||||
'response' => $captchaResponse
|
'response' => $captchaResponse
|
||||||
];
|
];
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'http' => [
|
'http' => [
|
||||||
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'content' => http_build_query($data)
|
'content' => http_build_query($data)
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$context = stream_context_create($options);
|
|
||||||
$result = file_get_contents($verifyUrl, false, $context);
|
|
||||||
$response = json_decode($result);
|
|
||||||
|
|
||||||
if (!$response->success) {
|
$context = stream_context_create($options);
|
||||||
die("❌ Error de verificación reCAPTCHA.");
|
$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'] ?? '');
|
// Validar RFC (12 o 13 caracteres con formato correcto)
|
||||||
$rfc = encrypt($_POST['rfc'] ?? '');
|
if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/', strtoupper($_POST['rfc'] ?? ''))) {
|
||||||
$email = $_POST['email'] ?? '';
|
die("❌ El RFC no tiene un formato válido.");
|
||||||
$telefono = $_POST['phone'] ?? '';
|
}
|
||||||
$archivo = $_FILES['opinion_file'];
|
|
||||||
|
|
||||||
// Validar RFC
|
// Validar email (solo minúsculas, sin caracteres especiales fuera del estándar)
|
||||||
if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/i', $_POST['rfc'] ?? '')) {
|
if (!preg_match('/^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/', $email)) {
|
||||||
die("RFC inválido. Debe seguir el formato oficial.");
|
die("❌ No es una dirección de correo válida.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validar el Email (minúsculas + dominio @empresa.com)
|
// Validar teléfono (formato nacional: 3 dígitos + espacio + 7 dígitos)
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) {
|
||||||
die("No es una dirección de correo válida.");
|
die("❌ El número de teléfono no tiene un formato válido. Ejemplo: 123 4567890");
|
||||||
}
|
}
|
||||||
if (!preg_match('/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/', $email)) {
|
|
||||||
die("No es una dirección de correo.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validar el Teléfono: debe tener formato 3 dígitos + espacio + 7 dígitos
|
// Validar archivo
|
||||||
if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) {
|
if ($archivo['error'] !== 0 || pathinfo($archivo['name'], PATHINFO_EXTENSION) !== 'pdf') {
|
||||||
die("El teléfono debe tener el formato 3 dígitos, espacio, 7 dígitos (ej. 123 4567890).");
|
die("❌ Archivo inválido. Solo se permiten PDFs.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Guardar archivo
|
// Guardar archivo
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title><?= htmlspecialchars($siglas) ?> | Registro de Importador</title>
|
<title><?= htmlspecialchars($siglas) ?> | Registro de Importador</title>
|
||||||
@@ -67,7 +68,8 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-control, .form-select {
|
.form-control,
|
||||||
|
.form-select {
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +91,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<!-- Navbar institucional -->
|
<!-- Navbar institucional -->
|
||||||
@@ -119,7 +122,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
|
|
||||||
<!-- Contenedor del formulario -->
|
<!-- Contenedor del formulario -->
|
||||||
<div class="container card-form">
|
<div class="container card-form">
|
||||||
|
|
||||||
|
|
||||||
<form action="/IMPORTADORES/registro/enviar" method="POST" enctype="multipart/form-data" id="formRegistro">
|
<form action="/IMPORTADORES/registro/enviar" method="POST" enctype="multipart/form-data" id="formRegistro">
|
||||||
<div class="row g-3">
|
<div class="row g-3">
|
||||||
@@ -157,86 +160,73 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
|
||||||
document.getElementById("formRegistro").addEventListener("submit", function(event) {
|
|
||||||
const rfcInput = document.querySelector('input[name="rfc"]');
|
|
||||||
const emailInput = document.querySelector('input[name="email"]');
|
|
||||||
const phoneInput = document.querySelector('input[name="phone"]');
|
|
||||||
|
|
||||||
const rfc = rfcInput.value.toUpperCase();
|
|
||||||
const email = emailInput.value.trim();
|
|
||||||
const phone = phoneInput.value.trim();
|
|
||||||
|
|
||||||
// Validación RFC
|
|
||||||
const rfcRegex = /^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/;
|
|
||||||
if (!rfcRegex.test(rfc)) {
|
|
||||||
alert("RFC inválido. Asegúrate de que siga el formato correcto.");
|
|
||||||
rfcInput.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
rfcInput.value = rfc; // Convertir a mayúsculas
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validación correo - solo minúsculas y con cualquier dominio
|
|
||||||
const correoRegex = /^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
|
|
||||||
if (!correoRegex.test(email)) {
|
|
||||||
e.preventDefault(); // Detiene el envío del formulario
|
|
||||||
alert("No es una dirección de correo válida (solo minúsculas, sin acentos ni caracteres especiales).");
|
|
||||||
emailInput.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validación teléfono
|
|
||||||
const phoneRegex = /^\d{3}\s\d{7}$/;
|
|
||||||
if (!phoneRegex.test(phone)) {
|
|
||||||
alert("El teléfono debe tener el formato 3 dígitos, espacio, 7 dígitos (ej. 123 4567890)");
|
|
||||||
phoneInput.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validación de solo números sin espacios para verificación
|
|
||||||
const digitsOnly = phone.replace(/\s/g, "");
|
|
||||||
if (digitsOnly.length !== 10 || isNaN(digitsOnly)) {
|
|
||||||
alert("El teléfono debe contener exactamente 10 dígitos numéricos.");
|
|
||||||
phoneInput.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="container ">
|
<div class="container ">
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
Una vez que envíes tu solicitud, será revisada manualmente por la agencia aduanal.
|
Una vez que envíes tu solicitud, será revisada manualmente por la agencia aduanal.
|
||||||
Recibirás una notificación por correo electrónico cuando tu registro sea aprobado, junto con las instrucciones para activar tu cuenta e iniciar sesión en la plataforma.
|
Recibirás una notificación por correo electrónico cuando tu registro sea aprobado, junto con las instrucciones para activar tu cuenta e iniciar sesión en la plataforma.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- FOOTER -->
|
<!-- FOOTER -->
|
||||||
<footer class="fixed-bottom">
|
<footer class="fixed-bottom">
|
||||||
© <?= date('Y') ?> <?= htmlspecialchars($siglas) ?> · <?= htmlspecialchars($nombre) ?>
|
© <?= date('Y') ?> <?= htmlspecialchars($siglas) ?> · <?= htmlspecialchars($nombre) ?>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
|
||||||
<!-- Validación JS -->
|
<!-- Validación JS -->
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('formRegistro').addEventListener('submit', function (e) {
|
document.getElementById('formRegistro').addEventListener('submit', function(e) {
|
||||||
|
const rfcInput = document.querySelector('input[name="rfc"]');
|
||||||
|
const emailInput = document.querySelector('input[name="email"]');
|
||||||
|
const phoneInput = document.querySelector('input[name="phone"]');
|
||||||
const archivo = document.getElementById('opinion_file').files[0];
|
const archivo = document.getElementById('opinion_file').files[0];
|
||||||
const recaptcha = grecaptcha.getResponse();
|
const recaptcha = grecaptcha.getResponse();
|
||||||
|
|
||||||
|
const rfc = rfcInput.value.trim().toUpperCase();
|
||||||
|
const email = emailInput.value.trim();
|
||||||
|
const phone = phoneInput.value.trim();
|
||||||
|
|
||||||
|
// Expresiones regulares
|
||||||
|
const correoRegex = /^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
|
||||||
|
const rfcRegex = /^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/;
|
||||||
|
const telefonoRegex = /^\d{3}\s\d{7}$/;
|
||||||
|
|
||||||
|
// Validación de correo
|
||||||
|
if (!correoRegex.test(email)) {
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire("Correo inválido", "No es una dirección de correo válida. Solo se permiten minúsculas.", "error");
|
||||||
|
emailInput.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación de RFC
|
||||||
|
if (!rfcRegex.test(rfc)) {
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire("RFC inválido", "El RFC debe tener 12 o 13 caracteres con el formato correcto (ej. ABC123456XYZ).", "error");
|
||||||
|
rfcInput.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación de teléfono
|
||||||
|
if (!telefonoRegex.test(phone)) {
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire("Teléfono inválido", "Debe tener 10 dígitos en el formato: 3 dígitos (LADA), espacio, y 7 dígitos. Ejemplo: 123 4567890", "error");
|
||||||
|
phoneInput.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación de archivo PDF
|
||||||
if (!archivo || archivo.type !== 'application/pdf') {
|
if (!archivo || archivo.type !== 'application/pdf') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Swal.fire("Error", "Solo se permite subir archivos PDF.", "error");
|
Swal.fire("Error", "Solo se permite subir archivos PDF.", "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validación de reCAPTCHA
|
||||||
if (recaptcha.length === 0) {
|
if (recaptcha.length === 0) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Swal.fire("Verificación requerida", "Por favor completa el reCAPTCHA.", "warning");
|
Swal.fire("Verificación requerida", "Por favor completa el reCAPTCHA.", "warning");
|
||||||
@@ -246,4 +236,5 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user