66 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE html>
 | 
						|
<html lang="en">
 | 
						|
  <head>
 | 
						|
    <meta charset="utf-8">
 | 
						|
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
 | 
						|
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
						|
    <title>Registration</title>
 | 
						|
    </head>
 | 
						|
  <body>
 | 
						|
    <div id="app">
 | 
						|
      <h1>Create new user</h1>
 | 
						|
        <form action="/register" method="post" id="signup">
 | 
						|
          <h1>Sign Up</h1>
 | 
						|
	  <div class="field">
 | 
						|
	    <label for="name">Name:</label>
 | 
						|
	    <input type="text" id="name" name="name" placeholder="Enter your profile name" />
 | 
						|
	    <small></small>
 | 
						|
	  </div>
 | 
						|
	  <div class="field">
 | 
						|
	    <label for="email">PubKey:</label>
 | 
						|
	    <input type="text" id="pubkey" name="pubkey" placeholder="Enter your pubkey" />
 | 
						|
	    <small></small>
 | 
						|
	  </div>
 | 
						|
	  <button type="submit">Register</button>
 | 
						|
        </form> 
 | 
						|
    </div>
 | 
						|
  </body>
 | 
						|
  <script>
 | 
						|
    const form = document.getElementById('signup');
 | 
						|
 | 
						|
    form.addEventListener('submit', async (event) => {
 | 
						|
      // stop form submission
 | 
						|
	event.preventDefault();
 | 
						|
 | 
						|
	const name = form.elements['name'];
 | 
						|
	const pubkey = form.elements['pubkey'];
 | 
						|
 | 
						|
	// getting the element's value
 | 
						|
	let userName = name.value;
 | 
						|
	let pubKey = pubkey.value;
 | 
						|
 | 
						|
	console.log(`${userName}:${pubKey}`);
 | 
						|
	const data = { name: userName, pubkey: pubKey};
 | 
						|
 | 
						|
	// Send user data
 | 
						|
	await postJSON(data);
 | 
						|
    });
 | 
						|
 | 
						|
    async function postJSON(data) {
 | 
						|
	try {
 | 
						|
	    const response = await fetch("http://localhost:8085/register", {
 | 
						|
		method: "POST",
 | 
						|
		headers: {
 | 
						|
		    "Content-Type": "application/json",
 | 
						|
		},
 | 
						|
		body: JSON.stringify(data),
 | 
						|
	    });
 | 
						|
 | 
						|
	    const result = await response.json();
 | 
						|
	    console.log("Success:", result);
 | 
						|
	} catch (error) {
 | 
						|
	    console.error("Error:", error);
 | 
						|
	}
 | 
						|
    }
 | 
						|
  </script>
 | 
						|
</html>
 |