Skip to content

Latest commit

 

History

History
90 lines (79 loc) · 2.87 KB

SignupPage.md

File metadata and controls

90 lines (79 loc) · 2.87 KB
permalink
/signup

Sign Up

User ID:

Name:

DOB:

Password:

Nick:

Signup

<script type="module"> // uri variable and options object are obtained from config.js import { uri, options } from '{{site.baseurl}}/assets/js/api/config.js'; function signup_user(){ // Set Authenticate endpoint const url = uri + '/api/users'; // Set the body of the request to include login data from the DOM const body = { uid: document.getElementById("uid").value, name: document.getElementById("name").value, password: document.getElementById("password").value, dob: document.getElementById("dob").value, Nick: document.getElementById("Nick").value, }; // Change options according to Authentication requirements const authOptions = { ...options, // This will copy all properties from options method: 'POST', // Override the method property cache: 'no-cache', // Set the cache property body: JSON.stringify(body) }; // Fetch JWT fetch(url, authOptions) .then(response => { // handle error response from Web API if (!response.ok) { const errorMsg = 'Signup error: ' + response.status; console.log(errorMsg); return; } // Success!!! // Redirect to the database page window.location.href = "{{site.baseurl}}/main_menu/"; }) // catch fetch errors (ie ACCESS to server blocked) .catch(err => { console.error(err); }); } // Attach login_user to the window object, allowing access to form action window.signup_user = signup_user; </script>