diff --git a/backend/web/static/base.js b/backend/web/static/base.js index e09a07bfd2df2766026d802109fa5c60ae562f49..606f1ab758a5acc7e6d3075d6e681bf14b047222 100644 --- a/backend/web/static/base.js +++ b/backend/web/static/base.js @@ -643,50 +643,3 @@ $.urlParam = function (name) { } return decodeURI(results[1]) || 0; }; - -////////////////////////////////////// -// sign up form for the demo instance -////////////////////////////////////// - -function submitSignup() { - let result = document.querySelector("#signup-result"); - let email = document.querySelector("#signup-email"); - let xhr = new XMLHttpRequest(); - xhr.responseType = "json"; - let url = "/web/demo-user"; - xhr.open("POST", url, true); - xhr.setRequestHeader("Content-Type", "application/json"); - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - // In the success case, we get a plain (json) string; in the error - // case, we get an object with `errorMessage` property. - if (typeof this.response == "object" && "errorMessage" in this.response) { - window.console.log("Error in sign-up request."); - result.classList.remove("alert-success"); - result.classList.add("alert-danger"); - if ( - this.response.errorMessage == - "[KratosError] Unable to insert or update resource because a resource with that value exists already" - ) { - result.innerHTML = "A user with that email address already exists."; - } else if ( - this.response.errorMessage == - "[KratosError] The request was malformed or contained invalid parameters" - ) { - result.innerHTML = "That doesn't appear to be a valid email address."; - } else { - result.innerHTML = this.response.errorMessage; - } - } else { - result.classList.add("alert-success"); - result.classList.remove("alert-danger"); - result.innerHTML = this.response; - } - result.style.visibility = "visible"; - } - }; - // Converting JSON data to string - var data = JSON.stringify({ email: email.value }); - // Sending data with the request - xhr.send(data); -} diff --git a/backend/web/static/css/main.css b/backend/web/static/css/main.css index 698b3ea1be893ce15d67c0125d932e40f232dfdc..9b0d30098d6b8c204d3127c1a45e2ee5dee7b847 100644 --- a/backend/web/static/css/main.css +++ b/backend/web/static/css/main.css @@ -599,14 +599,6 @@ label { display: block; } -.inline-block { - display: inline-block; -} - -.inline { - display: inline; -} - .flex { display: flex; } @@ -647,10 +639,6 @@ label { flex-direction: column; } -.place-content-end { - place-content: end; -} - .place-items-center { place-items: center; } @@ -671,10 +659,6 @@ label { justify-content: space-between; } -.justify-items-end { - justify-items: end; -} - .gap-4 { gap: 1rem; } diff --git a/backend/web/static/js/demo.js b/backend/web/static/js/demo.js new file mode 100644 index 0000000000000000000000000000000000000000..47a748f70f7034186f51d19bb461a2e6661999b8 --- /dev/null +++ b/backend/web/static/js/demo.js @@ -0,0 +1,46 @@ +////////////////////////////////////// +// sign up form for the demo instance +////////////////////////////////////// + +function submitSignup() { + let result = document.querySelector("#signup-result"); + let email = document.querySelector("#signup-email"); + let xhr = new XMLHttpRequest(); + xhr.responseType = "json"; + let url = "/web/demo-user"; + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + // In the success case, we get a plain (json) string; in the error + // case, we get an object with `errorMessage` property. + if (typeof this.response == "object" && "errorMessage" in this.response) { + window.console.log("Error in sign-up request."); + result.classList.remove("alert-success"); + result.classList.add("alert-danger"); + if ( + this.response.errorMessage == + "[KratosError] Unable to insert or update resource because a resource with that value exists already" + ) { + result.innerHTML = "A user with that email address already exists."; + } else if ( + this.response.errorMessage == + "[KratosError] The request was malformed or contained invalid parameters" + ) { + result.innerHTML = "That doesn't appear to be a valid email address."; + } else { + result.innerHTML = this.response.errorMessage; + } + } else { + result.classList.add("alert-success"); + result.classList.remove("alert-danger"); + result.innerHTML = this.response; + } + result.style.visibility = "visible"; + } + }; + // Converting JSON data to string + var data = JSON.stringify({ email: email.value }); + // Sending data with the request + xhr.send(data); +} diff --git a/backend/web/templates/base.html b/backend/web/templates/base.html index d5221bfc684a042d70007826c5949538352183e2..178fa584eccc0498e167fccb8da253828330de6e 100644 --- a/backend/web/templates/base.html +++ b/backend/web/templates/base.html @@ -9,6 +9,9 @@ <script src="static/js/bootstrap.bundle.min.js"></script> <script src="static/js/js.cookie.min.js"></script> <script src="static/base.js"></script> + {% if demo %} + <script src="static/js/demo.js"></script> + {% endif %} <title>Your Stackspin Account</title> </html> diff --git a/backend/web/templates/login.html b/backend/web/templates/login.html index 9a6c891bc1ea3ce35ba34180f7a917eec7e9e4c6..6bcde578eba827158ab355730e577a937a6623b2 100644 --- a/backend/web/templates/login.html +++ b/backend/web/templates/login.html @@ -16,10 +16,12 @@ // On demo instance, submit the sign-up form via ajax // so we can show the result on the same page. {% if demo %} - $('#signup-form').submit((event) => { - event.preventDefault(); - window.console.log("signup submit"); - submitSignup(); + $(document).ready(function(){ + $('#signup-form').submit((event) => { + event.preventDefault(); + window.console.log("signup submit"); + submitSignup(); + }); }); {% endif %} </script>