Spaces:
Sleeping
Sleeping
Update templates/api_key.html
Browse files- templates/api_key.html +334 -261
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| 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,314 +22,387 @@
|
|
| 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 |
-
--bg-
|
| 35 |
-
--
|
| 36 |
-
--
|
| 37 |
-
--
|
| 38 |
-
--
|
| 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 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
-
/*
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
}
|
| 132 |
|
| 133 |
-
/*
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 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-
|
| 146 |
-
<span class="material-symbols-rounded">
|
| 147 |
</button>
|
| 148 |
-
|
| 149 |
-
<
|
| 150 |
-
<div class="flex items-center mb-
|
| 151 |
-
<img src="https://i.imgur.com/7Gn3toV.png" alt="
|
| 152 |
-
<
|
| 153 |
</div>
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
<a
|
| 161 |
-
|
| 162 |
-
<span class="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 184 |
-
|
| 185 |
-
|
| 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 |
-
<
|
| 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="
|
| 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 |
-
<
|
| 214 |
-
<
|
| 215 |
-
|
| 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 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
<
|
| 233 |
-
|
| 234 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
<script>
|
| 247 |
-
//
|
| 248 |
-
const
|
| 249 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
-
|
| 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 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
}
|
| 269 |
-
updateIcon();
|
| 270 |
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
} else {
|
| 277 |
-
|
| 278 |
-
html.classList.add('dark');
|
| 279 |
-
localStorage.setItem('theme', 'dark');
|
| 280 |
}
|
| 281 |
-
updateIcon();
|
| 282 |
-
});
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
const spinner = document.getElementById('spinner');
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
document.execCommand('copy');
|
| 297 |
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
}
|
| 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
|
| 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>
|
|
|
|
| 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;
|
| 26 |
top: 1rem;
|
| 27 |
right: 1rem;
|
| 28 |
+
z-index: 50;
|
| 29 |
}
|
| 30 |
|
| 31 |
/* Définir les Variables de Thème */
|
| 32 |
+
:root {
|
| 33 |
+
--color-bg-primary: #f7f7f7;
|
| 34 |
+
--color-bg-secondary: #ffffff;
|
| 35 |
+
--color-text-primary: #1f2937;
|
| 36 |
+
--color-text-secondary: #4b5563;
|
| 37 |
+
--color-border: #e5e7eb;
|
| 38 |
+
--color-accent: #3b82f6; /* Bleu par défaut */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
+
|
| 41 |
+
/* Thème sombre (Dark Mode) */
|
| 42 |
+
.dark {
|
| 43 |
+
--color-bg-primary: #111827;
|
| 44 |
+
--color-bg-secondary: #1f2937;
|
| 45 |
+
--color-text-primary: #f9fafb;
|
| 46 |
+
--color-text-secondary: #d1d5db;
|
| 47 |
+
--color-border: #374151;
|
| 48 |
+
--color-accent: #60a5fa; /* Bleu plus clair pour le dark mode */
|
| 49 |
}
|
| 50 |
|
| 51 |
+
/* Classes Tailwind surchargées pour le thème */
|
| 52 |
+
.bg-theme-primary { background-color: var(--color-bg-primary); }
|
| 53 |
+
.bg-theme-secondary { background-color: var(--color-bg-secondary); }
|
| 54 |
+
.text-theme-primary { color: var(--color-text-primary); }
|
| 55 |
+
.text-theme-secondary { color: var(--color-text-secondary); }
|
| 56 |
+
.border-theme-border { border-color: var(--color-border); }
|
| 57 |
+
.text-theme-accent { color: var(--color-accent); }
|
| 58 |
+
.hover\:bg-theme-accent-hover:hover { background-color: #3b82f6; } /* Réajuster au besoin pour le dark mode */
|
| 59 |
|
| 60 |
+
/* Sidebar Responsive */
|
| 61 |
+
#sidebar { transform: translateX(-100%); transition: transform 0.3s ease-in-out; }
|
| 62 |
+
#sidebar.open { transform: translateX(0); }
|
| 63 |
+
@media (min-width: 1024px) { #sidebar { transform: translateX(0) !important; } }
|
|
|
|
|
|
|
|
|
|
| 64 |
</style>
|
| 65 |
</head>
|
| 66 |
+
<body class="bg-theme-primary text-theme-primary min-h-screen transition-colors-theme">
|
|
|
|
| 67 |
|
| 68 |
+
<button id="theme-switch" class="theme-switch text-theme-primary">
|
| 69 |
+
<span class="material-symbols-rounded">light_mode</span>
|
| 70 |
</button>
|
| 71 |
+
|
| 72 |
+
<nav id="sidebar" class="fixed top-0 left-0 h-full w-72 bg-theme-secondary border-r border-theme-border p-4 z-40 lg:z-10 transition-colors-theme lg:shadow-xl">
|
| 73 |
+
<div class="flex items-center space-x-2 mb-8">
|
| 74 |
+
<img src="https://i.imgur.com/7Gn3toV.png" alt="Logo Nexus" class="w-8 h-8">
|
| 75 |
+
<h1 class="text-xl font-bold text-theme-primary">Nexus.</h1>
|
| 76 |
</div>
|
| 77 |
+
<ul class="space-y-2">
|
| 78 |
+
<li><a href="{{ url_for('user_bp.tableau_de_bord') }}" class="flex items-center p-3 rounded-lg text-theme-secondary hover:bg-gray-700/5 transition-colors-theme">
|
| 79 |
+
<span class="material-symbols-rounded mr-3">dashboard</span> Tableau de bord
|
| 80 |
+
</a></li>
|
| 81 |
+
<li><a href="#" class="flex items-center p-3 rounded-lg bg-gray-700/10 text-theme-accent font-semibold transition-colors-theme">
|
| 82 |
+
<span class="material-symbols-rounded mr-3">key</span> Clés API
|
| 83 |
+
</a></li>
|
| 84 |
+
<li><a href="{{ url_for('user_bp.profil') }}" class="flex items-center p-3 rounded-lg text-theme-secondary hover:bg-gray-700/5 transition-colors-theme">
|
| 85 |
+
<span class="material-symbols-rounded mr-3">settings</span> Paramètres du compte
|
| 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 |
+
<header class="mb-8">
|
| 102 |
+
<h1 class="text-3xl font-bold text-theme-primary">Gestion des Clés API</h1>
|
| 103 |
+
<p class="text-theme-secondary mt-1">Créez, gérez et révoquez vos clés d'accès à l'API Nexus.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
</header>
|
| 105 |
|
| 106 |
+
<div id="status-message" class="mb-6 p-3 rounded-lg text-sm hidden" role="alert"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 p-4 bg-theme-secondary border border-theme-border rounded-lg shadow-sm">
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
<p class="text-theme-secondary mb-3 sm:mb-0">
|
| 111 |
+
<span class="font-semibold text-theme-primary">{{ user.api_keys | length }}</span> / {{ max_keys }} clés utilisées.
|
| 112 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
{% set current_keys = user.api_keys | length %}
|
| 115 |
+
{% set keys_limit = max_keys %}
|
| 116 |
+
<button
|
| 117 |
+
id="generate-key-btn"
|
| 118 |
+
class="w-full sm:w-auto flex items-center justify-center px-4 py-2 bg-theme-accent text-white font-semibold rounded-lg transition duration-150 hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed"
|
| 119 |
+
{% if current_keys >= keys_limit %}disabled{% endif %}>
|
| 120 |
+
<span class="material-symbols-rounded mr-2">add</span>
|
| 121 |
+
Générer une nouvelle clé
|
| 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 |
+
</main>
|
| 205 |
|
| 206 |
<script>
|
| 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 |
+
// --- Fonctions Utilitaires ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
+
/**
|
| 219 |
+
* Formate une date ISO 8601 en chaîne lisible.
|
| 220 |
+
* @param {string} isoString - La date au format ISO.
|
| 221 |
+
* @returns {string} Date formatée.
|
| 222 |
+
*/
|
| 223 |
+
function formatDate(isoString) {
|
| 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 |
+
* Affiche un message de statut (Succès ou Erreur).
|
| 236 |
+
* @param {string} message - Le message à afficher.
|
| 237 |
+
* @param {string} type - 'success' ou 'error'.
|
| 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 |
+
statusMessage.classList.add('bg-red-100', 'text-red-800', 'dark:bg-red-800/30', 'dark:text-red-300');
|
|
|
|
|
|
|
| 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 |
+
if (currentTheme === 'dark') {
|
| 262 |
+
themeSwitch.querySelector('.material-symbols-rounded').textContent = 'light_mode';
|
| 263 |
+
} else {
|
| 264 |
+
themeSwitch.querySelector('.material-symbols-rounded').textContent = 'dark_mode';
|
| 265 |
+
}
|
|
|
|
| 266 |
|
| 267 |
+
themeSwitch.addEventListener('click', () => {
|
| 268 |
+
let theme = document.documentElement.classList.contains('dark') ? 'light' : 'dark';
|
| 269 |
+
document.documentElement.className = theme;
|
| 270 |
+
localStorage.setItem('theme', theme);
|
|
|
|
| 271 |
|
| 272 |
+
if (theme === 'dark') {
|
| 273 |
+
themeSwitch.querySelector('.material-symbols-rounded').textContent = 'light_mode';
|
| 274 |
+
} else {
|
| 275 |
+
themeSwitch.querySelector('.material-symbols-rounded').textContent = 'dark_mode';
|
| 276 |
+
}
|
| 277 |
});
|
| 278 |
|
| 279 |
+
// 2. Logique de la Sidebar sur mobile (Conservée)
|
|
|
|
|
|
|
|
|
|
| 280 |
sidebarToggle.addEventListener('click', () => {
|
| 281 |
sidebar.classList.toggle('open');
|
| 282 |
});
|
| 283 |
+
|
| 284 |
+
// 3. Logique de Déconnexion (Conservée)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|