-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotected.ejs
164 lines (153 loc) · 5.84 KB
/
protected.ejs
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Panel de Administración</title>
<link rel="stylesheet" href="styles.css">
<script>
async function realizarSolicitudPost(url, datos) {
try {
const respuesta = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(datos)
});
if (respuesta.ok) {
window.location.href = '/';
} else {
console.error('Error al cerrar sesión');
}
} catch (error) {
console.error('Error en la solicitud:', error);
}
}
function cerrarSesion() {
realizarSolicitudPost('/api/v1/logout', {});
}
// Función para cargar las estadísticas del usuario
async function loadUserData() {
try {
const userResponse = await fetch('/api/v1/user/data'); // Adjust the endpoint as needed
const userData = await userResponse.json();
if (userData.success) {
document.getElementById('username').textContent = userData.data.username;
document.getElementById('user_tag').textContent = userData.data.user_tag;
}
const response = await fetch('/api/v1/user/stats');
const data = await response.json();
console.log('User stats:', data);
if (data.success) {
document.getElementById('highestScore').textContent = data.data.highestScore || 0;
document.getElementById('lastScore').textContent = data.data.lastScore || 0;
document.getElementById('correctAnswers').textContent = data.data.correctAnswers || 0;
document.getElementById('incorrectAnswers').textContent = data.data.incorrectAnswers || 0;
document.getElementById('totalQuestions').textContent = data.data.totalQuestions || 0;
document.getElementById('accuracy').textContent = data.data.accuracy || '0%';
}
} catch (error) {
console.error('Error loading user stats:', error);
}
}
// También puedes llamar a loadUserStats aquí si deseas cargar las estadísticas al inicio
document.addEventListener('DOMContentLoaded', loadUserData);
</script>
<style>
body {
font-family: "Helvetica Neue", Arial, sans-serif;
}
.protected-container {
text-align: center;
padding: 20px;
border: 1px solid #ccc;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
width: 50%;
margin: 20px auto;
}
button.logout {
width: 100%;
padding: 10px;
background-color: red;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
}
button.back {
width: 100%;
padding: 10px;
background-color: green;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.stats-container {
background: #f0f0f0;
padding: 20px;
border-radius: 8px;
margin-top: 20px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
.stat-item {
background: white;
padding: 10px;
border-radius: 4px;
text-align: center;
}
.stat-label {
font-weight: bold;
color: #666;
}
.stat-value {
font-size: 1.2em;
color: #333;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="protected-container">
<h2>Hola <span id="username"></span>!</h2>
<p>Tu user tag es: <span id="user_tag"></span></p>
<p>Estás en el panel de administración</p>
<!-- Nueva sección de estadísticas -->
<div class="stats-container">
<div class="stat-item">
<div class="stat-label">Mejor Puntaje</div>
<div class="stat-value" id="highestScore">0</div>
</div>
<div class="stat-item">
<div class="stat-label">Último Puntaje</div>
<div class="stat-value" id="lastScore">0</div>
</div>
<div class="stat-item">
<div class="stat-label">Respuestas Correctas</div>
<div class="stat-value" id="correctAnswers">0</div>
</div>
<div class="stat-item">
<div class="stat-label">Respuestas Incorrectas</div>
<div class="stat-value" id="incorrectAnswers">0</div>
</div>
<div class="stat-item">
<div class="stat-label">Total Preguntas</div>
<div class="stat-value" id="totalQuestions">0</div>
</div>
<div class="stat-item">
<div class="stat-label">Precisión</div>
<div class="stat-value" id="accuracy">0%</div>
</div>
</div>
<div style="text-align: center; margin: 20px; display: flex; justify-content: center; gap: 10px;">
<button class="back" onclick="window.location.href='/'">← Volver al inicio</button>
<button class="logout" onclick="cerrarSesion()">Cerrar sesión</button>
</div>
</div>
</body>
</html>