diff --git a/front/static/edit_report.html b/front/static/edit_report.html index 80d39df..474746f 100644 --- a/front/static/edit_report.html +++ b/front/static/edit_report.html @@ -36,7 +36,7 @@ -
Welcome to Reimbursinator
An open source expense management solution sponsored by the Software Freedom Conservancy
diff --git a/front/static/js/login.js b/front/static/js/login.js index 20b411d..0bdaa9b 100644 --- a/front/static/js/login.js +++ b/front/static/js/login.js @@ -2,7 +2,7 @@ function postToLoginEndpoint(event) { event.preventDefault(); const credentials = { - "username" : this.elements.username.value, + "email" : this.elements.email.value, "password" : this.elements.password.value } const url = "https://" + window.location.hostname + ":8444/api/v1/account/login/"; diff --git a/front/static/js/signupPage.js b/front/static/js/signupPage.js index 0055cce..8777450 100644 --- a/front/static/js/signupPage.js +++ b/front/static/js/signupPage.js @@ -1,20 +1,64 @@ -const password = document.getElementById("password"); -const confirm_password = document.getElementById("confirmPassword"); -function validatePassword(){ - if(password.value != confirm_password.value) { - confirm_password.setCustomValidity("Passwords Don't Match"); - } - else { - confirm_password.setCustomValidity(''); +const password1 = document.getElementById("password1"); +const password2 = document.getElementById("password2"); + +function validatePassword() { + if (password1.value != password2.value) { + password2.setCustomValidity("Passwords don't match"); + } else { + password2.setCustomValidity(''); } } -password.onchange = validatePassword; -confirm_password.onkeyup = validatePassword; +password1.onchange = validatePassword; +password2.onkeyup = validatePassword; -function validateEmail(email) -{ - if(email.validity.patternMismatch) +function validateEmail(email) { + if (email.validity.patternMismatch) { email.setCustomValidity('Please input correct email'); - else + } else { email.setCustomValidity(''); -} \ No newline at end of file + } +} + +function postToRegistrationEndpoint(event) { + event.preventDefault(); + + const credentials = { + "email" : this.elements.email.value, + "first_name" : this.elements.first_name.value, + "last_name" : this.elements.last_name.value, + "password1" : this.elements.password1.value, + "password2" : this.elements.password2.value + } + const url = "https://" + window.location.hostname + ":8444/api/v1/account/register/"; + const xhr = new XMLHttpRequest(); + + console.log("Attempting a connection to the following endpoint: " + url); + console.log("User credentials:\n" + JSON.stringify(credentials)); + + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function() { + if (this.readyState === 4) { + if (this.status === 201) { + console.log("REGISTRATION SUCCESS!"); + console.log("Server response:\n" + this.response); + token = JSON.parse(this.response).key; + localStorage.setItem("token", token); + window.location.replace("home.html"); + } else { + console.error("REGISTRATION FAILURE!"); + console.error("Server status: " + this.status); + console.error("Server response:\n" + this.response); + } + } + }; + + xhr.onerror = function() { + alert("Error connecting to the authentication server!"); + }; + + xhr.send(JSON.stringify(credentials)); +} + +const form = document.querySelector("form"); +form.addEventListener("submit", postToRegistrationEndpoint); diff --git a/front/static/login.html b/front/static/login.html index 9a8af2f..a09051e 100644 --- a/front/static/login.html +++ b/front/static/login.html @@ -14,7 +14,7 @@ -Create a new report