login.html
7.56 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Inicie Sesión - Ecosistema SIGEM</title>
<!-- Google Font: Source Sans Pro (Estandar de AdminLTE) -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<!-- Theme style AdminLTE 3 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">
<style>
.login-page {
background: linear-gradient(135deg, #e0eafc 0%, #cfdef3 100%);
}
.card-primary.card-outline {
border-top: 3px solid #0056b3;
}
.btn-primary {
background-color: #0056b3;
border-color: #0056b3;
}
.btn-primary:hover {
background-color: #004494;
border-color: #004494;
}
.login-logo a {
color: #333 !important;
}
</style>
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<a href="#"><b>SIGEM</b>WEB</a>
</div>
<!-- /.login-logo -->
<div class="card card-outline card-primary shadow-lg">
<div class="card-body login-card-body rounded">
<p class="login-box-msg font-weight-bold" style="color: #555;">Visor Georreferenciado Multi-Tenant</p>
<form id="loginForm">
<label for="municipioSearch" class="text-xs text-muted mb-1" style="font-size: 0.8rem; text-transform: uppercase;">1. Entidad (Municipalidad)</label>
<div class="input-group mb-2">
<input type="text" id="municipioSearch" class="form-control" placeholder="Buscar municipio (ej. 505)" autocomplete="off">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-search"></span>
</div>
</div>
</div>
<div class="form-group mb-3">
<select id="entidad" class="form-control" required size="3" style="height: 85px; cursor: pointer; font-size: 0.9rem;">
<option value="505">Entidad 505 (Piloto GIS)</option>
<option value="800">Entidad 800 (Pruebas)</option>
<option value="900">Entidad 900 (Desarrollo)</option>
</select>
</div>
<label class="text-xs text-muted mb-1" style="font-size: 0.8rem; text-transform: uppercase;">2. Credenciales</label>
<div class="input-group mb-3">
<input type="text" id="username" class="form-control" placeholder="Usu_alias (ej. operador)" required autocomplete="username">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-user"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" id="password" class="form-control" placeholder="Tu clave alfanumérica" required autocomplete="current-password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div id="error-msg" class="alert alert-danger p-2 mb-3 text-center" style="display:none; font-size: 13px;"></div>
<div class="row mt-4">
<div class="col-12">
<button type="submit" class="btn btn-primary btn-block font-weight-bold" id="btn-login" style="padding: 10px;">
<span id="btn-text">INICIAR SESIÓN</span>
<div class="spinner-border spinner-border-sm text-light" id="spinner" role="status" style="display:none; margin: auto;"></div>
</button>
</div>
</div>
</form>
</div>
<!-- /.login-card-body -->
</div>
</div>
<!-- /.login-box -->
<!-- jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/js/adminlte.min.js"></script>
<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');
localStorage.removeItem('user_name');
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
window.location.href = "/gis-geoserver/landing";
})
.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>