Actualizar crear-cita.html
This commit is contained in:
@@ -181,29 +181,62 @@
|
|||||||
<script>
|
<script>
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
// 🔧 CONFIGURACIÓN
|
// 🔧 CONFIGURACIÓN SAAS ESTRICTA
|
||||||
const API_URL = 'https://integrarepara-api.integrarepara.es';
|
const API_URL = 'https://integrarepara-api.integrarepara.es';
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const OWNER_ID = parseInt(urlParams.get('c')) || 1;
|
|
||||||
|
// 🚨 CAMBIO 1: Quitamos el "|| 1". Declaramos con 'let' para rescatarlo de la sesión si hace falta.
|
||||||
|
let OWNER_ID = parseInt(urlParams.get('c'));
|
||||||
|
|
||||||
let currentClient = null;
|
let currentClient = null;
|
||||||
|
|
||||||
// 🔄 INICIO: CARGAR DATOS Y SESIÓN
|
// 🔄 INICIO: CARGAR DATOS Y SESIÓN
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
loadCompanyData();
|
|
||||||
|
|
||||||
const sesionGuardada = localStorage.getItem('clienteSesion');
|
const sesionGuardada = localStorage.getItem('clienteSesion');
|
||||||
|
let datosSesion = null;
|
||||||
|
|
||||||
|
// 1. Revisamos si hay sesión y si está caducada
|
||||||
if (sesionGuardada) {
|
if (sesionGuardada) {
|
||||||
try {
|
try {
|
||||||
const datos = JSON.parse(sesionGuardada);
|
datosSesion = JSON.parse(sesionGuardada);
|
||||||
if (Date.now() < datos.expires) {
|
if (Date.now() < datosSesion.expires) {
|
||||||
document.getElementById('cliPhone').value = datos.phone;
|
// 🛡️ ESCUDO 1: Si el cliente borró el '?c=ID' de la URL pero tiene sesión guardada, lo rescatamos
|
||||||
prepareStep3(datos.client);
|
if (!OWNER_ID && datosSesion.owner_id) {
|
||||||
goToStep(3);
|
OWNER_ID = datosSesion.owner_id;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem('clienteSesion');
|
localStorage.removeItem('clienteSesion');
|
||||||
|
datosSesion = null;
|
||||||
}
|
}
|
||||||
} catch (e) { localStorage.removeItem('clienteSesion'); }
|
} catch (e) {
|
||||||
|
localStorage.removeItem('clienteSesion');
|
||||||
|
datosSesion = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🛑 ESCUDO 2: BLOQUEO TOTAL SI NO HAY EMPRESA (Ni en URL ni en sesión)
|
||||||
|
if (!OWNER_ID || isNaN(OWNER_ID)) {
|
||||||
|
// Borramos todo y mostramos el mensaje de error hermético
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<div class="min-h-screen w-full flex flex-col items-center justify-center p-8 text-center bg-slate-50">
|
||||||
|
<div class="w-24 h-24 bg-red-100 text-red-600 rounded-[2rem] flex items-center justify-center mb-6 shadow-xl shadow-red-100">
|
||||||
|
<i data-lucide="shield-alert" class="w-12 h-12"></i>
|
||||||
|
</div>
|
||||||
|
<h2 class="text-3xl font-black text-slate-800 mb-3 uppercase tracking-tighter">Acceso Denegado</h2>
|
||||||
|
<p class="text-slate-500 font-bold text-[10px] uppercase tracking-widest leading-relaxed">Falta la clave de la empresa.<br>Utiliza el enlace exacto que te proporcionó el servicio técnico.</p>
|
||||||
|
</div>`;
|
||||||
|
lucide.createIcons();
|
||||||
|
return; // ⛔ Cortamos la ejecución aquí. No hace NADA más.
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Si pasamos el escudo, cargamos los datos con total seguridad
|
||||||
|
loadCompanyData();
|
||||||
|
|
||||||
|
// 3. Si teníamos sesión activa, pre-cargamos el paso 3 (Como lo tenías tú)
|
||||||
|
if (datosSesion) {
|
||||||
|
document.getElementById('cliPhone').value = datosSesion.phone;
|
||||||
|
prepareStep3(datosSesion.client);
|
||||||
|
goToStep(3);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -296,8 +329,9 @@
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.ok) {
|
if (data.ok) {
|
||||||
const caducidad = Date.now() + (10 * 24 * 60 * 60 * 1000);
|
const caducidad = Date.now() + (10 * 24 * 60 * 60 * 1000);
|
||||||
|
// 🚨 CAMBIO 2: Guardamos 'owner_id' en la sesión para que funcione el Escudo 1
|
||||||
localStorage.setItem('clienteSesion', JSON.stringify({
|
localStorage.setItem('clienteSesion', JSON.stringify({
|
||||||
phone: phone, client: data.exists ? data.client : null, expires: caducidad
|
phone: phone, client: data.exists ? data.client : null, expires: caducidad, owner_id: OWNER_ID
|
||||||
}));
|
}));
|
||||||
prepareStep3(data.exists ? data.client : null);
|
prepareStep3(data.exists ? data.client : null);
|
||||||
goToStep(3);
|
goToStep(3);
|
||||||
|
|||||||
Reference in New Issue
Block a user