45 lines
No EOL
2.1 KiB
JavaScript
45 lines
No EOL
2.1 KiB
JavaScript
document.addEventListener("DOMContentLoaded", function () {
|
|
document.getElementById("regForm").addEventListener("submit", async function (formE) {
|
|
formE.preventDefault();
|
|
formData = new FormData(formE.target);
|
|
if (formData.get("password") == formData.get("password2")) {
|
|
formData.delete("password2");
|
|
if (formData.get("username").trim().length < 4) msg("Login użytkownika musi mieć przynajmniej 4 znaki");
|
|
else if (formData.get("username").trim().length > 32) msg("Login nie może być dłuższa niż 32 znaki");
|
|
else if (formData.get("password").trim().length < 4) msg("Hasło musi mieć przynajmniej 4 znaki");
|
|
else if (formData.get("password").trim().length > 32) msg("Hasło nie może być dłuże niż 32 znaki");
|
|
else {
|
|
const response = await fetch("register.php", {
|
|
method: "POST",
|
|
body: formData,
|
|
credentials: "include",
|
|
headers: {
|
|
'X-Requested-With': 'XMLHttpRequest'
|
|
}
|
|
});
|
|
const result = await response.json();
|
|
msg(result.msg);
|
|
if (result.redirect) setTimeout(function () { window.location.replace(result.redirect); }, 300);
|
|
}
|
|
} else msg("Hasła nie są identyczne");
|
|
});
|
|
passwordI = document.getElementById("password");
|
|
passwordI2 = document.getElementById("password2");
|
|
document.getElementById("showPassword").addEventListener("mousedown", function () {
|
|
passwordI.type = "text";
|
|
passwordI2.type = "text";
|
|
});
|
|
document.getElementById("showPassword").addEventListener("mouseup", function () {
|
|
passwordI.type = "password";
|
|
passwordI2.type = "password";
|
|
});
|
|
document.getElementById("showPassword").addEventListener("mouseleave", function () {
|
|
passwordI.type = "password";
|
|
passwordI2.type = "password";
|
|
});
|
|
});
|
|
function msg(msg) {
|
|
const output = document.getElementById("info");
|
|
output.innerHTML = msg;
|
|
output.style.display = "block";
|
|
} |