fix(DevWeb): Import static files

This commit is contained in:
Lucàs
2024-04-05 12:39:01 +02:00
parent c438395a1a
commit 61603ddac6
26 changed files with 36 additions and 170 deletions
@@ -0,0 +1,13 @@
const ERROR_MESSAGE = {
"expired-token": "Lien expiré, veuillez recommencer la procédure de récupération de mot de passe.",
"invalid-token": "Lien invalide, veuillez recommencer la procédure de récupération de mot de passe.",
};
const urlParams = new URLSearchParams(window.location.search);
const error = urlParams.get('error');
if (error) {
const errorMessage = ERROR_MESSAGE[error];
console.error(errorMessage);
window.alert(errorMessage);
}
@@ -0,0 +1,29 @@
const loginForm = document.getElementById("login-form");
loginForm.addEventListener("submit", (event) => {
event.preventDefault();
const formData = new FormData(loginForm);
const data = {};
formData.forEach((value, key) => data[key] = value);
fetch(loginForm.getAttribute("action"), {
headers: {"Content-Type": "application/json"},
body: JSON.stringify(data),
method: loginForm.getAttribute("method"),
})
.then(res => res.json())
.then(d => window.location.href = "./main-menu")
.catch(error => console.error("Error:", error));
});
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('success')) {
if (urlParams.get('success') === "account-created") {
window.alert("Compte créé avec succès.");
}
if (urlParams.get('success') === "password-reseted") {
window.alert("Mot de passe réinitialisé avec succès.");
}
}
@@ -0,0 +1,16 @@
let cb = document.querySelectorAll(".close");
for (let i = 0; i < cb.length; i++) {
cb[i].addEventListener("click", function() {
const dia = this.parentNode.parentNode; /* You need to update this part if you change level of close button */
dia.style.display = "none";
});
}
let mt = document.querySelectorAll(".modal-toggle");
for (let i = 0; i < mt.length; i++) {
mt[i].addEventListener("click", function() {
const targetId = this.getAttribute("data-target");
const target = document.querySelector(targetId);
target.style.display = "block";
});
}
@@ -0,0 +1,19 @@
const nbColorsElement = document.getElementById("nbColors");
const nbValuesElement = document.getElementById("nbValues");
const nbRoundsElement = document.getElementById("nbRounds")
/**
* Mise à jour du nombre de rounds max en fonction du nombre de couleurs et de valeurs séléctionnés
*/
function updateOnChange() {
nbRoundsElement.max = nbColorsElement.value * nbValuesElement.value;
nbRoundsElement.value =
(nbRoundsElement.value > nbRoundsElement.max)
? nbRoundsElement.max
: nbRoundsElement.value
;
}
nbColorsElement.addEventListener("change", updateOnChange);
nbValuesElement.addEventListener("change", updateOnChange);
@@ -0,0 +1,21 @@
const registerForm = document.getElementById("register-form");
const confirmPassword = document.getElementById("confirmPassword");
registerForm.addEventListener("submit", (event) => {
event.preventDefault();
const formData = new FormData(registerForm);
const data = {};
formData.forEach((value, key) => data[key] = value);
fetch(registerForm.getAttribute("action"), {
method: registerForm.getAttribute("method"),
headers: {"Content-Type": "application/json"},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(_ => {
window.location.href = "./login"
})
.catch(error => console.error("Error: " + error))
});
@@ -0,0 +1,31 @@
const resetPasswordForm = document.getElementById("resetPasswordForm");
const confirmPassword = document.getElementById("confirmPassword");
resetPasswordForm.addEventListener("submit", function (event) {
event.preventDefault();
const formData = new FormData(resetPasswordForm);
const data = {};
formData.forEach((value, key) => data[key] = value);
const action = loginForm.getAttribute("action")
const method = loginForm.getAttribute("method")
fetch("/reset-password", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
}).then(response => {
if (response.ok) {
window.location.href = "/login";
} else {
response.json().then(data => {
alert(data.message);
});
}
}).catch(error => {
console.error("Error:", error);
});
});