File size: 3,196 Bytes
cecfa21
 
 
 
 
 
 
180f531
 
cecfa21
 
 
 
 
5438e06
 
 
 
cecfa21
 
 
 
 
 
0942ca6
291f934
 
 
 
 
 
 
 
cecfa21
291f934
 
 
5438e06
 
 
291f934
5438e06
291f934
 
 
 
5438e06
291f934
5438e06
291f934
 
 
 
 
 
 
5438e06
291f934
 
 
 
 
 
 
 
 
 
6bd3097
5438e06
291f934
 
 
 
 
 
 
5438e06
291f934
cecfa21
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<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="styles1.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>