Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>CatGPT Admin Login</title> | |
| <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| padding: 20px; | |
| } | |
| .login-container { | |
| background: white; | |
| border-radius: 12px; | |
| box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); | |
| padding: 40px; | |
| width: 100%; | |
| max-width: 400px; | |
| text-align: center; | |
| } | |
| .logo { | |
| margin-bottom: 30px; | |
| } | |
| .logo i { | |
| font-size: 3rem; | |
| color: #667eea; | |
| margin-bottom: 15px; | |
| } | |
| .logo h1 { | |
| font-size: 1.5rem; | |
| color: #333; | |
| margin-bottom: 10px; | |
| } | |
| .logo p { | |
| color: #666; | |
| font-size: 0.9rem; | |
| } | |
| .login-form { | |
| margin-top: 30px; | |
| } | |
| .form-group { | |
| margin-bottom: 20px; | |
| text-align: left; | |
| } | |
| .form-group label { | |
| display: block; | |
| margin-bottom: 8px; | |
| color: #333; | |
| font-weight: 500; | |
| font-size: 0.9rem; | |
| } | |
| .form-group input { | |
| width: 100%; | |
| padding: 12px 16px; | |
| border: 2px solid #e1e5e9; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| transition: all 0.3s ease; | |
| background: white; | |
| } | |
| .form-group input:focus { | |
| outline: none; | |
| border-color: #667eea; | |
| box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); | |
| } | |
| .login-btn { | |
| width: 100%; | |
| padding: 14px; | |
| background: #667eea; | |
| color: white; | |
| border: none; | |
| border-radius: 8px; | |
| font-size: 1rem; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 8px; | |
| } | |
| .login-btn:hover { | |
| background: #5a67d8; | |
| transform: translateY(-1px); | |
| } | |
| .login-btn:active { | |
| transform: translateY(0); | |
| } | |
| .login-btn:disabled { | |
| background: #cbd5e0; | |
| cursor: not-allowed; | |
| transform: none; | |
| } | |
| .error-message { | |
| background: #fed7d7; | |
| color: #c53030; | |
| padding: 12px; | |
| border-radius: 8px; | |
| margin-bottom: 20px; | |
| font-size: 0.9rem; | |
| display: none; | |
| } | |
| .loading { | |
| opacity: 0.7; | |
| pointer-events: none; | |
| } | |
| .spinner { | |
| animation: spin 1s linear infinite; | |
| } | |
| @keyframes spin { | |
| from { transform: rotate(0deg); } | |
| to { transform: rotate(360deg); } | |
| } | |
| @keyframes shake { | |
| 0%, 100% { transform: translateX(0); } | |
| 10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); } | |
| 20%, 40%, 60%, 80% { transform: translateX(5px); } | |
| } | |
| .success { | |
| background: #22c55e ; | |
| border-color: #22c55e ; | |
| color: white ; | |
| } | |
| .success:hover { | |
| background: #16a34a ; | |
| border-color: #16a34a ; | |
| } | |
| .success:disabled { | |
| background: #22c55e ; | |
| border-color: #22c55e ; | |
| color: white ; | |
| opacity: 1 ; | |
| cursor: default ; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="login-container"> | |
| <div class="logo"> | |
| <i class="fas fa-robot"></i> | |
| <h1>CatGPT Admin</h1> | |
| <p>Please login to access the model manager</p> | |
| </div> | |
| <div id="errorMessage" class="error-message"></div> | |
| <form class="login-form" id="loginForm"> | |
| <div class="form-group"> | |
| <label for="adminKey">Admin Key</label> | |
| <input | |
| type="password" | |
| id="adminKey" | |
| name="adminKey" | |
| placeholder="Enter your admin key" | |
| required | |
| autocomplete="current-password" | |
| > | |
| </div> | |
| <button type="submit" class="login-btn" id="loginBtn"> | |
| <i class="fas fa-sign-in-alt"></i> | |
| <span>Login</span> | |
| </button> | |
| </form> | |
| </div> | |
| <script> | |
| const loginForm = document.getElementById('loginForm'); | |
| const adminKeyInput = document.getElementById('adminKey'); | |
| const loginBtn = document.getElementById('loginBtn'); | |
| const errorMessage = document.getElementById('errorMessage'); | |
| // Focus on the input field when page loads | |
| adminKeyInput.focus(); | |
| // Check if already logged in | |
| checkExistingAuth(); | |
| // Handle form submission | |
| loginForm.addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const adminKey = adminKeyInput.value.trim(); | |
| if (!adminKey) { | |
| showError('Please enter your admin key'); | |
| return; | |
| } | |
| // Show loading state | |
| setLoading(true); | |
| hideError(); | |
| try { | |
| console.log('π Sending login request...'); | |
| const response = await fetch('/api/login', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ admin_key: adminKey }) | |
| }); | |
| console.log('π‘ Response received:', response.status, response.statusText); | |
| if (response.ok) { | |
| console.log('β Login successful, showing success feedback...'); | |
| // Parse response data first | |
| const data = await response.json(); | |
| console.log('π Response data:', data); | |
| // Store token in localStorage as fallback | |
| if (data.token) { | |
| localStorage.setItem('auth_token', data.token); | |
| localStorage.setItem('token_expires', Date.now() + (data.expires_in * 1000)); | |
| console.log('πΎ Token stored in localStorage'); | |
| } | |
| // Show success feedback | |
| console.log('π¨ Updating button appearance...'); | |
| loginBtn.innerHTML = '<i class="fas fa-check"></i><span>Success! Redirecting...</span>'; | |
| loginBtn.style.background = '#22c55e'; | |
| loginBtn.style.borderColor = '#22c55e'; | |
| loginBtn.disabled = true; | |
| loginBtn.classList.add('success'); | |
| // Hide any error messages | |
| hideError(); | |
| // Force a repaint | |
| loginBtn.offsetHeight; | |
| console.log('β³ Starting redirect timer (1.5 seconds)...'); | |
| // Shorter redirect time | |
| setTimeout(() => { | |
| console.log('π Redirecting to main app...'); | |
| window.location.href = '/'; | |
| }, 1500); | |
| return; | |
| } else { | |
| console.error('β Login failed with status:', response.status); | |
| const error = await response.json(); | |
| console.error('β Error details:', error); | |
| showError(error.detail || 'Invalid admin key'); | |
| // Shake the form to indicate error | |
| loginForm.style.animation = 'shake 0.5s'; | |
| setTimeout(() => { | |
| loginForm.style.animation = ''; | |
| }, 500); | |
| // Only reset loading state on error | |
| setLoading(false); | |
| } | |
| } catch (error) { | |
| console.error('π₯ Login error:', error); | |
| showError('Network error. Please try again.'); | |
| // Only reset loading state on error | |
| setLoading(false); | |
| } | |
| }); | |
| async function checkExistingAuth() { | |
| // Check localStorage token | |
| const token = localStorage.getItem('auth_token'); | |
| const expires = localStorage.getItem('token_expires'); | |
| if (token && expires && Date.now() < parseInt(expires)) { | |
| console.log('π Found valid token in localStorage, checking with server...'); | |
| try { | |
| const response = await fetch('/api/auth-status', { | |
| headers: { | |
| 'Authorization': `Bearer ${token}` | |
| } | |
| }); | |
| if (response.ok) { | |
| const data = await response.json(); | |
| if (data.authenticated) { | |
| console.log('β Already authenticated, redirecting...'); | |
| window.location.href = '/'; | |
| return; | |
| } | |
| } | |
| } catch (error) { | |
| console.log('β Auth check failed:', error); | |
| } | |
| // Clean up invalid token | |
| localStorage.removeItem('auth_token'); | |
| localStorage.removeItem('token_expires'); | |
| } | |
| } | |
| function showError(message) { | |
| errorMessage.textContent = message; | |
| errorMessage.style.display = 'block'; | |
| } | |
| function hideError() { | |
| errorMessage.style.display = 'none'; | |
| } | |
| function setLoading(loading) { | |
| if (loading) { | |
| loginBtn.disabled = true; | |
| loginBtn.classList.add('loading'); | |
| loginBtn.innerHTML = '<i class="fas fa-spinner spinner"></i><span>Logging in...</span>'; | |
| } else { | |
| // Don't reset if we're in success state | |
| if (!loginBtn.classList.contains('success')) { | |
| loginBtn.disabled = false; | |
| loginBtn.classList.remove('loading'); | |
| loginBtn.innerHTML = '<i class="fas fa-sign-in-alt"></i><span>Login</span>'; | |
| loginBtn.style.background = ''; // Reset any custom background | |
| loginBtn.style.borderColor = ''; // Reset border color | |
| } | |
| } | |
| } | |
| // Handle Enter key | |
| adminKeyInput.addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') { | |
| loginForm.dispatchEvent(new Event('submit')); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> |