Actualizar pruebas-robot.html

This commit is contained in:
2026-03-05 22:28:03 +00:00
parent f075dc6b4a
commit 6c99c8e31e

View File

@@ -97,14 +97,27 @@
<div id="loginBlocker" class="fixed inset-0 bg-slate-900 z-[200] flex flex-col items-center justify-center text-white hidden"> <div id="loginBlocker" class="fixed inset-0 bg-slate-900 z-[200] flex flex-col items-center justify-center text-white hidden">
<i data-lucide="lock" class="w-16 h-16 text-rose-500 mb-4"></i> <i data-lucide="lock" class="w-16 h-16 text-rose-500 mb-4"></i>
<h2 class="text-2xl font-black tracking-tight mb-2">Acceso Denegado</h2> <h2 class="text-2xl font-black tracking-tight mb-2">Laboratorio Bloqueado</h2>
<p class="text-slate-400 mb-6 text-center max-w-md">No se detecta ninguna sesión activa. Debes iniciar sesión en la plataforma principal para obtener permisos de seguridad.</p> <p class="text-slate-400 mb-8 text-center max-w-md">Para realizar pruebas en el robot necesitas iniciar sesión con tu cuenta de administrador.</p>
<a href="index.html" class="bg-blue-600 hover:bg-blue-500 px-6 py-3 rounded-xl font-bold uppercase tracking-widest text-xs transition-colors">Ir al Login</a>
<form onsubmit="loginLab(event)" class="bg-slate-800 p-8 rounded-3xl w-full max-w-sm space-y-5 shadow-2xl border border-slate-700">
<div>
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 ml-1">Email o Teléfono</label>
<input type="text" id="labEmail" class="w-full bg-slate-900 border border-slate-700 px-4 py-3 rounded-xl text-sm font-semibold text-white outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all" required>
</div>
<div>
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 ml-1">Contraseña</label>
<input type="password" id="labPass" class="w-full bg-slate-900 border border-slate-700 px-4 py-3 rounded-xl text-sm font-semibold text-white outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all" required>
</div>
<button type="submit" id="btnLabLogin" class="w-full bg-blue-600 hover:bg-blue-500 px-6 py-4 rounded-xl font-black uppercase tracking-widest text-xs transition-colors mt-2">
Desbloquear Laboratorio
</button>
</form>
</div> </div>
<script> <script>
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' || window.location.protocol === 'file:'
? 'http://localhost:3000' ? 'https://integrarepara-api.integrarepara.es' // Forzamos que siempre apunte al servidor real si estás en tu PC
: 'https://integrarepara-api.integrarepara.es'; : 'https://integrarepara-api.integrarepara.es';
let knownJobs = {}; let knownJobs = {};
@@ -119,17 +132,51 @@
return; return;
} }
// 2. COMPROBAR CREDENCIALES DE HOMESERVE EN LA BD // Si ya hay token, arrancamos directo
await checkHomeServeCredentials(token); startLab(token);
});
// 3. ARRANCAR EL MONITOR // Lógica para iniciar sesión directamente desde aquí
async function loginLab(e) {
e.preventDefault();
const btn = document.getElementById('btnLabLogin');
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin mx-auto"></i>';
lucide.createIcons();
try {
const res = await fetch(`${API_URL}/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: document.getElementById('labEmail').value,
password: document.getElementById('labPass').value
})
});
const data = await res.json();
if (data.ok) {
localStorage.setItem("token", data.token);
document.getElementById('loginBlocker').classList.add('hidden');
startLab(data.token);
} else {
alert(data.error || "Credenciales incorrectas.");
btn.innerHTML = 'Desbloquear Laboratorio';
}
} catch (err) {
alert("Error conectando con el servidor.");
btn.innerHTML = 'Desbloquear Laboratorio';
}
}
async function startLab(token) {
await checkHomeServeCredentials(token);
addLog("Conectado a la Base de Datos. Escuchando la cola...", "system"); addLog("Conectado a la Base de Datos. Escuchando la cola...", "system");
setInterval(fetchQueueStatus, 3000); setInterval(fetchQueueStatus, 3000);
fetchQueueStatus(); fetchQueueStatus();
}); }
// ===================================== // =====================================
// MAGIA: VERIFICAR CREDENCIALES // VERIFICAR CREDENCIALES
// ===================================== // =====================================
async function checkHomeServeCredentials(token) { async function checkHomeServeCredentials(token) {
try { try {
@@ -142,7 +189,6 @@
const btnLaunch = document.getElementById('btnLaunch'); const btnLaunch = document.getElementById('btnLaunch');
if (data.ok && data.credentials) { if (data.ok && data.credentials) {
// Buscamos si existe homeserve
const hsCreds = data.credentials.find(c => c.provider === 'homeserve'); const hsCreds = data.credentials.find(c => c.provider === 'homeserve');
if (hsCreds && hsCreds.status === 'active') { if (hsCreds && hsCreds.status === 'active') {
@@ -159,7 +205,7 @@
addLog("⚠️ ATENCIÓN: El robot no podrá funcionar porque no has configurado tu usuario y contraseña de HomeServe en la pestaña de Proveedores.", "warning"); addLog("⚠️ ATENCIÓN: El robot no podrá funcionar porque no has configurado tu usuario y contraseña de HomeServe en la pestaña de Proveedores.", "warning");
btnLaunch.disabled = false; // Le dejamos inyectar, pero le avisamos. btnLaunch.disabled = false;
btnLaunch.className = "w-full bg-rose-600 hover:bg-rose-500 text-white font-black py-4 rounded-xl text-xs uppercase tracking-widest shadow-lg shadow-rose-500/30 transition-all active:scale-95 flex items-center justify-center gap-2 mt-4"; btnLaunch.className = "w-full bg-rose-600 hover:bg-rose-500 text-white font-black py-4 rounded-xl text-xs uppercase tracking-widest shadow-lg shadow-rose-500/30 transition-all active:scale-95 flex items-center justify-center gap-2 mt-4";
btnLaunch.innerHTML = '<i data-lucide="rocket" class="w-4 h-4"></i> Inyectar de todos modos'; btnLaunch.innerHTML = '<i data-lucide="rocket" class="w-4 h-4"></i> Inyectar de todos modos';
} }