login.html 8.72 KB
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Inicie Sesión - Ecosistema SIGEM</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap" rel="stylesheet">
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(-45deg, #0d1b2a, #1b263b, #415a77, #778da9);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #fff;
        }
        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }
        .login-container {
            background: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 24px;
            padding: 40px;
            width: 100%;
            max-width: 400px;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
            animation: slideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
            opacity: 0;
            transform: translateY(30px);
        }
        @keyframes slideUp { to { opacity: 1; transform: translateY(0); } }
        .logo-area { text-align: center; margin-bottom: 30px; }
        .logo-area h1 { font-weight: 800; font-size: 28px; letter-spacing: -0.5px; }
        .logo-area span { color: #facc15; }
        .logo-area p { font-size: 14px; font-weight: 300; color: #cbd5e1; margin-top: 5px; }
        .input-group { margin-bottom: 20px; }
        .input-group label {
            display: block; font-size: 13px; font-weight: 600; color: #94a3b8; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px;
        }
        .input-group input, .input-group select {
            width: 100%; padding: 14px 16px; background: rgba(0, 0, 0, 0.2); border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 12px; color: #fff; font-size: 15px; font-family: 'Inter', sans-serif; transition: all 0.3s ease;
        }
        .input-group select { appearance: none; cursor: pointer; }
        .input-group select option { color: #000; }
        .input-group input:focus, .input-group select:focus {
            outline: none; border-color: #facc15; background: rgba(0, 0, 0, 0.4); box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.2);
        }
        .btn-submit {
            width: 100%; padding: 16px; background: linear-gradient(135deg, #eab308, #ca8a04);
            color: #000; border: none; border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 10px 15px -3px rgba(234, 179, 8, 0.3);
            margin-top: 10px;
        }
        .btn-submit:hover { transform: translateY(-2px); box-shadow: 0 15px 25px -5px rgba(234, 179, 8, 0.4); }
        .btn-submit:active { transform: translateY(0); }
        
        #error-msg {
            display: none; color: #fca5a5; font-size: 14px; font-weight: 600; text-align: center;
            background: rgba(239, 68, 68, 0.2); padding: 10px; border-radius: 8px; margin-top: 15px; border: 1px solid rgba(239, 68, 68, 0.3);
        }
        
        .loader {
            display: none; border: 3px solid rgba(0, 0, 0, 0.1); border-radius: 50%;
            border-top: 3px solid #000; width: 24px; height: 24px; animation: spin 1s linear infinite; margin: 0 auto;
        }
        @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
    </style>
</head>
<body>

<div class="login-container">
    <div class="logo-area">
        <h1>SIGEM<span>WEB</span></h1>
        <p>Visor Georreferenciado Multi-Tenant</p>
    </div>

    <form id="loginForm">
        <div class="input-group">
            <label for="municipioSearch">Municipalidad (Entidad)</label>
            <input type="text" id="municipioSearch" placeholder="Escriba para buscar (ej. 505)" autocomplete="off" style="margin-bottom: 5px;">
            <select id="entidad" required size="3" style="height: 100px; overflow-y: auto;">
                <option value="505">Entidad 505 (Piloto GIS)</option>
                <option value="800">Entidad 800 (Pruebas)</option>
                <option value="900">Entidad 900 (Desarrollo)</option>
            </select>
            <p style="font-size: 11px; color: #94a3b8; margin-top: 5px;">Seleccione de la lista superior</p>
        </div>
        <div class="input-group">
            <label for="username">Usuario</label>
            <input type="text" id="username" placeholder="Usu_alias (ej. operador)" required autocomplete="username">
        </div>
        <div class="input-group">
            <label for="password">Contraseña</label>
            <input type="password" id="password" placeholder="Tu clave alfanumérica" required autocomplete="current-password">
        </div>
        
        <button type="submit" class="btn-submit" id="btn-login">
            <span id="btn-text">INICIAR SESIÓN</span>
            <div class="loader" id="spinner"></div>
        </button>
        
        <div id="error-msg"></div>
    </form>
</div>

<script>
    // Filtro interactivo de municipios
    const searchInput = document.getElementById('municipioSearch');
    const selectEntidad = document.getElementById('entidad');
    const originalOptions = Array.from(selectEntidad.options);

    searchInput.addEventListener('input', (e) => {
        const text = e.target.value.toLowerCase();
        selectEntidad.innerHTML = '';
        originalOptions.forEach(opt => {
            if (opt.text.toLowerCase().includes(text) || opt.value.includes(text)) {
                selectEntidad.appendChild(opt);
            }
        });
        if (selectEntidad.options.length > 0) {
            selectEntidad.options[0].selected = true;
        }
    });

    // Limpiar sesión previa si por error caen al login
    localStorage.removeItem('jwt');
    
    document.getElementById('loginForm').addEventListener('submit', function(e) {
        e.preventDefault();
        
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;
        const entidad = document.getElementById('entidad').value;
        const errorMsg = document.getElementById('error-msg');
        const btnText = document.getElementById('btn-text');
        const spinner = document.getElementById('spinner');
        
        // Bloquear UI
        errorMsg.style.display = 'none';
        btnText.style.display = 'none';
        spinner.style.display = 'block';
        document.getElementById('btn-login').disabled = true;

        const payload = {
            username: username,
            password: password,
            entidad: entidad
        };

        fetch('/gis-geoserver/api/auth/login', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(payload)
        })
        .then(response => {
            if (!response.ok) {
                return response.json().then(errData => {
                    throw new Error(errData.message || "Credenciales incorrectas.");
                });
            }
            return response.json();
        })
        .then(data => {
            // LOGIN EXITOOSO!
            localStorage.setItem('jwt', data.token);     
            localStorage.setItem('user_name', data.nombre); // Nombre completo del usuario
            localStorage.setItem('entidad', entidad); 
            
            // Persistir metadatos del Visor
            localStorage.setItem('map_lat', data.lat);
            localStorage.setItem('map_lng', data.lng);
            localStorage.setItem('map_zoom', data.zoom);
            localStorage.setItem('map_min_zoom', data.minZoom);
            localStorage.setItem('map_max_zoom', data.maxZoom);
            localStorage.setItem('mapa_base_id', data.mapaBase);
            localStorage.setItem('map_bounds', data.bounds);
            
            // Redirigir a la URL del Mapas de Leaflet
            window.location.href = "/gis-geoserver/mapas";
        })
        .catch(error => {
            // LOGIN ERROR
            errorMsg.innerText = error.message;
            errorMsg.style.display = 'block';
            
            // Restaurar UI
            btnText.style.display = 'block';
            spinner.style.display = 'none';
            document.getElementById('btn-login').disabled = false;
        });
    });
</script>

</body>
</html>
GitLab Appliance - Powered by TurnKey Linux