97 lines
2.5 KiB
JavaScript
97 lines
2.5 KiB
JavaScript
function load_ficha() {
|
|
$.ajax({
|
|
url: window.api + "player",
|
|
type: "GET",
|
|
xhrFields: {
|
|
withCredentials: true,
|
|
},
|
|
success: function (resp) {
|
|
window.location.href = "index.html";
|
|
},
|
|
});
|
|
}
|
|
|
|
function verifyInputs(player, passwd, confpasswd, lore) {
|
|
if (
|
|
player &&
|
|
!player.includes(" ") &&
|
|
passwd &&
|
|
!passwd.includes(" ") &&
|
|
confpasswd &&
|
|
!confpasswd.includes(" ") &&
|
|
lore
|
|
) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
$("#imgClick").on("click", () => $("#inputImagem").click());
|
|
|
|
$("#inputImagem").on("change", function () {
|
|
const file = this.files[0];
|
|
if (file && file.type.startsWith("image/")) {
|
|
const reader = new FileReader();
|
|
reader.onload = (e) => $("#imgClick").attr("src", e.target.result);
|
|
reader.readAsDataURL(file);
|
|
}
|
|
});
|
|
|
|
$(document).ready(function () {
|
|
load_ficha();
|
|
$("#loginBtn").on("click", function () {
|
|
const $btn = $(this);
|
|
$btn.prop("disabled", true).val("Criando conta...");
|
|
|
|
const fileInput = $("#inputImagem")[0];
|
|
const file = fileInput.files[0];
|
|
|
|
const player = $("#loginInput[name='player']").val();
|
|
const password = $("#loginInput[name='password']").val();
|
|
const confPassword = $("#loginInput[name='confirmpassword']").val();
|
|
const lore = $("#playerlore[name='playerlore']").val();
|
|
|
|
if (!file) {
|
|
msg("Error", "Você é obrigado a colocar uma imagem.");
|
|
return finalizarErro($btn, "Registrar");
|
|
}
|
|
|
|
if (!verifyInputs(player, password, confPassword, lore)) {
|
|
msg("Error", "Por favor, preencha todos os dados corretamente.");
|
|
return finalizarErro($btn, "Registrar");
|
|
}
|
|
|
|
const form = new FormData();
|
|
form.append("PlayerImage", fileInput.files[0]);
|
|
form.append("player", player);
|
|
form.append("password", password);
|
|
form.append("confirmpassword", confPassword);
|
|
form.append("playerlore", lore);
|
|
console.log(form);
|
|
$.ajax({
|
|
url: window.api + "register",
|
|
type: "POST",
|
|
data: form,
|
|
contentType: false,
|
|
processData: false,
|
|
xhrFields: { withCredentials: true },
|
|
success: function (resp) {
|
|
msg(resp.Status, resp.Message);
|
|
$btn.val("Concluído");
|
|
window.location.href = "index.html";
|
|
},
|
|
error: function (resp) {
|
|
msg(
|
|
resp.responseJSON?.Status || "Erro",
|
|
resp.responseJSON?.Message || "Algo deu errado.",
|
|
);
|
|
finalizarErro($btn, "Registrar");
|
|
},
|
|
});
|
|
});
|
|
|
|
function finalizarErro($btn, texto = "Registrar") {
|
|
$btn.prop("disabled", false).val(texto);
|
|
}
|
|
});
|