Spaces:
Runtime error
Runtime error
| {% extends "base.html" %} | |
| {% block title %}Register - Rating Predictor{% endblock %} | |
| {% block content %} | |
| <div class="flex items-center justify-center min-h-[calc(100vh-200px)]"> | |
| <div class="bg-white dark:bg-slate-800 rounded-2xl shadow-xl p-8 w-full max-w-md fade-in"> | |
| <div class="text-center mb-8"> | |
| <i class="fas fa-user-plus text-5xl text-indigo-600 mb-4"></i> | |
| <h2 class="text-3xl font-bold text-gray-800 dark:text-gray-100">Đăng Ký</h2> | |
| <p class="text-gray-600 dark:text-gray-400 mt-2">Create your Rating Predictor account</p> | |
| </div> | |
| <form id="registerForm" class="space-y-6"> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"> | |
| <i class="fas fa-user mr-2"></i>Username | |
| </label> | |
| <input | |
| type="text" | |
| id="username" | |
| name="username" | |
| required | |
| minlength="3" | |
| maxlength="50" | |
| class="w-full px-4 py-3 border border-gray-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-transparent transition bg-white dark:bg-slate-700 text-gray-900 dark:text-gray-100" | |
| placeholder="Choose a username (3-50 characters)" | |
| > | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"> | |
| <i class="fas fa-envelope mr-2"></i>Email | |
| </label> | |
| <input | |
| type="email" | |
| id="email" | |
| name="email" | |
| required | |
| class="w-full px-4 py-3 border border-gray-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-transparent transition bg-white dark:bg-slate-700 text-gray-900 dark:text-gray-100" | |
| placeholder="Enter your email" | |
| > | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"> | |
| <i class="fas fa-lock mr-2"></i>Password | |
| </label> | |
| <input | |
| type="password" | |
| id="password" | |
| name="password" | |
| required | |
| minlength="6" | |
| class="w-full px-4 py-3 border border-gray-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-transparent transition bg-white dark:bg-slate-700 text-gray-900 dark:text-gray-100" | |
| placeholder="Enter password (minimum 6 characters)" | |
| > | |
| </div> | |
| <button | |
| type="submit" | |
| id="register-btn" | |
| class="w-full bg-indigo-600 text-white py-3 rounded-lg hover:bg-indigo-700 transition font-medium shadow-lg hover:shadow-xl" | |
| > | |
| <i class="fas fa-user-plus mr-2"></i>Register | |
| </button> | |
| </form> | |
| <div class="mt-6 text-center"> | |
| <p class="text-gray-600 dark:text-gray-400"> | |
| Already have an account? | |
| <a href="/login" class="text-indigo-600 hover:text-indigo-800 dark:text-indigo-400 dark:hover:text-indigo-300 font-medium"> | |
| Login here | |
| </a> | |
| </p> | |
| </div> | |
| </div> | |
| </div> | |
| {% endblock %} | |
| {% block scripts %} | |
| <script> | |
| document.getElementById('registerForm').addEventListener('submit', async (e) => { | |
| e.preventDefault(); | |
| const username = document.getElementById('username').value; | |
| const email = document.getElementById('email').value; | |
| const password = document.getElementById('password').value; | |
| const registerBtn = document.getElementById('register-btn'); | |
| // Show loading state | |
| registerBtn.disabled = true; | |
| registerBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Creating account...'; | |
| try { | |
| const response = await fetch('/api/auth/register', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ username, email, password }) | |
| }); | |
| const data = await response.json(); | |
| if (response.ok) { | |
| // Show success toast | |
| toast.success('Registration Successful', 'Your account has been created. Redirecting to login...'); | |
| // Redirect to login | |
| setTimeout(() => { | |
| window.location.href = '/login'; | |
| }, 1500); | |
| } else { | |
| // Show error toast | |
| toast.error('Registration Failed', data.detail || 'Please try again.'); | |
| registerBtn.disabled = false; | |
| registerBtn.innerHTML = '<i class="fas fa-user-plus mr-2"></i>Register'; | |
| } | |
| } catch (error) { | |
| toast.error('Error', 'An error occurred. Please try again.'); | |
| registerBtn.disabled = false; | |
| registerBtn.innerHTML = '<i class="fas fa-user-plus mr-2"></i>Register'; | |
| } | |
| }); | |
| </script> | |
| {% endblock %} | |