Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Register</title> | |
| <link rel="stylesheet" href="log_reg_style.css"> | |
| <!-- <script src="https://accounts.google.com/gsi/client" async defer></script> | |
| <script src="https://apis.google.com/js/platform.js" async defer></script> --> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h2>Create an Account</h2> | |
| <form id="registrationForm"> | |
| <input type="text" id="name" name="name" placeholder="Full Name" required> | |
| <input type="email" id="email" name="email" placeholder="Email" required> | |
| <input type="text" id="username" name="username" placeholder="Username" required> | |
| <input type="password" id="password" name="password" placeholder="Password" required> | |
| <button type="submit">Register</button> | |
| </form> | |
| <p>Already have an account? <a href="login.html">Login here</a></p> | |
| </div> | |
| <script> | |
| // Function to generate and retrieve the device ID | |
| function getDeviceId() { | |
| let deviceId = localStorage.getItem("deviceId"); | |
| if (!deviceId) { | |
| // Generate a new unique ID | |
| deviceId = 'device_' + new Date().getTime() + '_' + Math.random().toString(36).substr(2, 9); | |
| // Store it in local storage | |
| localStorage.setItem("deviceId", deviceId); | |
| } | |
| return deviceId; | |
| } | |
| // Handle form submission | |
| document.getElementById('registrationForm').addEventListener('submit', function(event) { | |
| event.preventDefault(); // Prevent the form from submitting and showing data in the URL | |
| // Retrieve form input values | |
| const name = document.getElementById('name').value; | |
| const username = document.getElementById('username').value; | |
| const email = document.getElementById('email').value; | |
| const password = document.getElementById('password').value; | |
| const deviceId = getDeviceId(); // Get the device ID | |
| // Prepare the registration data | |
| const registrationData = { | |
| name: name, | |
| email: email, | |
| username: username, | |
| password: password, | |
| device_id: deviceId // Include the device ID | |
| }; | |
| // Make a POST request to the registration endpoint | |
| fetch('https://thevera-botveradb.hf.space/register_user', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify(registrationData) | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| console.log("Response from server:", data); // Log the full response | |
| alert(data.message); // Show success or error message | |
| if (data.message.includes("registered")) { | |
| window.location.href = "login.html"; // Redirect to login page if registered successfully | |
| } | |
| }) | |
| .catch(error => { | |
| console.error('Error:', error); | |
| alert('An error occurred during registration.'); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> | |