added division by tabs, validating nickname before registration, showing server responses using jquery

This commit is contained in:
2025-02-02 19:19:12 +03:00
parent 0803970233
commit 9a2c8a6eca
11 changed files with 149 additions and 58 deletions

View File

@@ -0,0 +1,19 @@
$(document).ready(() => {
$("#passwordChangeForm").submit(() => {
$.ajax({
type: "POST",
url: "/api/changePassword",
contentType: 'application/json',
data: JSON.stringify({
oldPassword: $("#oldPassword").val(),
newPassword: $("#newPassword").val()
}),
success: () => {
alert("Пароль изменён")
},
error: (xhr) => {
alert(xhr.responseText);
}
});
});
});

3
public/js/index.js Normal file
View File

@@ -0,0 +1,3 @@
const goToPage = (page) => {
window.location.href = `${page}`
}

View File

@@ -1,5 +1,10 @@
$(document).ready(() => {
$("#registerForm").submit(() => {
if ($("#password").val() != $("#passwordConfirm").val()) {
alert("Password dont match!")
return;
}
$.ajax({
type: "POST",
url: "/api/register",
@@ -9,10 +14,10 @@ $(document).ready(() => {
inviteToken: $("#inviteToken").val()
}),
contentType: 'application/json',
success: function() {
success: () => {
window.location.href = "/index";
},
error: function(xhr) {
error: (xhr) => {
alert (xhr.responseText);
}
})

View File

@@ -38,34 +38,9 @@ const uploadCape = async (event) => {
window.location = window.location.href+'?eraseCache=true';
}
const changePassword = async (event) => {
event.preventDefault();
const oldPassword = document.getElementById("oldPassword").value
const newPassword = document.getElementById("newPassword").value
if (oldPassword == newPassword) {
alert("You cannod change your password to the same!")
return;
}
await fetch(`/api/changePassword`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
oldPassword,
newPassword
})
});
alert("Password has been changed!");
}
window.onload = async function() {
document.getElementById("skinForm").addEventListener("submit", uploadSkin)
document.getElementById("passwordChangeForm").addEventListener("submit", changePassword);
if (document.getElementById("cape")) {
document.getElementById("cape").addEventListener("click", () => { set_cape_type("cape") }, false);
document.getElementById("cape").checked = true;