Skip to content

Commit

Permalink
Refactor signup page
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Oct 5, 2024
1 parent 60c9575 commit d56768e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,55 @@
<div class="form-item">
<button type="submit" th:text="#{form.signup.submit}"></button>
</div>

<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function () {
function sendRequest() {
return new Promise((resolve, reject) => {
const email = document.getElementById("email").value;
if (!email) {
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/);
}
fetch("/signup/send-email-code", {
method: "POST",
body: JSON.stringify({ email: email }),
headers: {
"Content-Type": "application/json",
[[${_csrf.headerName}]]: [[${_csrf.token}]],
},
})
.then((response) => {
if (response.ok) {
resolve(response);
}
reject(response);
})
.catch((e) => {
reject(e);
});
});
}
const emailCodeSendButton = document.getElementById("emailCodeSendButton");
sendVerificationCode(emailCodeSendButton, sendRequest);
var password = document.getElementById("password"),
confirm_password = document.getElementById("confirmPassword");
function validatePassword() {
if (password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity("");
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
});
</script>
</form>

<form
Expand Down Expand Up @@ -239,5 +288,4 @@
<button type="submit" th:text="#{form.passwordReset.submit}"></button>
</div>
</form>
</th:block>

</th:block>
48 changes: 0 additions & 48 deletions application/src/main/resources/templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,5 @@ <h1 class="form-title" th:text="#{title}"></h1>
</div>
<div th:replace="~{gateway_modules/common_fragments::languageSwitcher}"></div>
</div>
<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function () {
function sendRequest() {
return new Promise((resolve, reject) => {
const email = document.getElementById("email").value;
if (!email) {
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/);
}
fetch("/signup/send-email-code", {
method: "POST",
body: JSON.stringify({ email: email }),
headers: {
"Content-Type": "application/json",
[[${_csrf.headerName}]]: [[${_csrf.token}]],
},
})
.then((response) => {
if (response.ok) {
resolve(response);
}
reject(response);
})
.catch((e) => {
reject(e);
});
});
}
const emailCodeSendButton = document.getElementById("emailCodeSendButton");
sendVerificationCode(emailCodeSendButton, sendRequest);
var password = document.getElementById("password"),
confirm_password = document.getElementById("confirmPassword");
function validatePassword() {
if (password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity("");
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
});
</script>
</th:block>
</html>

0 comments on commit d56768e

Please sign in to comment.