login.html
4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SIGEM GIS - Login</title>
<style>
body, html { height: 100%; margin: 0; font-family: 'Inter', sans-serif; background: #0f172a; color: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.login-card { background: #1e293b; padding: 40px; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.5); width: 100%; max-width: 400px; border: 1px solid rgba(255,255,255,0.1); }
.logo { text-align: center; margin-bottom: 30px; font-weight: 800; font-size: 24px; color: #3b82f6; letter-spacing: -1px; }
.form-group { margin-bottom: 20px; }
label { display: block; font-size: 11px; text-transform: uppercase; color: #64748b; font-weight: 700; margin-bottom: 8px; letter-spacing: 0.5px; }
input, select { width: 100%; padding: 12px 16px; background: #0f172a; border: 1px solid #334155; border-radius: 10px; color: #fff; font-size: 14px; transition: all 0.2s; }
input:focus, select:focus { border-color: #3b82f6; outline: none; box-shadow: 0 0 0 3px rgba(59,130,246,0.2); }
.login-btn { width: 100%; padding: 14px; background: #3b82f6; color: #fff; border: none; border-radius: 10px; font-weight: 600; cursor: pointer; transition: all 0.2s; margin-top: 20px; }
.login-btn:hover { background: #2563eb; transform: translateY(-1px); }
#error-msg { color: #ef4444; font-size: 13px; margin-top: 15px; text-align: center; display: none; }
</style>
</head>
<body>
<div class="login-card">
<div class="logo">SIGEM<span style="color:#fff">WEB</span> GIS</div>
<form id="loginForm">
<div class="form-group">
<label>Municipalidad (Entidad)</label>
<select id="entidad" required></select>
</div>
<div class="form-group">
<label>Usuario</label>
<input type="text" id="username" placeholder="operador" required>
</div>
<div class="form-group">
<label>Contraseña</label>
<input type="password" id="password" required>
</div>
<button type="submit" class="login-btn">Acceder al Sistema</button>
<div id="error-msg"></div>
</form>
</div>
<script>
const entidadSelect = document.getElementById('entidad');
const loginForm = document.getElementById('loginForm');
const errorMsg = document.getElementById('error-msg');
async function loadEntidades() {
try {
const res = await fetch('/gis-geoserver/api/auth/entidades');
const list = await res.json();
list.forEach(e => {
const opt = document.createElement('option');
opt.value = e.entidad;
opt.textContent = e.nombre;
entidadSelect.appendChild(opt);
});
} catch (e) { console.error('Error al cargar entidades'); }
}
loginForm.onsubmit = async (e) => {
e.preventDefault();
errorMsg.style.display = 'none';
const payload = {
username: document.getElementById('username').value,
password: document.getElementById('password').value,
entidad: entidadSelect.value
};
try {
const res = await fetch('/gis-geoserver/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (res.ok) {
const data = await res.json();
localStorage.setItem('jwt', data.token);
localStorage.setItem('entidad', entidadSelect.value);
localStorage.setItem('map_lat', data.lat);
localStorage.setItem('map_lng', data.lng);
localStorage.setItem('map_zoom', data.zoom);
window.location.href = '/gis-geoserver/mapas';
} else {
errorMsg.innerText = 'Credenciales inválidas';
errorMsg.style.display = 'block';
}
} catch (e) {
errorMsg.innerText = 'Error al conectar con el servidor';
errorMsg.style.display = 'block';
}
};
loadEntidades();
</script>
</body>
</html>