-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-admin-user.html
More file actions
422 lines (362 loc) · 14 KB
/
init-admin-user.html
File metadata and controls
422 lines (362 loc) · 14 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inicializar Usuario Super - MOPC</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
max-width: 700px;
width: 100%;
padding: 40px;
}
h1 {
color: #2c3e50;
margin-bottom: 10px;
font-size: 28px;
}
.subtitle {
color: #7f8c8d;
margin-bottom: 30px;
font-size: 14px;
}
.info-box {
background: #e3f2fd;
border-left: 4px solid #2196f3;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
}
.info-box h3 {
color: #1976d2;
margin-bottom: 10px;
font-size: 16px;
}
.info-box p {
color: #424242;
margin: 5px 0;
}
.success-box {
background: #d4edda;
border-left: 4px solid #28a745;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
display: none;
}
.success-box.show {
display: block;
animation: slideIn 0.3s ease;
}
.success-box h3 {
color: #155724;
margin-bottom: 10px;
font-size: 16px;
}
.error-box {
background: #f8d7da;
border-left: 4px solid #dc3545;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
display: none;
}
.error-box.show {
display: block;
animation: slideIn 0.3s ease;
}
.error-box h3 {
color: #721c24;
margin-bottom: 10px;
font-size: 16px;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
button {
width: 100%;
padding: 15px 30px;
border: none;
border-radius: 10px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
margin-bottom: 10px;
}
.btn-primary {
background: #28a745;
color: white;
}
.btn-primary:hover {
background: #218838;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}
.btn-secondary {
background: #6c757d;
color: white;
}
.btn-secondary:hover {
background: #5a6268;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(108, 117, 125, 0.3);
}
.status-info {
background: #f8f9fa;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
}
.status-info h3 {
color: #2c3e50;
margin-bottom: 15px;
}
.status-item {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
padding: 8px;
background: white;
border-radius: 5px;
}
.status-label {
color: #424242;
font-weight: 500;
}
.status-value {
color: #2c3e50;
font-weight: bold;
}
.status-value.good {
color: #28a745;
}
.status-value.bad {
color: #dc3545;
}
</style>
</head>
<body>
<div class="container">
<h1>🔧 Inicializar Usuario Super</h1>
<p class="subtitle">Sistema de Gestión MOPC v0.1</p>
<div class="info-box">
<h3>ℹ️ Acerca de esta herramienta</h3>
<p>Esta herramienta creará el usuario administrador "super" si no existe:</p>
<p style="margin-top: 10px;"><strong>Usuario:</strong> super</p>
<p><strong>Contraseña:</strong> 02260516</p>
<p><strong>Rol:</strong> Administrador</p>
</div>
<div class="success-box" id="successBox">
<h3>✅ Usuario Super Creado</h3>
<p id="successMessage"></p>
</div>
<div class="error-box" id="errorBox">
<h3>❌ Error</h3>
<p id="errorMessage"></p>
</div>
<div class="status-info" id="statusInfo" style="display: none;">
<h3>📊 Estado del Sistema</h3>
<div class="status-item">
<span class="status-label">Base de datos inicializada:</span>
<span class="status-value" id="dbStatus">-</span>
</div>
<div class="status-item">
<span class="status-label">Total de usuarios:</span>
<span class="status-value" id="totalUsers">-</span>
</div>
<div class="status-item">
<span class="status-label">Usuario "super" existe:</span>
<span class="status-value" id="superExists">-</span>
</div>
</div>
<button class="btn-secondary" onclick="checkStatus()">
🔍 Verificar Estado Actual
</button>
<button class="btn-primary" onclick="initializeSuperUser()">
⚡ Crear Usuario Super
</button>
</div>
<script>
function checkStatus() {
const statusInfo = document.getElementById('statusInfo');
const successBox = document.getElementById('successBox');
const errorBox = document.getElementById('errorBox');
// Ocultar mensajes previos
successBox.classList.remove('show');
errorBox.classList.remove('show');
try {
// Verificar si existe la base de datos
const userStorageData = localStorage.getItem('mopc_users_db');
const dbExists = userStorageData !== null;
document.getElementById('dbStatus').textContent = dbExists ? 'Sí ✓' : 'No ✗';
document.getElementById('dbStatus').className = 'status-value ' + (dbExists ? 'good' : 'bad');
if (dbExists) {
const userStorage = JSON.parse(userStorageData);
const totalUsers = Object.keys(userStorage).length;
document.getElementById('totalUsers').textContent = totalUsers;
document.getElementById('totalUsers').className = 'status-value ' + (totalUsers > 0 ? 'good' : 'bad');
// Verificar si existe usuario super
const superUser = Object.values(userStorage).find(u => u.username === 'super');
document.getElementById('superExists').textContent = superUser ? 'Sí ✓' : 'No ✗';
document.getElementById('superExists').className = 'status-value ' + (superUser ? 'good' : 'bad');
} else {
document.getElementById('totalUsers').textContent = '0';
document.getElementById('totalUsers').className = 'status-value bad';
document.getElementById('superExists').textContent = 'No ✗';
document.getElementById('superExists').className = 'status-value bad';
}
statusInfo.style.display = 'block';
} catch (error) {
showError('Error al verificar el estado: ' + error.message);
console.error('Error:', error);
}
}
function initializeSuperUser() {
try {
// Inicializar userStorage si no existe
let userStorageData = localStorage.getItem('mopc_users_db');
let userStorage = {};
if (userStorageData) {
userStorage = JSON.parse(userStorageData);
} else {
// Inicializar base de datos
localStorage.setItem('mopc_users_db', JSON.stringify({}));
localStorage.setItem('mopc_users_index', JSON.stringify([]));
const metadata = {
version: 1,
createdAt: new Date().toISOString(),
lastModified: new Date().toISOString(),
totalUsers: 0,
activeUsers: 0
};
localStorage.setItem('mopc_users_metadata', JSON.stringify(metadata));
}
// Verificar si el usuario super ya existe
const existingSuperUser = Object.values(userStorage).find(u => u.username === 'super');
if (existingSuperUser) {
showError('El usuario "super" ya existe en el sistema.');
return;
}
// Crear ID único para el usuario
const userId = 'user-' + Date.now() + '-' + Math.random().toString(36).substring(2, 9);
const now = new Date().toISOString();
// Crear el usuario super
const superUser = {
id: userId,
username: 'super',
password: '02260516',
name: 'Administrador Super',
email: 'admin@mopc.gob.do',
phone: '',
cedula: '000-0000000-0',
role: 'Administrador',
department: 'Dirección de Coordinación Regional',
isActive: true,
isVerified: true,
lastSeen: now,
joinDate: now,
avatar: '',
currentLocation: {
province: 'Distrito Nacional',
municipality: 'Santo Domingo',
coordinates: {
lat: 18.4861,
lng: -69.9312
},
lastUpdated: now
},
reportsCount: 0,
pendingReportsCount: 0,
notes: [],
createdAt: now,
updatedAt: now,
createdBy: 'system',
version: 1
};
// Guardar en userStorage
userStorage[userId] = superUser;
localStorage.setItem('mopc_users_db', JSON.stringify(userStorage));
// Actualizar índice
const indexData = localStorage.getItem('mopc_users_index');
let index = indexData ? JSON.parse(indexData) : [];
index.push({
id: userId,
username: 'super',
name: 'Administrador Super',
email: 'admin@mopc.gob.do',
role: 'Administrador',
department: 'Dirección de Coordinación Regional',
isActive: true
});
localStorage.setItem('mopc_users_index', JSON.stringify(index));
// Actualizar metadata
const metadataData = localStorage.getItem('mopc_users_metadata');
const metadata = metadataData ? JSON.parse(metadataData) : {
version: 1,
createdAt: now,
totalUsers: 0,
activeUsers: 0
};
metadata.totalUsers = Object.keys(userStorage).length;
metadata.activeUsers = Object.values(userStorage).filter(u => u.isActive).length;
metadata.lastModified = now;
localStorage.setItem('mopc_users_metadata', JSON.stringify(metadata));
showSuccess('✅ Usuario "super" creado exitosamente. Puede iniciar sesión con usuario: "super" y contraseña: "02260516"');
// Actualizar verificación
setTimeout(() => {
checkStatus();
}, 1500);
} catch (error) {
showError('Error al crear el usuario: ' + error.message);
console.error('Error:', error);
}
}
function showSuccess(message) {
const successBox = document.getElementById('successBox');
const successMessage = document.getElementById('successMessage');
const errorBox = document.getElementById('errorBox');
errorBox.classList.remove('show');
successMessage.textContent = message;
successBox.classList.add('show');
}
function showError(message) {
const errorBox = document.getElementById('errorBox');
const errorMessage = document.getElementById('errorMessage');
const successBox = document.getElementById('successBox');
successBox.classList.remove('show');
errorMessage.textContent = message;
errorBox.classList.add('show');
}
// Verificación automática al cargar
window.addEventListener('load', () => {
console.log('🔧 Herramienta de inicialización cargada');
checkStatus();
});
</script>
</body>
</html>