Spaces:
Sleeping
Sleeping
Update templates/api_key.html
Browse files- templates/api_key.html +261 -334
templates/api_key.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Nexus
|
| 7 |
<link rel="icon" type="image/png" href="https://i.imgur.com/7Gn3toV.png">
|
| 8 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
<link rel="stylesheet"
|
|
@@ -22,387 +22,314 @@
|
|
| 22 |
cursor: pointer;
|
| 23 |
font-size: 24px;
|
| 24 |
transition: color 0.2s;
|
| 25 |
-
position: fixed;
|
| 26 |
top: 1rem;
|
| 27 |
right: 1rem;
|
| 28 |
-
z-index: 50;
|
| 29 |
}
|
| 30 |
|
| 31 |
/* Définir les Variables de Thème */
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
--
|
| 35 |
-
--
|
| 36 |
-
--
|
| 37 |
-
--
|
| 38 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
--
|
| 44 |
-
--
|
| 45 |
-
--
|
| 46 |
-
--
|
| 47 |
-
--color
|
| 48 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
/*
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
</style>
|
| 65 |
</head>
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
-
<button id="theme-
|
| 69 |
-
<span class="material-symbols-rounded">
|
| 70 |
</button>
|
| 71 |
-
|
| 72 |
-
<
|
| 73 |
-
<div class="flex items-center
|
| 74 |
-
<img src="https://i.imgur.com/7Gn3toV.png" alt="Logo
|
| 75 |
-
<
|
| 76 |
</div>
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
<span class="
|
| 86 |
-
</a></li>
|
| 87 |
-
</ul>
|
| 88 |
-
<div class="mt-8 pt-4 border-t border-theme-border">
|
| 89 |
-
<a href="{{ url_for('user_bp.deconnexion') }}" id="logout-button-sidebar" class="flex items-center p-3 rounded-lg text-red-500 hover:bg-red-500/10 transition-colors-theme">
|
| 90 |
-
<span class="material-symbols-rounded mr-3">logout</span> Déconnexion
|
| 91 |
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
</div>
|
| 93 |
-
</nav>
|
| 94 |
-
|
| 95 |
-
<button id="sidebar-toggle" class="fixed top-4 left-4 z-50 p-2 lg:hidden bg-theme-secondary rounded-lg border border-theme-border text-theme-primary transition-colors-theme">
|
| 96 |
-
<span class="material-symbols-rounded">menu</span>
|
| 97 |
-
</button>
|
| 98 |
-
|
| 99 |
-
<main class="lg:pl-72 pt-20 p-4 sm:p-6 lg:p-8">
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
</header>
|
| 105 |
|
| 106 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
<div class="
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
<
|
| 111 |
-
<
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
<
|
| 121 |
-
|
| 122 |
-
</button>
|
| 123 |
-
</div>
|
| 124 |
-
|
| 125 |
-
<div class="overflow-x-auto bg-theme-secondary rounded-lg shadow-xl border border-theme-border">
|
| 126 |
-
<table class="min-w-full divide-y divide-theme-border">
|
| 127 |
-
<thead class="bg-gray-50/5 dark:bg-gray-800/20">
|
| 128 |
-
<tr>
|
| 129 |
-
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-theme-secondary uppercase tracking-wider">
|
| 130 |
-
Clé API
|
| 131 |
-
</th>
|
| 132 |
-
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-theme-secondary uppercase tracking-wider hidden sm:table-cell">
|
| 133 |
-
Créée le
|
| 134 |
-
</th>
|
| 135 |
-
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-theme-secondary uppercase tracking-wider">
|
| 136 |
-
Statut
|
| 137 |
-
</th>
|
| 138 |
-
<th scope="col" class="relative px-6 py-3">
|
| 139 |
-
<span class="sr-only">Actions</span>
|
| 140 |
-
</th>
|
| 141 |
-
</tr>
|
| 142 |
-
</thead>
|
| 143 |
-
<tbody class="divide-y divide-theme-border">
|
| 144 |
-
{% if not user.api_keys %}
|
| 145 |
-
<tr>
|
| 146 |
-
<td colspan="4" class="px-6 py-4 whitespace-nowrap text-sm text-center text-theme-secondary">
|
| 147 |
-
Aucune clé API trouvée. Générez-en une pour commencer.
|
| 148 |
-
</td>
|
| 149 |
-
</tr>
|
| 150 |
-
{% else %}
|
| 151 |
-
{% for key_obj in user.api_keys %}
|
| 152 |
-
<tr id="key-row-{{ loop.index }}" class="hover:bg-gray-50/5 dark:hover:bg-gray-800/10 transition-colors">
|
| 153 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm font-mono text-theme-primary">
|
| 154 |
-
<div class="flex items-center space-x-2">
|
| 155 |
-
<span id="display-key-{{ loop.index }}" class="w-48 overflow-hidden text-ellipsis whitespace-nowrap cursor-pointer"
|
| 156 |
-
data-full-key="{{ key_obj.key }}"
|
| 157 |
-
data-masked="true">
|
| 158 |
-
{{ key_obj.key[:4] }}_{{ "*" * 10 }}...
|
| 159 |
-
</span>
|
| 160 |
-
<button onclick="toggleKeyVisibility(this, '{{ key_obj.key }}', {{ loop.index }})"
|
| 161 |
-
class="text-theme-accent p-1 rounded-full hover:bg-gray-500/10 transition duration-150"
|
| 162 |
-
title="Afficher la clé complète">
|
| 163 |
-
<span class="material-symbols-rounded text-base">visibility_off</span>
|
| 164 |
-
</button>
|
| 165 |
-
<button onclick="copyKey('{{ key_obj.key }}')"
|
| 166 |
-
class="text-theme-accent p-1 rounded-full hover:bg-gray-500/10 transition duration-150"
|
| 167 |
-
title="Copier la clé">
|
| 168 |
-
<span class="material-symbols-rounded text-base">content_copy</span>
|
| 169 |
-
</button>
|
| 170 |
-
</div>
|
| 171 |
-
</td>
|
| 172 |
-
|
| 173 |
-
<td class="px-6 py-4 whitespace-nowrap text-sm text-theme-secondary hidden sm:table-cell">
|
| 174 |
-
<span id="created-at-{{ loop.index }}" data-iso-date="{{ key_obj.created_at }}">
|
| 175 |
-
</span>
|
| 176 |
-
</td>
|
| 177 |
-
|
| 178 |
-
<td class="px-6 py-4 whitespace-nowrap">
|
| 179 |
-
{% if key_obj.status == 'active' %}
|
| 180 |
-
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800 dark:bg-green-800/30 dark:text-green-300">
|
| 181 |
-
Active
|
| 182 |
-
</span>
|
| 183 |
-
{% else %}
|
| 184 |
-
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800 dark:bg-red-800/30 dark:text-red-300">
|
| 185 |
-
Inactive
|
| 186 |
-
</span>
|
| 187 |
-
{% endif %}
|
| 188 |
-
</td>
|
| 189 |
-
|
| 190 |
-
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
| 191 |
-
<button onclick="deleteApiKey('{{ key_obj.key }}')"
|
| 192 |
-
class="text-red-500 hover:text-red-700 dark:hover:text-red-300 transition duration-150 p-2 rounded-full hover:bg-red-500/10"
|
| 193 |
-
title="Supprimer la clé">
|
| 194 |
-
<span class="material-symbols-rounded text-lg">delete</span>
|
| 195 |
-
</button>
|
| 196 |
-
</td>
|
| 197 |
-
</tr>
|
| 198 |
-
{% endfor %}
|
| 199 |
-
{% endif %}
|
| 200 |
-
</tbody>
|
| 201 |
-
</table>
|
| 202 |
</div>
|
| 203 |
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
|
| 207 |
-
// DOM Elements
|
| 208 |
-
const themeSwitch = document.getElementById('theme-switch');
|
| 209 |
-
const sidebarToggle = document.getElementById('sidebar-toggle');
|
| 210 |
-
const sidebar = document.getElementById('sidebar');
|
| 211 |
-
const statusMessage = document.getElementById('status-message');
|
| 212 |
-
const generateBtn = document.getElementById('generate-key-btn');
|
| 213 |
-
const maxKeys = {{ max_keys }};
|
| 214 |
-
const currentKeys = {{ user.api_keys | length }};
|
| 215 |
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
try {
|
| 225 |
-
const date = new Date(isoString);
|
| 226 |
-
// Configuration pour le format français
|
| 227 |
-
const options = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' };
|
| 228 |
-
return date.toLocaleDateString('fr-FR', options);
|
| 229 |
-
} catch (e) {
|
| 230 |
-
return isoString; // Retourne l'original en cas d'erreur
|
| 231 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
}
|
|
|
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
function showStatus(message, type) {
|
| 240 |
-
statusMessage.textContent = message;
|
| 241 |
-
statusMessage.classList.remove('hidden', 'bg-green-100', 'text-green-800', 'bg-red-100', 'text-red-800', 'dark:bg-green-800/30', 'dark:text-green-300', 'dark:bg-red-800/30', 'dark:text-red-300');
|
| 242 |
-
|
| 243 |
-
if (type === 'success') {
|
| 244 |
-
statusMessage.classList.add('bg-green-100', 'text-green-800', 'dark:bg-green-800/30', 'dark:text-green-300');
|
| 245 |
} else {
|
| 246 |
-
|
|
|
|
|
|
|
| 247 |
}
|
|
|
|
|
|
|
| 248 |
|
| 249 |
-
// Masquer le message après 5 secondes
|
| 250 |
-
setTimeout(() => {
|
| 251 |
-
statusMessage.classList.add('hidden');
|
| 252 |
-
}, 5000);
|
| 253 |
-
}
|
| 254 |
-
|
| 255 |
-
// --- Logique de la Page ---
|
| 256 |
-
|
| 257 |
-
// 1. Logique du Thème (Conservée)
|
| 258 |
-
const currentTheme = localStorage.getItem('theme') || 'dark';
|
| 259 |
-
document.documentElement.className = currentTheme;
|
| 260 |
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
|
|
|
| 266 |
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
|
|
|
| 271 |
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
}
|
| 277 |
});
|
| 278 |
|
| 279 |
-
// 2. Logique de la Sidebar sur mobile
|
|
|
|
|
|
|
|
|
|
| 280 |
sidebarToggle.addEventListener('click', () => {
|
| 281 |
sidebar.classList.toggle('open');
|
| 282 |
});
|
| 283 |
-
|
| 284 |
-
// 3. Logique de
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
const logoutHandler = async (e) => {
|
| 286 |
e.preventDefault();
|
|
|
|
| 287 |
window.location.href = document.getElementById('logout-button-sidebar').href;
|
| 288 |
};
|
|
|
|
| 289 |
document.getElementById('logout-button-sidebar').addEventListener('click', logoutHandler);
|
| 290 |
|
| 291 |
|
| 292 |
-
// 4. Logique de Copie de la Clé
|
| 293 |
-
async function copyKey(key) {
|
| 294 |
-
try {
|
| 295 |
-
// Utilise l'API du presse-papiers moderne
|
| 296 |
-
await navigator.clipboard.writeText(key);
|
| 297 |
-
showStatus('Clé API copiée dans le presse-papiers !', 'success');
|
| 298 |
-
} catch (err) {
|
| 299 |
-
// Fallback (e.g., pour HTTP non sécurisé ou anciens navigateurs)
|
| 300 |
-
const textArea = document.createElement("textarea");
|
| 301 |
-
textArea.value = key;
|
| 302 |
-
document.body.appendChild(textArea);
|
| 303 |
-
textArea.focus();
|
| 304 |
-
textArea.select();
|
| 305 |
-
try {
|
| 306 |
-
document.execCommand('copy');
|
| 307 |
-
showStatus('Clé API copiée (méthode de secours) !', 'success');
|
| 308 |
-
} catch (err) {
|
| 309 |
-
showStatus('Erreur : Impossible de copier la clé automatiquement.', 'error');
|
| 310 |
-
}
|
| 311 |
-
document.body.removeChild(textArea);
|
| 312 |
-
}
|
| 313 |
-
}
|
| 314 |
-
|
| 315 |
-
// 5. Logique Afficher/Masquer la Clé
|
| 316 |
-
function toggleKeyVisibility(btnElement, fullKey, index) {
|
| 317 |
-
const displaySpan = document.getElementById(`display-key-${index}`);
|
| 318 |
-
const isMasked = displaySpan.getAttribute('data-masked') === 'true';
|
| 319 |
-
|
| 320 |
-
if (isMasked) {
|
| 321 |
-
// Afficher la clé
|
| 322 |
-
displaySpan.textContent = fullKey;
|
| 323 |
-
btnElement.querySelector('.material-symbols-rounded').textContent = 'visibility';
|
| 324 |
-
btnElement.setAttribute('title', 'Masquer la clé');
|
| 325 |
-
displaySpan.setAttribute('data-masked', 'false');
|
| 326 |
-
} else {
|
| 327 |
-
// Masquer la clé (NXS_****************...)
|
| 328 |
-
displaySpan.textContent = fullKey.substring(0, 4) + '_' + "*".repeat(10) + '...';
|
| 329 |
-
btnElement.querySelector('.material-symbols-rounded').textContent = 'visibility_off';
|
| 330 |
-
btnElement.setAttribute('title', 'Afficher la clé complète');
|
| 331 |
-
displaySpan.setAttribute('data-masked', 'true');
|
| 332 |
-
}
|
| 333 |
-
}
|
| 334 |
-
|
| 335 |
-
// 6. Logique de GÉNÉRATION d'une nouvelle clé
|
| 336 |
-
generateBtn.addEventListener('click', async () => {
|
| 337 |
-
generateBtn.disabled = true;
|
| 338 |
-
generateBtn.textContent = 'Génération...';
|
| 339 |
-
|
| 340 |
-
try {
|
| 341 |
-
const response = await fetch('{{ url_for("user_bp.api_key_generate") }}', {
|
| 342 |
-
method: 'POST',
|
| 343 |
-
headers: {
|
| 344 |
-
'Content-Type': 'application/json'
|
| 345 |
-
}
|
| 346 |
-
});
|
| 347 |
-
const data = await response.json();
|
| 348 |
-
|
| 349 |
-
if (response.ok && response.status === 201) {
|
| 350 |
-
showStatus(data.message || 'Clé créée avec succès ! Rechargement de la page...', 'success');
|
| 351 |
-
// Recharger la page pour mettre à jour la liste complète
|
| 352 |
-
setTimeout(() => window.location.reload(), 1500);
|
| 353 |
-
} else {
|
| 354 |
-
showStatus(data.message || "Erreur lors de la génération de la clé.", 'error');
|
| 355 |
-
}
|
| 356 |
-
|
| 357 |
-
} catch (error) {
|
| 358 |
-
showStatus("Erreur réseau: Impossible de contacter le serveur.", 'error');
|
| 359 |
-
} finally {
|
| 360 |
-
// Rétablir le bouton en cas d'échec seulement (il sera rechargé en cas de succès)
|
| 361 |
-
if (!generateBtn.disabled) {
|
| 362 |
-
generateBtn.textContent = 'Générer une nouvelle clé';
|
| 363 |
-
if (currentKeys < maxKeys) { // S'assurer qu'il n'est pas réactivé si la limite est atteinte
|
| 364 |
-
generateBtn.disabled = false;
|
| 365 |
-
}
|
| 366 |
-
}
|
| 367 |
-
}
|
| 368 |
-
});
|
| 369 |
-
|
| 370 |
-
// 7. Logique de SUPPRESSION d'une clé
|
| 371 |
-
async function deleteApiKey(key) {
|
| 372 |
-
// Phase 3 : Confirmation de Suppression (UX)
|
| 373 |
-
if (!confirm(`Êtes-vous sûr de vouloir supprimer la clé se terminant par ...${key.slice(-4)} ? Cette action est irréversible et annulera toutes les requêtes API l'utilisant.`)) {
|
| 374 |
-
return;
|
| 375 |
-
}
|
| 376 |
-
|
| 377 |
-
try {
|
| 378 |
-
const response = await fetch('{{ url_for("user_bp.api_key_delete") }}', {
|
| 379 |
-
method: 'POST',
|
| 380 |
-
headers: {
|
| 381 |
-
'Content-Type': 'application/json'
|
| 382 |
-
},
|
| 383 |
-
body: JSON.stringify({ key: key })
|
| 384 |
-
});
|
| 385 |
-
const data = await response.json();
|
| 386 |
-
|
| 387 |
-
if (response.ok) {
|
| 388 |
-
showStatus(data.message || 'Clé API supprimée avec succès ! Rechargement de la page...', 'success');
|
| 389 |
-
// Recharger la page pour mettre à jour la liste complète
|
| 390 |
-
setTimeout(() => window.location.reload(), 1500);
|
| 391 |
-
} else {
|
| 392 |
-
showStatus(data.message || "Erreur lors de la suppression de la clé.", 'error');
|
| 393 |
-
}
|
| 394 |
-
|
| 395 |
-
} catch (error) {
|
| 396 |
-
showStatus("Erreur réseau: Impossible de contacter le serveur pour la suppression.", 'error');
|
| 397 |
-
}
|
| 398 |
-
}
|
| 399 |
-
|
| 400 |
-
// 8. Initialisation : Formatage des dates au chargement
|
| 401 |
-
document.querySelectorAll('[data-iso-date]').forEach(element => {
|
| 402 |
-
const isoDate = element.getAttribute('data-iso-date');
|
| 403 |
-
element.textContent = formatDate(isoDate);
|
| 404 |
-
});
|
| 405 |
-
|
| 406 |
</script>
|
| 407 |
</body>
|
| 408 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Nexus| Clés API - Pro</title>
|
| 7 |
<link rel="icon" type="image/png" href="https://i.imgur.com/7Gn3toV.png">
|
| 8 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
<link rel="stylesheet"
|
|
|
|
| 22 |
cursor: pointer;
|
| 23 |
font-size: 24px;
|
| 24 |
transition: color 0.2s;
|
| 25 |
+
position: fixed; /* Reste fixe même si le reste défile */
|
| 26 |
top: 1rem;
|
| 27 |
right: 1rem;
|
| 28 |
+
z-index: 50; /* Doit être au-dessus de tout */
|
| 29 |
}
|
| 30 |
|
| 31 |
/* Définir les Variables de Thème */
|
| 32 |
+
/* Mode Sombre (Défaut) */
|
| 33 |
+
:root, .dark {
|
| 34 |
+
--bg-page: #121212;
|
| 35 |
+
--bg-card: #1E1E1E;
|
| 36 |
+
--bg-sidebar: #1E1E1E; /* Sidebar aussi foncée que les cartes */
|
| 37 |
+
--bg-sidebar-active: #2C2C2C;
|
| 38 |
+
--border-sidebar: #383838;
|
| 39 |
+
--text-color: #FFFFFF;
|
| 40 |
+
--text-secondary: #D1D5DB;
|
| 41 |
+
--text-link: #3B82F6;
|
| 42 |
+
--text-link-hover: #60A5FA;
|
| 43 |
+
--input-bg: #2C2C2C;
|
| 44 |
+
--input-border: #4B5563;
|
| 45 |
+
--input-text-key: #6EE7B7; /* Vert clair pour la clé */
|
| 46 |
+
--primary-color: #3B82F6;
|
| 47 |
+
--primary-hover: #2563EB;
|
| 48 |
+
--warning-bg: #451A03; /* Orange très sombre */
|
| 49 |
+
--warning-border: #78350F;
|
| 50 |
+
--warning-text: #FBBF24;
|
| 51 |
}
|
| 52 |
+
/* Mode Clair */
|
| 53 |
+
.light {
|
| 54 |
+
--bg-page: #F5F5F5;
|
| 55 |
+
--bg-card: #FFFFFF;
|
| 56 |
+
--bg-sidebar: #FFFFFF;
|
| 57 |
+
--bg-sidebar-active: #F3F4F6;
|
| 58 |
+
--border-sidebar: #D1D5DB;
|
| 59 |
+
--text-color: #000000;
|
| 60 |
+
--text-secondary: #4B5563;
|
| 61 |
+
--text-link: #1D4ED8;
|
| 62 |
+
--text-link-hover: #3B82F6;
|
| 63 |
+
--input-bg: #FFFFFF;
|
| 64 |
+
--input-border: #D1D5DB;
|
| 65 |
+
--input-text-key: #059669; /* Vert foncé pour la clé */
|
| 66 |
+
--primary-color: #3B82F6;
|
| 67 |
+
--primary-hover: #2563EB;
|
| 68 |
+
--warning-bg: #FEF3C7; /* Jaune très clair */
|
| 69 |
+
--warning-border: #FBBF24;
|
| 70 |
+
--warning-text: #92400E;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/* Appliquer les variables au body et aux éléments */
|
| 74 |
+
.bg-page-var { background-color: var(--bg-page); }
|
| 75 |
+
.bg-card-var { background-color: var(--bg-card); }
|
| 76 |
+
.bg-sidebar-var { background-color: var(--bg-sidebar); }
|
| 77 |
+
.border-sidebar-var { border-color: var(--border-sidebar); }
|
| 78 |
+
.text-color-var { color: var(--text-color); }
|
| 79 |
+
.text-secondary-var { color: var(--text-secondary); }
|
| 80 |
+
.text-link-var { color: var(--text-link); }
|
| 81 |
+
.hover\:text-link-hover-var:hover { color: var(--text-link-hover); }
|
| 82 |
+
.bg-input-var { background-color: var(--input-bg); }
|
| 83 |
+
.border-input-var { border-color: var(--input-border); }
|
| 84 |
+
.text-input-key-var { color: var(--input-text-key); }
|
| 85 |
+
.bg-primary-color-var { background-color: var(--primary-color); }
|
| 86 |
+
.hover\:bg-primary-hover-var:hover { background-color: var(--primary-hover); }
|
| 87 |
+
.focus\:ring-primary-color-var:focus { --tw-ring-color: var(--primary-color); }
|
| 88 |
+
.focus\:border-primary-color-var:focus { border-color: var(--primary-color); }
|
| 89 |
+
.bg-sidebar-active-var { background-color: var(--bg-sidebar-active); }
|
| 90 |
+
.bg-warning-var { background-color: var(--warning-bg); }
|
| 91 |
+
.border-warning-var { border-color: var(--warning-border); }
|
| 92 |
+
.text-warning-var { color: var(--warning-text); }
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
/* Style pour les boutons et cartes carrés (Artboard) */
|
| 96 |
+
.btn-square, .card-square {
|
| 97 |
+
border-radius: 0; /* Supprime l'arrondi */
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/* Styles spécifiques pour le chargement/spinner */
|
| 101 |
+
.spinner {
|
| 102 |
+
border-top-color: var(--primary-color); /* Utiliser la couleur primaire pour le spinner */
|
| 103 |
+
animation: spin 1s linear infinite;
|
| 104 |
+
}
|
| 105 |
+
@keyframes spin {
|
| 106 |
+
to { transform: rotate(360deg); }
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* Style pour la Sidebar - FIXE et complète */
|
| 110 |
+
.sidebar {
|
| 111 |
+
transition: transform 0.3s ease-in-out;
|
| 112 |
+
transform: translateX(-100%);
|
| 113 |
+
position: fixed;
|
| 114 |
+
top: 0;
|
| 115 |
+
left: 0;
|
| 116 |
+
z-index: 30;
|
| 117 |
+
height: 100vh;
|
| 118 |
}
|
| 119 |
|
| 120 |
+
.sidebar.open {
|
| 121 |
+
transform: translateX(0);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/* Sur les grands écrans (lg), la sidebar est statique et toujours visible */
|
| 125 |
+
@media (min-width: 1024px) {
|
| 126 |
+
.sidebar {
|
| 127 |
+
transform: translateX(0) !important;
|
| 128 |
+
position: fixed; /* Changement : Rendre la sidebar fixe sur grand écran */
|
| 129 |
+
height: 100vh;
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
|
| 133 |
+
/* Conteneur principal pour décaler le contenu sur les grands écrans (lg) */
|
| 134 |
+
/* La marge doit correspondre à la largeur de la sidebar (w-64) */
|
| 135 |
+
@media (min-width: 1024px) {
|
| 136 |
+
.main-content {
|
| 137 |
+
margin-left: 256px;
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
</style>
|
| 141 |
</head>
|
| 142 |
+
|
| 143 |
+
<body class="bg-page-var text-color-var min-h-screen transition-colors-theme">
|
| 144 |
|
| 145 |
+
<button id="theme-toggle" class="theme-switch text-color-var hover:text-link-hover-var transition-colors-theme">
|
| 146 |
+
<span class="material-symbols-rounded">dark_mode</span>
|
| 147 |
</button>
|
| 148 |
+
|
| 149 |
+
<aside id="sidebar" class="sidebar w-64 bg-sidebar-var border-r border-sidebar-var p-6 lg:block transition-colors-theme">
|
| 150 |
+
<div class="flex items-center mb-10">
|
| 151 |
+
<img src="https://i.imgur.com/7Gn3toV.png" alt="Nexus Pro Logo" class="h-8">
|
| 152 |
+
<span class="text-xl font-bold text-color-var ml-2 transition-colors-theme">Nexus Pro</span>
|
| 153 |
</div>
|
| 154 |
+
|
| 155 |
+
<nav class="space-y-3">
|
| 156 |
+
<a href="{{ url_for('user_bp.dashboard') }}" class="flex items-center p-3 text-secondary-var hover:text-color-var hover:bg-sidebar-active-var rounded-lg transition duration-150 transition-colors-theme">
|
| 157 |
+
<span class="material-symbols-rounded">dashboard</span>
|
| 158 |
+
<span class="ml-3">Dashboard</span>
|
| 159 |
+
</a>
|
| 160 |
+
<a href="{{ url_for('user_bp.api_key') }}" class="flex items-center p-3 bg-sidebar-active-var text-color-var rounded-lg transition duration-150 transition-colors-theme">
|
| 161 |
+
<span class="material-symbols-rounded">key</span>
|
| 162 |
+
<span class="ml-3">Clés API</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
</a>
|
| 164 |
+
<a href="{{ url_for('user_bp.api_logs') }}" class="flex items-center p-3 text-secondary-var hover:text-color-var hover:bg-sidebar-active-var rounded-lg transition duration-150 transition-colors-theme">
|
| 165 |
+
<span class="material-symbols-rounded">list_alt</span>
|
| 166 |
+
<span class="ml-3">Logs d'API</span>
|
| 167 |
+
</a>
|
| 168 |
+
<a href="{{ url_for('user_bp.profile') }}" class="flex items-center p-3 text-secondary-var hover:text-color-var hover:bg-sidebar-active-var rounded-lg transition duration-150 transition-colors-theme">
|
| 169 |
+
<span class="material-symbols-rounded">person</span>
|
| 170 |
+
<span class="ml-3">Profil</span>
|
| 171 |
+
</a>
|
| 172 |
+
<a href="{{ url_for('user_bp.deconnexion') }}" id="logout-button-sidebar" class="flex items-center p-3 text-red-500 hover:text-red-400 hover:bg-sidebar-active-var rounded-lg transition duration-150 transition-colors-theme">
|
| 173 |
+
<span class="material-symbols-rounded">logout</span>
|
| 174 |
+
<span class="ml-3">Déconnexion</span>
|
| 175 |
+
</a>
|
| 176 |
+
</nav>
|
| 177 |
+
|
| 178 |
+
<div class="absolute bottom-6 w-52 text-xs text-secondary-var transition-colors-theme">
|
| 179 |
+
<p>Connecté en tant que: <span class="font-semibold text-color-var transition-colors-theme">{{ user.email if user else 'Chargement...' }}</span></p>
|
| 180 |
+
<p>Plan: <span class="font-semibold text-color-var transition-colors-theme">{{ (user.plan | upper) if user else 'Chargement...' }}</span></p>
|
| 181 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
+
</aside>
|
| 184 |
+
|
| 185 |
+
<div id="main-content" class="main-content p-8 transition-colors-theme">
|
| 186 |
+
|
| 187 |
+
<header class="lg:hidden flex justify-between items-center mb-8">
|
| 188 |
+
<div class="flex items-center">
|
| 189 |
+
<img src="https://i.imgur.com/7Gn3toV.png" alt="Nexus Pro Logo" class="h-8">
|
| 190 |
+
<span class="text-xl font-bold text-color-var ml-2 transition-colors-theme">Nexus Pro</span>
|
| 191 |
+
</div>
|
| 192 |
+
<button id="sidebar-toggle" class="p-2 rounded-lg bg-sidebar-active-var hover:bg-sidebar-active-var/80 transition-colors-theme">
|
| 193 |
+
<span class="material-symbols-rounded text-color-var">menu</span>
|
| 194 |
+
</button>
|
| 195 |
</header>
|
| 196 |
|
| 197 |
+
<h1 class="text-3xl font-bold mb-8 text-color-var transition-colors-theme">Gestion des Clés API</h1>
|
| 198 |
+
|
| 199 |
+
{% with messages = get_flashed_messages(with_categories=true) %}
|
| 200 |
+
{% if messages %}
|
| 201 |
+
{% for category, message in messages %}
|
| 202 |
+
<div class="p-4 mb-4 text-sm rounded-lg {{ 'bg-red-800 text-red-300' if category == 'error' or category == 'danger' else 'bg-green-800 text-green-300' }} border border-transparent" role="alert">
|
| 203 |
+
{{ message }}
|
| 204 |
+
</div>
|
| 205 |
+
{% endfor %}
|
| 206 |
+
{% endif %}
|
| 207 |
+
{% endwith %}
|
| 208 |
|
| 209 |
+
<div class="bg-card-var p-6 rounded-lg shadow-xl border border-sidebar-var transition-colors-theme">
|
| 210 |
+
<h2 class="text-xl font-semibold mb-4 text-color-var transition-colors-theme">Votre Clé d'Accès Principale</h2>
|
| 211 |
+
<p class="text-secondary-var mb-6 transition-colors-theme">Utilisez cette clé pour authentifier vos requêtes auprès de l'API ErnestMind Nexus.</p>
|
| 212 |
|
| 213 |
+
<div class="flex items-center space-x-4 mb-6">
|
| 214 |
+
<input id="api-key-display"
|
| 215 |
+
type="text"
|
| 216 |
+
readonly
|
| 217 |
+
class="flex-grow bg-input-var border border-input-var text-input-key-var p-3 rounded-lg font-mono text-sm break-all focus:outline-none focus:ring-2 focus:ring-primary-color-var focus:border-primary-color-var transition-colors-theme"
|
| 218 |
+
value="{{ user.api_key if user and user.api_key else 'Clé API non trouvée. Réinitialisez-la.' }}">
|
| 219 |
+
|
| 220 |
+
<button id="copy-btn" class="bg-primary-color-var hover:bg-primary-hover-var text-white font-bold py-3 px-4 rounded-lg transition duration-200 flex items-center btn-square transition-colors-theme">
|
| 221 |
+
<span class="material-symbols-rounded">content_copy</span>
|
| 222 |
+
<span class="ml-2 hidden sm:inline">Copier</span>
|
| 223 |
+
</button>
|
| 224 |
+
</div>
|
| 225 |
|
| 226 |
+
<div class="flex items-center justify-between border-t border-sidebar-var pt-4 transition-colors-theme">
|
| 227 |
+
<button id="regenerate-btn" class="text-sm text-red-500 hover:text-red-400 transition duration-200 flex items-center font-medium transition-colors-theme">
|
| 228 |
+
<span class="material-symbols-rounded text-lg mr-1">refresh</span>
|
| 229 |
+
Régénérer la Clé
|
| 230 |
+
<div id="spinner" class="spinner w-4 h-4 border-2 rounded-full ml-2 hidden" style="border-bottom-color: transparent;"></div>
|
| 231 |
+
</button>
|
| 232 |
+
<p id="status-message" class="text-sm text-input-key-var font-medium transition-colors-theme"></p>
|
| 233 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
</div>
|
| 235 |
|
| 236 |
+
<div class="mt-8 p-4 bg-warning-var border border-warning-border-var rounded-lg text-warning-text-var transition-colors-theme">
|
| 237 |
+
<h3 class="font-bold flex items-center">
|
| 238 |
+
<span class="material-symbols-rounded mr-2">warning</span>
|
| 239 |
+
Attention Sécurité
|
| 240 |
+
</h3>
|
| 241 |
+
<p class="text-sm mt-2">La clé API est un mot de passe pour vos applications. Ne la partagez jamais publiquement et traitez-la comme une information confidentielle.</p>
|
| 242 |
+
</div>
|
| 243 |
|
| 244 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
+
<script>
|
| 247 |
+
// Logique du thème (copiée de inscription.html)
|
| 248 |
+
const themeToggle = document.getElementById('theme-toggle');
|
| 249 |
+
const html = document.documentElement;
|
| 250 |
|
| 251 |
+
const updateIcon = () => {
|
| 252 |
+
const icon = themeToggle.querySelector('.material-symbols-rounded');
|
| 253 |
+
if (html.classList.contains('light')) {
|
| 254 |
+
icon.textContent = 'light_mode';
|
| 255 |
+
} else {
|
| 256 |
+
icon.textContent = 'dark_mode';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
}
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
const savedTheme = localStorage.getItem('theme');
|
| 261 |
+
if (savedTheme === 'light') {
|
| 262 |
+
html.classList.remove('dark');
|
| 263 |
+
html.classList.add('light');
|
| 264 |
+
} else {
|
| 265 |
+
// Par défaut, nous nous assurons que 'dark' est appliqué s'il n'y a pas de thème enregistré
|
| 266 |
+
html.classList.add('dark');
|
| 267 |
+
html.classList.remove('light');
|
| 268 |
}
|
| 269 |
+
updateIcon();
|
| 270 |
|
| 271 |
+
themeToggle.addEventListener('click', () => {
|
| 272 |
+
if (html.classList.contains('dark')) {
|
| 273 |
+
html.classList.remove('dark');
|
| 274 |
+
html.classList.add('light');
|
| 275 |
+
localStorage.setItem('theme', 'light');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
} else {
|
| 277 |
+
html.classList.remove('light');
|
| 278 |
+
html.classList.add('dark');
|
| 279 |
+
localStorage.setItem('theme', 'dark');
|
| 280 |
}
|
| 281 |
+
updateIcon();
|
| 282 |
+
});
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
+
// Logique pour la copie de la clé API
|
| 286 |
+
const copyBtn = document.getElementById('copy-btn');
|
| 287 |
+
const apiKeyDisplay = document.getElementById('api-key-display');
|
| 288 |
+
const statusMessage = document.getElementById('status-message');
|
| 289 |
+
const regenerateBtn = document.getElementById('regenerate-btn');
|
| 290 |
+
const spinner = document.getElementById('spinner');
|
| 291 |
|
| 292 |
+
// 1. Fonctionnalité de Copie
|
| 293 |
+
copyBtn.addEventListener('click', () => {
|
| 294 |
+
apiKeyDisplay.select();
|
| 295 |
+
apiKeyDisplay.setSelectionRange(0, 99999); /* Pour les mobiles */
|
| 296 |
+
document.execCommand('copy');
|
| 297 |
|
| 298 |
+
// Afficher le message de statut
|
| 299 |
+
statusMessage.textContent = 'Clé copiée !';
|
| 300 |
+
setTimeout(() => {
|
| 301 |
+
statusMessage.textContent = '';
|
| 302 |
+
}, 3000);
|
| 303 |
});
|
| 304 |
|
| 305 |
+
// 2. Logique de la Sidebar sur mobile
|
| 306 |
+
const sidebarToggle = document.getElementById('sidebar-toggle');
|
| 307 |
+
const sidebar = document.getElementById('sidebar');
|
| 308 |
+
|
| 309 |
sidebarToggle.addEventListener('click', () => {
|
| 310 |
sidebar.classList.toggle('open');
|
| 311 |
});
|
| 312 |
+
|
| 313 |
+
// 3. Logique de REGÉNÉRATION (Message de démo)
|
| 314 |
+
regenerateBtn.addEventListener('click', (e) => {
|
| 315 |
+
e.preventDefault();
|
| 316 |
+
// Simuler une action pour l'utilisateur
|
| 317 |
+
statusMessage.textContent = 'Fonction de régénération en cours de développement. Veuillez revenir plus tard.';
|
| 318 |
+
setTimeout(() => {
|
| 319 |
+
statusMessage.textContent = '';
|
| 320 |
+
}, 4000);
|
| 321 |
+
});
|
| 322 |
+
|
| 323 |
+
// 4. Logique de Déconnexion (Conservée)
|
| 324 |
const logoutHandler = async (e) => {
|
| 325 |
e.preventDefault();
|
| 326 |
+
// La déconnexion est maintenant gérée par la route Flask directe
|
| 327 |
window.location.href = document.getElementById('logout-button-sidebar').href;
|
| 328 |
};
|
| 329 |
+
// On attache l'événement à la déconnexion dans la sidebar.
|
| 330 |
document.getElementById('logout-button-sidebar').addEventListener('click', logoutHandler);
|
| 331 |
|
| 332 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
</script>
|
| 334 |
</body>
|
| 335 |
</html>
|