-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-admin-user.html
More file actions
449 lines (380 loc) · 14.6 KB
/
setup-admin-user.html
File metadata and controls
449 lines (380 loc) · 14.6 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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Configuración de Usuario Administrador - 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);
}
}
.user-status {
background: #f8f9fa;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
}
.user-status 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;
}
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-check {
background: #3498db;
color: white;
}
.btn-check:hover {
background: #2980b9;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}
.btn-setup {
background: #28a745;
color: white;
}
.btn-setup:hover {
background: #218838;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}
.btn-setup:disabled {
background: #95a5a6;
cursor: not-allowed;
transform: none;
}
.user-details {
background: #fff3cd;
border-radius: 8px;
padding: 15px;
margin-top: 15px;
display: none;
}
.user-details.show {
display: block;
}
.user-details h4 {
color: #856404;
margin-bottom: 10px;
}
.user-details p {
color: #856404;
margin: 5px 0;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h1>👤 Configuración de Usuario Administrador</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 verifica y configura el usuario administrador del sistema:</p>
<p style="margin-top: 10px;"><strong>Miguel de Jesús Cabrera Cruz</strong></p>
</div>
<div class="success-box" id="successBox">
<h3>✅ Usuario Administrador Configurado</h3>
<p id="successMessage"></p>
</div>
<div class="error-box" id="errorBox">
<h3>❌ Error</h3>
<p id="errorMessage"></p>
</div>
<div class="user-status" id="userStatus" style="display: none;">
<h3>📊 Estado del Usuario Administrador</h3>
<div class="status-item">
<span class="status-label">Nombre:</span>
<span class="status-value" id="userName">-</span>
</div>
<div class="status-item">
<span class="status-label">Usuario:</span>
<span class="status-value" id="userUsername">-</span>
</div>
<div class="status-item">
<span class="status-label">Email:</span>
<span class="status-value" id="userEmail">-</span>
</div>
<div class="status-item">
<span class="status-label">Rol:</span>
<span class="status-value" id="userRole">-</span>
</div>
<div class="status-item">
<span class="status-label">Estado:</span>
<span class="status-value" id="userActive">-</span>
</div>
<div class="status-item">
<span class="status-label">Verificado:</span>
<span class="status-value" id="userVerified">-</span>
</div>
<div class="user-details" id="userDetails">
<h4>🔧 Acciones Necesarias</h4>
<p id="actionsNeeded"></p>
</div>
</div>
<button class="btn-check" onclick="checkAdminUser()">
🔍 Verificar Usuario Administrador
</button>
<button class="btn-setup" id="setupButton" onclick="setupAdminUser()" disabled>
⚙️ Configurar como Administrador
</button>
</div>
<script>
let currentUser = null;
function checkAdminUser() {
const successBox = document.getElementById('successBox');
const errorBox = document.getElementById('errorBox');
const userStatus = document.getElementById('userStatus');
const setupButton = document.getElementById('setupButton');
const userDetails = document.getElementById('userDetails');
// Ocultar mensajes previos
successBox.classList.remove('show');
errorBox.classList.remove('show');
userDetails.classList.remove('show');
try {
// Obtener usuarios de userStorage
const userStorageData = localStorage.getItem('mopc_users_db');
if (!userStorageData) {
showError('No se encontró la base de datos de usuarios. El sistema userStorage no está inicializado.');
userStatus.style.display = 'none';
setupButton.disabled = true;
return;
}
const userStorage = JSON.parse(userStorageData);
// Buscar usuario por nombre
currentUser = Object.values(userStorage).find(u =>
u.name.toLowerCase().includes('miguel') &&
u.name.toLowerCase().includes('cabrera')
);
if (!currentUser) {
showError('No se encontró el usuario "Miguel de Jesús Cabrera Cruz" en userStorage. Debe ser creado primero.');
userStatus.style.display = 'none';
setupButton.disabled = true;
return;
}
// Mostrar información del usuario
document.getElementById('userName').textContent = currentUser.name;
document.getElementById('userUsername').textContent = currentUser.username;
document.getElementById('userEmail').textContent = currentUser.email;
const roleEl = document.getElementById('userRole');
roleEl.textContent = currentUser.role;
roleEl.className = 'status-value ' + (currentUser.role === 'Administrador' ? 'good' : 'bad');
const activeEl = document.getElementById('userActive');
activeEl.textContent = currentUser.isActive ? 'Activo ✓' : 'Inactivo ✗';
activeEl.className = 'status-value ' + (currentUser.isActive ? 'good' : 'bad');
const verifiedEl = document.getElementById('userVerified');
verifiedEl.textContent = currentUser.isVerified ? 'Verificado ✓' : 'No Verificado ✗';
verifiedEl.className = 'status-value ' + (currentUser.isVerified ? 'good' : 'bad');
userStatus.style.display = 'block';
// Verificar si necesita configuración
const needsSetup = currentUser.role !== 'Administrador' ||
!currentUser.isActive ||
!currentUser.isVerified;
if (needsSetup) {
const actions = [];
if (currentUser.role !== 'Administrador') actions.push('Cambiar rol a Administrador');
if (!currentUser.isActive) actions.push('Activar cuenta');
if (!currentUser.isVerified) actions.push('Verificar cuenta');
document.getElementById('actionsNeeded').textContent =
'El usuario necesita: ' + actions.join(', ');
userDetails.classList.add('show');
setupButton.disabled = false;
} else {
showSuccess('El usuario ya está configurado correctamente como Administrador.');
setupButton.disabled = true;
}
} catch (error) {
showError('Error al verificar el usuario: ' + error.message);
console.error('Error:', error);
userStatus.style.display = 'none';
setupButton.disabled = true;
}
}
function setupAdminUser() {
if (!currentUser) {
showError('Primero debe verificar el usuario.');
return;
}
if (!confirm('¿Está seguro de que desea configurar a "' + currentUser.name + '" como Administrador del sistema?')) {
return;
}
try {
// Obtener userStorage
const userStorageData = localStorage.getItem('mopc_users_db');
const userStorage = JSON.parse(userStorageData);
// Actualizar usuario
const updatedUser = {
...currentUser,
role: 'Administrador',
isActive: true,
isVerified: true,
updatedAt: new Date().toISOString(),
version: currentUser.version + 1
};
// Guardar en userStorage
userStorage[currentUser.id] = updatedUser;
localStorage.setItem('mopc_users_db', JSON.stringify(userStorage));
// Actualizar índice
const indexData = localStorage.getItem('mopc_users_index');
if (indexData) {
const index = JSON.parse(indexData);
const userIndex = index.find(u => u.id === currentUser.id);
if (userIndex) {
userIndex.role = 'Administrador';
userIndex.isActive = true;
}
localStorage.setItem('mopc_users_index', JSON.stringify(index));
}
showSuccess('✅ Usuario configurado exitosamente como Administrador. Puede iniciar sesión con privilegios completos.');
// Actualizar verificación
setTimeout(() => {
checkAdminUser();
}, 1500);
} catch (error) {
showError('Error al configurar 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 configuración de administrador cargada');
});
</script>
</body>
</html>