Suppression appels au frontend dans scripts frontend pour récupérer les variables de configuration utiles
This commit is contained in:
parent
764fc9bf93
commit
50f53a969b
@ -61,131 +61,6 @@ exports.getGodfatherId = async (req, res, next) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// retourne toutes les infos utiles côté client pour un utilisateur
|
|
||||||
// revoir : placer dans un autre contrôler dédié à communication avec le front-end
|
|
||||||
exports.getConfig = (req, res, next) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//const configLinks = require("../config/links.js");
|
|
||||||
//const configIllustrations = require("../config/illustrations.js");
|
|
||||||
const configUsers =
|
|
||||||
{
|
|
||||||
// les routes :
|
|
||||||
siteUrl: config.siteUrl,
|
|
||||||
apiUrl: config.apiUrl,
|
|
||||||
// -- users
|
|
||||||
userRoutes: "/user",
|
|
||||||
subscribeRoute: "/signup",
|
|
||||||
getGodfatherRoute: "/getgodfatherid",
|
|
||||||
checkIfIsEmailfreeRoute: "/isemailfree",
|
|
||||||
checkSubscribeTokenRoute: "/validation/",
|
|
||||||
checkLoginRoute: "/checklogin/",
|
|
||||||
connectionRoute: "/login",
|
|
||||||
getLoginLinkRoute: "/getloginlink",
|
|
||||||
connectionWithLinkRoute: "/checkloginlink",
|
|
||||||
getUserInfos: "/get/",
|
|
||||||
createUserRoute: "/create",
|
|
||||||
validateUserRoute: "/validate/",
|
|
||||||
updateUserInfos: "/modify/",
|
|
||||||
searchUserRoute: "/search/",
|
|
||||||
getGodChilds: "/getgodchilds/",
|
|
||||||
checkNewLoginLinkRoute: "/confirmnewlogin/",
|
|
||||||
checkDeleteLinkRoute: "/confirmdelete/",
|
|
||||||
getPayments: "/payment/getforoneuser/",
|
|
||||||
unsubscribeRoute: "/subscription/stop/",
|
|
||||||
// -- questionnaires :
|
|
||||||
questionnaireRoutes: "/questionnaire",
|
|
||||||
getQuestionnaireRoutes: "/get",
|
|
||||||
previewQuestionnaireRoutes: "/preview",
|
|
||||||
publishedQuestionnaireRoutes: "/quiz/",
|
|
||||||
saveAnswersRoute: "/answer/",
|
|
||||||
getStatsQuestionnaires : "/stats/",
|
|
||||||
searchQuestionnairesRoute : "/search",
|
|
||||||
searchAdminQuestionnairesRoute : "/searchAdmin",
|
|
||||||
getListNextQuestionnaires: "/getListNextQuestionnaires/",
|
|
||||||
// -- tags :
|
|
||||||
tagsSearchRoute: "/tags/search/",
|
|
||||||
// -- links :
|
|
||||||
linksRoute: "/link/",
|
|
||||||
// -- illustrations :
|
|
||||||
illustrationsRoute: "/illustration/",
|
|
||||||
// -- questions & choices :
|
|
||||||
questionsRoute: "/question/",
|
|
||||||
// -- answers :
|
|
||||||
getQuestionnairesWithoutAnswer: "/withoutanswer/user/",
|
|
||||||
getPreviousAnswers: "/user/answers/",
|
|
||||||
getStatsAnswers : "/user/anwswers/stats/",
|
|
||||||
getAdminStats: "/getadminstats/",
|
|
||||||
// configuration des champs de saisie
|
|
||||||
// revoir : toutes ces données devraient venir de fichiers de configuration
|
|
||||||
// -- users :
|
|
||||||
name: { maxlength: 70, required: true },
|
|
||||||
email: { maxlength: 255, required: true },
|
|
||||||
password: { minlength: config.passwordMinLength, required: true },
|
|
||||||
newPassword: { minlength: config.passwordMinLength },
|
|
||||||
codeGodfather: { maxlength: 255 },
|
|
||||||
cguOk: { value: "true", required: true },
|
|
||||||
timeDifferenceMin:-720,
|
|
||||||
timeDifferenceMax:840,
|
|
||||||
beginCodeGodfather: config.beginCodeGodfather,
|
|
||||||
// -- questionnaires :
|
|
||||||
Questionnaire :
|
|
||||||
{
|
|
||||||
title: { maxlength: 255, required: true },
|
|
||||||
slug: { maxlength: 150 }, // champ requis mais calculé à partir du titre qd vide
|
|
||||||
introduction: { required: true }
|
|
||||||
},
|
|
||||||
searchQuestionnaires : { minlength: config.minSearchQuestionnaires, required: true },
|
|
||||||
// -- links :
|
|
||||||
Link :
|
|
||||||
{
|
|
||||||
url: { maxlength: 255, required: true },
|
|
||||||
anchor: { maxlength: 150, required: true }
|
|
||||||
},
|
|
||||||
nbLinksMin: 1,
|
|
||||||
nbLinksMax: 1,
|
|
||||||
// -- illustrations :
|
|
||||||
Illustration :
|
|
||||||
{
|
|
||||||
alt: { maxlength: 255 },
|
|
||||||
title: { maxlength: 255 },
|
|
||||||
caption: { maxlength: 255 },
|
|
||||||
image: { required: true, accept: "'image/jpg', 'image/jpeg', 'image/png', 'image/gif', 'image/png'" } // si possibilité de sélectionner une image déjà chargée, required != true, mais oblige à revoir la suppression des fichiers image
|
|
||||||
},
|
|
||||||
nbIllustrationsMin: 0,
|
|
||||||
nbIllustrationsMax: 1,
|
|
||||||
// -- questions & choice :
|
|
||||||
Question :
|
|
||||||
{
|
|
||||||
text: { maxlength: 255, required: true },
|
|
||||||
rank: { required: true, min:1, defaultValue:1 }
|
|
||||||
},
|
|
||||||
Choice :
|
|
||||||
{
|
|
||||||
text: { maxlength: 255, required: true }
|
|
||||||
},
|
|
||||||
nbQuestionsMin: config.nbQuestionsMin,
|
|
||||||
nbQuestionsMax: config.nbQuestionsMax,
|
|
||||||
nbChoicesMax: config.nbChoicesMax,
|
|
||||||
// durée des token :
|
|
||||||
signupValidationTimeInHours: config.tokenSignupValidationTimeInHours,
|
|
||||||
loginLinkTimeInHours: config.tokenLoginLinkTimeInHours,
|
|
||||||
connexionMinTimeInHours: config.tokenConnexionMinTimeInHours,
|
|
||||||
connexionMaxTimeInHours: config.tokenConnexionMaxTimeInDays,
|
|
||||||
loginChangingTimeInHours: config.tokenLoginChangingTimeInHours,
|
|
||||||
deleteUserTimeInHours: config.tokenDeleteUserTimeInHours,
|
|
||||||
unsubscribeLinkTimeInDays: config.tokenUnsubscribeLinkTimeInDays
|
|
||||||
}
|
|
||||||
res.status(200).json(configUsers);
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
next(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.signup = async (req, res, next) =>
|
exports.signup = async (req, res, next) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -10,7 +10,9 @@
|
|||||||
// Fichier de configuration côté client :
|
// Fichier de configuration côté client :
|
||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
const configTemplate = require("../../views/"+theme+"/config/"+lang+".js");// besoin de toutes les déclarations pour la fonction : updateAccountLink()
|
||||||
|
const { beginCodeGodfather } = require("../../config/instance");
|
||||||
|
const configUsers = require("../../config/users"); // besoin de tous le fichier pour configurer le formulaire
|
||||||
|
|
||||||
// Fonctions utiles au script
|
// Fonctions utiles au script
|
||||||
import { getLocaly, removeLocaly } from "./tools/clientstorage.js";
|
import { getLocaly, removeLocaly } from "./tools/clientstorage.js";
|
||||||
@ -46,213 +48,207 @@ const initialise = async () =>
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const config = await getConfig();
|
// Si l'utilisateur n'est pas connecté avec le bon statut, pas la peine d'aller + loin :
|
||||||
if(!config)
|
const isConnected=await checkSession(["user"], "/"+configTemplate.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
||||||
addElement(divCrash, "p", serverError, "", ["error"]);
|
if(isConnected)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Si l'utilisateur n'est pas connecté avec le bon statut, pas la peine d'aller + loin :
|
divMain.style.display="block";
|
||||||
const isConnected=await checkSession(["user"], "/"+configFrontEnd.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
// l'éventuelle ancre est ignorée, car absente du DOM avant d'avoir vérifié la connexion
|
||||||
if(isConnected)
|
if(window.location.hash!==undefined)
|
||||||
|
window.location.assign(window.location.hash);
|
||||||
|
|
||||||
|
if(!isEmpty(getLocaly("message")))
|
||||||
{
|
{
|
||||||
divMain.style.display="block";
|
addElement(divMessage, "p", getLocaly("message", true).message, "", [getLocaly("message", true).color], "", false);
|
||||||
// l'éventuelle ancre est ignorée, car absente du DOM avant d'avoir vérifié la connexion
|
removeLocaly("message");
|
||||||
if(window.location.hash!==undefined)
|
}
|
||||||
window.location.assign(window.location.hash);
|
const user=getLocaly("user", true);
|
||||||
|
updateAccountLink(user.status, configTemplate);
|
||||||
|
// Initialise le formulaire permettant de mettre à jour les infos :
|
||||||
|
setAttributesToInputs(configUsers, formAccount);
|
||||||
|
// Certains navigateurs remplissent les champs password :
|
||||||
|
newPassword.value="";
|
||||||
|
|
||||||
if(!isEmpty(getLocaly("message")))
|
// Fonction affichant les infos connues au premier affichage, puis après envoi mise à jour
|
||||||
{
|
const getInfos = () =>
|
||||||
addElement(divMessage, "p", getLocaly("message", true).message, "", [getLocaly("message", true).color], "", false);
|
{
|
||||||
removeLocaly("message");
|
const xhrGetInfos = new XMLHttpRequest();
|
||||||
}
|
xhrGetInfos.open("GET", apiUrl+configUsers.userRoutes+configUsers.getUserInfos+user.id);
|
||||||
const user=getLocaly("user", true);
|
xhrGetInfos.onreadystatechange = function()
|
||||||
updateAccountLink(user.status, configFrontEnd);
|
|
||||||
// Initialise le formulaire permettant de mettre à jour les infos :
|
|
||||||
setAttributesToInputs(config, formAccount);
|
|
||||||
// Certains navigateurs remplissent les champs password :
|
|
||||||
newPassword.value="";
|
|
||||||
|
|
||||||
// Fonction affichant les infos connues au premier affichage, puis après envoi mise à jour
|
|
||||||
const getInfos = () =>
|
|
||||||
{
|
|
||||||
const xhrGetInfos = new XMLHttpRequest();
|
|
||||||
xhrGetInfos.open("GET", apiUrl+config.userRoutes+config.getUserInfos+user.id);
|
|
||||||
xhrGetInfos.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
|
||||||
{
|
|
||||||
let response=JSON.parse(this.responseText);
|
|
||||||
if (this.status === 200 && response.User != undefined && response.Subscription != undefined)
|
|
||||||
{
|
|
||||||
for(let data in response.User)
|
|
||||||
{
|
|
||||||
if(formAccount.elements[data]!==undefined)
|
|
||||||
{
|
|
||||||
if(response.User[data]!==true && response.User[data]!==false)// booléen = case à cocher !
|
|
||||||
formAccount.elements[data].value=response.User[data];
|
|
||||||
else if (response.User[data]==true) // si false, on ne fait rien
|
|
||||||
formAccount.elements[""+data].checked="checked";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// infos de l'abonnement
|
|
||||||
if(response.Subscription.noticeOk==true)
|
|
||||||
formAccount.elements["noticeOk"].checked="checked";
|
|
||||||
// jours de réception
|
|
||||||
for(let i in response.Subscription.receiptDays)
|
|
||||||
formAccount.elements["d"+response.Subscription.receiptDays[i]].checked="checked";
|
|
||||||
// "codes" possibles à transmettre pour parrainer d'autres utilisateurs
|
|
||||||
showGFEmail.innerHTML=response.User.email;
|
|
||||||
showGFCode.innerHTML=config.beginCodeGodfather+response.User.id;
|
|
||||||
}
|
|
||||||
const beginSubTS=new Date(response.Subscription.createdAt).getTime();
|
|
||||||
const nbDaysOk=response.Subscription.numberOfDays-Math.round((Date.now()-beginSubTS)/1000/3600/24);
|
|
||||||
if(nbDaysOk > 0)
|
|
||||||
addElement(divSubscribeIntro, "p", infosNbDays.replace("NB_DAYS", nbDaysOk), "", ["info"]);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
addElement(divSubscribeIntro, "p", infosExpirated.replace("NB_DAYS", nbDaysOk), "", ["error"]);
|
|
||||||
window.location.assign("#subscribe");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xhrGetInfos.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
||||||
xhrGetInfos.send();
|
|
||||||
}
|
|
||||||
// Remonte les infos déjà enregistrées :
|
|
||||||
getInfos();
|
|
||||||
|
|
||||||
// Traitement de l'envoi d'une mise à jour des infos
|
|
||||||
formAccount.addEventListener("submit", function(e)
|
|
||||||
{
|
|
||||||
e.preventDefault();
|
|
||||||
divResponse.innerHTML="";
|
|
||||||
let datas=getDatasFromInputs(formAccount);
|
|
||||||
// recomposition des jours valables pour l'abonnement :
|
|
||||||
datas.receiptDays="";
|
|
||||||
for(let i=1; i<=7; i++)
|
|
||||||
{
|
|
||||||
if(datas["d"+i]!==undefined)
|
|
||||||
datas.receiptDays+=""+i;
|
|
||||||
}
|
|
||||||
if(datas.noticeOk===undefined)
|
|
||||||
datas.noticeOk="false";
|
|
||||||
if(datas.newsletterOk===undefined)
|
|
||||||
datas.newsletterOk="false";
|
|
||||||
datas.timeDifference=getTimeDifference(config);
|
|
||||||
const xhrUserUpdate = new XMLHttpRequest();
|
|
||||||
if(datas.deleteOk!==undefined)
|
|
||||||
xhrUserUpdate.open("DELETE", apiUrl+config.userRoutes+"/"+user.id);
|
|
||||||
else
|
|
||||||
xhrUserUpdate.open("PUT", apiUrl+config.userRoutes+config.updateUserInfos+user.id);
|
|
||||||
xhrUserUpdate.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
|
||||||
{
|
|
||||||
let response=JSON.parse(this.responseText);
|
|
||||||
if (this.status === 200 && response.message!=undefined)
|
|
||||||
{
|
|
||||||
if(Array.isArray(response.message))
|
|
||||||
response.message = response.message.join("<br>");
|
|
||||||
else
|
|
||||||
response.message = response.message;
|
|
||||||
addElement(divResponse, "p", response.message, "", ["success"]);
|
|
||||||
}
|
|
||||||
else if (response.errors)
|
|
||||||
{
|
|
||||||
if(Array.isArray(response.errors))
|
|
||||||
response.errors = response.errors.join("<br>");
|
|
||||||
else
|
|
||||||
response.errors = serverError;
|
|
||||||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
// dans tous les cas, je mets à jour le contenu du formulaire :
|
|
||||||
getInfos();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xhrUserUpdate.setRequestHeader("Content-Type", "application/json");
|
|
||||||
xhrUserUpdate.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
||||||
if(datas)
|
|
||||||
{
|
|
||||||
datas.output="html";
|
|
||||||
xhrUserUpdate.send(JSON.stringify(datas));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// on passe à la caisse ?
|
|
||||||
const abo9=document.getElementById("abo9");
|
|
||||||
const abo18=document.getElementById("abo18");
|
|
||||||
const abo36=document.getElementById("abo36");
|
|
||||||
const abo54=document.getElementById("abo54");
|
|
||||||
const CGV=document.getElementById("CGVOk");
|
|
||||||
const divWPBtns=document.getElementById("WPBtns");
|
|
||||||
divWPBtns.style.display="none";
|
|
||||||
abo9.addEventListener("change", function(e)
|
|
||||||
{
|
|
||||||
unCheckAllOthers("abo9");
|
|
||||||
});
|
|
||||||
abo18.addEventListener("change", function(e)
|
|
||||||
{
|
|
||||||
unCheckAllOthers("abo18");
|
|
||||||
});
|
|
||||||
abo36.addEventListener("change", function(e)
|
|
||||||
{
|
|
||||||
unCheckAllOthers("abo36");
|
|
||||||
});
|
|
||||||
abo54.addEventListener("change", function(e)
|
|
||||||
{
|
|
||||||
unCheckAllOthers("abo54");
|
|
||||||
});
|
|
||||||
CGV.addEventListener("change", function(e)
|
|
||||||
{
|
|
||||||
if(CGV.checked===true)
|
|
||||||
{
|
|
||||||
divWPBtns.style.display="block";
|
|
||||||
if(abo9.checked===true)
|
|
||||||
showBtnPayment("btn9");
|
|
||||||
else if(abo18.checked===true)
|
|
||||||
showBtnPayment("btn18");
|
|
||||||
else if(abo36.checked===true)
|
|
||||||
showBtnPayment("btn36");
|
|
||||||
else if(abo54.checked===true)
|
|
||||||
showBtnPayment("btn54");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
divWPBtns.style.display="none";
|
|
||||||
CGV.checked=false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
divWPBtns.style.display="none";
|
|
||||||
});
|
|
||||||
|
|
||||||
// Liste des filleuls, si il y en a
|
|
||||||
const xhrGetGodchilds = new XMLHttpRequest();
|
|
||||||
xhrGetGodchilds.open("GET", apiUrl+config.userRoutes+config.getGodChilds);
|
|
||||||
xhrGetGodchilds.onreadystatechange = function()
|
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
{
|
{
|
||||||
let response=JSON.parse(this.responseText), txtGodchilds="";
|
let response=JSON.parse(this.responseText);
|
||||||
if (this.status === 200)
|
if (this.status === 200 && response.User != undefined && response.Subscription != undefined)
|
||||||
{
|
{
|
||||||
const nbGodchilds=response.length;
|
for(let data in response.User)
|
||||||
if(nbGodchilds===0)
|
|
||||||
txtGodchilds=infosUserNoGodchilds;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
txtGodchilds=infosUserNbGodChilds.replace("#NB", nbGodchilds);
|
if(formAccount.elements[data]!==undefined)
|
||||||
for(let i in response)
|
{
|
||||||
txtGodchilds+=response[i].name+" ("+response[i].email+") ";
|
if(response.User[data]!==true && response.User[data]!==false)// booléen = case à cocher !
|
||||||
|
formAccount.elements[data].value=response.User[data];
|
||||||
|
else if (response.User[data]==true) // si false, on ne fait rien
|
||||||
|
formAccount.elements[""+data].checked="checked";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// infos de l'abonnement
|
||||||
|
if(response.Subscription.noticeOk==true)
|
||||||
|
formAccount.elements["noticeOk"].checked="checked";
|
||||||
|
// jours de réception
|
||||||
|
for(let i in response.Subscription.receiptDays)
|
||||||
|
formAccount.elements["d"+response.Subscription.receiptDays[i]].checked="checked";
|
||||||
|
// "codes" possibles à transmettre pour parrainer d'autres utilisateurs
|
||||||
|
showGFEmail.innerHTML=response.User.email;
|
||||||
|
showGFCode.innerHTML=beginCodeGodfather+response.User.id;
|
||||||
|
}
|
||||||
|
const beginSubTS=new Date(response.Subscription.createdAt).getTime();
|
||||||
|
const nbDaysOk=response.Subscription.numberOfDays-Math.round((Date.now()-beginSubTS)/1000/3600/24);
|
||||||
|
if(nbDaysOk > 0)
|
||||||
|
addElement(divSubscribeIntro, "p", infosNbDays.replace("NB_DAYS", nbDaysOk), "", ["info"]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addElement(divSubscribeIntro, "p", infosExpirated.replace("NB_DAYS", nbDaysOk), "", ["error"]);
|
||||||
|
window.location.assign("#subscribe");
|
||||||
}
|
}
|
||||||
addElement(divGodchilds, "p", txtGodchilds, "", ["info"]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhrGetGodchilds.setRequestHeader("Authorization", "Bearer "+user.token);
|
xhrGetInfos.setRequestHeader("Authorization", "Bearer "+user.token);
|
||||||
xhrGetGodchilds.send();
|
xhrGetInfos.send();
|
||||||
}
|
}
|
||||||
|
// Remonte les infos déjà enregistrées :
|
||||||
|
getInfos();
|
||||||
|
|
||||||
|
// Traitement de l'envoi d'une mise à jour des infos
|
||||||
|
formAccount.addEventListener("submit", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
divResponse.innerHTML="";
|
||||||
|
let datas=getDatasFromInputs(formAccount);
|
||||||
|
// recomposition des jours valables pour l'abonnement :
|
||||||
|
datas.receiptDays="";
|
||||||
|
for(let i=1; i<=7; i++)
|
||||||
|
{
|
||||||
|
if(datas["d"+i]!==undefined)
|
||||||
|
datas.receiptDays+=""+i;
|
||||||
|
}
|
||||||
|
if(datas.noticeOk===undefined)
|
||||||
|
datas.noticeOk="false";
|
||||||
|
if(datas.newsletterOk===undefined)
|
||||||
|
datas.newsletterOk="false";
|
||||||
|
datas.timeDifference=getTimeDifference();
|
||||||
|
const xhrUserUpdate = new XMLHttpRequest();
|
||||||
|
if(datas.deleteOk!==undefined)
|
||||||
|
xhrUserUpdate.open("DELETE", apiUrl+configUsers.userRoutes+"/"+user.id);
|
||||||
|
else
|
||||||
|
xhrUserUpdate.open("PUT", apiUrl+configUsers.userRoutes+configUsers.updateUserInfos+user.id);
|
||||||
|
xhrUserUpdate.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
|
{
|
||||||
|
let response=JSON.parse(this.responseText);
|
||||||
|
if (this.status === 200 && response.message!=undefined)
|
||||||
|
{
|
||||||
|
if(Array.isArray(response.message))
|
||||||
|
response.message = response.message.join("<br>");
|
||||||
|
else
|
||||||
|
response.message = response.message;
|
||||||
|
addElement(divResponse, "p", response.message, "", ["success"]);
|
||||||
|
}
|
||||||
|
else if (response.errors)
|
||||||
|
{
|
||||||
|
if(Array.isArray(response.errors))
|
||||||
|
response.errors = response.errors.join("<br>");
|
||||||
|
else
|
||||||
|
response.errors = serverError;
|
||||||
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
||||||
|
// dans tous les cas, je mets à jour le contenu du formulaire :
|
||||||
|
getInfos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhrUserUpdate.setRequestHeader("Content-Type", "application/json");
|
||||||
|
xhrUserUpdate.setRequestHeader("Authorization", "Bearer "+user.token);
|
||||||
|
if(datas)
|
||||||
|
{
|
||||||
|
datas.output="html";
|
||||||
|
xhrUserUpdate.send(JSON.stringify(datas));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// on passe à la caisse ?
|
||||||
|
const abo9=document.getElementById("abo9");
|
||||||
|
const abo18=document.getElementById("abo18");
|
||||||
|
const abo36=document.getElementById("abo36");
|
||||||
|
const abo54=document.getElementById("abo54");
|
||||||
|
const CGV=document.getElementById("CGVOk");
|
||||||
|
const divWPBtns=document.getElementById("WPBtns");
|
||||||
|
divWPBtns.style.display="none";
|
||||||
|
abo9.addEventListener("change", function(e)
|
||||||
|
{
|
||||||
|
unCheckAllOthers("abo9");
|
||||||
|
});
|
||||||
|
abo18.addEventListener("change", function(e)
|
||||||
|
{
|
||||||
|
unCheckAllOthers("abo18");
|
||||||
|
});
|
||||||
|
abo36.addEventListener("change", function(e)
|
||||||
|
{
|
||||||
|
unCheckAllOthers("abo36");
|
||||||
|
});
|
||||||
|
abo54.addEventListener("change", function(e)
|
||||||
|
{
|
||||||
|
unCheckAllOthers("abo54");
|
||||||
|
});
|
||||||
|
CGV.addEventListener("change", function(e)
|
||||||
|
{
|
||||||
|
if(CGV.checked===true)
|
||||||
|
{
|
||||||
|
divWPBtns.style.display="block";
|
||||||
|
if(abo9.checked===true)
|
||||||
|
showBtnPayment("btn9");
|
||||||
|
else if(abo18.checked===true)
|
||||||
|
showBtnPayment("btn18");
|
||||||
|
else if(abo36.checked===true)
|
||||||
|
showBtnPayment("btn36");
|
||||||
|
else if(abo54.checked===true)
|
||||||
|
showBtnPayment("btn54");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
divWPBtns.style.display="none";
|
||||||
|
CGV.checked=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
divWPBtns.style.display="none";
|
||||||
|
});
|
||||||
|
|
||||||
|
// Liste des filleuls, si il y en a
|
||||||
|
const xhrGetGodchilds = new XMLHttpRequest();
|
||||||
|
xhrGetGodchilds.open("GET", apiUrl+configUsers.userRoutes+configUsers.getGodChilds);
|
||||||
|
xhrGetGodchilds.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
|
{
|
||||||
|
let response=JSON.parse(this.responseText), txtGodchilds="";
|
||||||
|
if (this.status === 200)
|
||||||
|
{
|
||||||
|
const nbGodchilds=response.length;
|
||||||
|
if(nbGodchilds===0)
|
||||||
|
txtGodchilds=infosUserNoGodchilds;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
txtGodchilds=infosUserNbGodChilds.replace("#NB", nbGodchilds);
|
||||||
|
for(let i in response)
|
||||||
|
txtGodchilds+=response[i].name+" ("+response[i].email+") ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addElement(divGodchilds, "p", txtGodchilds, "", ["info"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhrGetGodchilds.setRequestHeader("Authorization", "Bearer "+user.token);
|
||||||
|
xhrGetGodchilds.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
|
@ -5,36 +5,28 @@
|
|||||||
// Fichier de configuration côté client :
|
// Fichier de configuration côté client :
|
||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
|
||||||
|
|
||||||
// Importation des fonctions utile au script :
|
// Importation des fonctions utile au script :
|
||||||
import { removeLocaly } from "./tools/clientstorage.js";
|
import { removeLocaly } from "./tools/clientstorage.js";
|
||||||
import { addElement } from "./tools/dom.js";
|
import { addElement } from "./tools/dom.js";
|
||||||
import { helloDev } from "./tools/everywhere.js";
|
import { helloDev } from "./tools/everywhere.js";
|
||||||
import { getConfig } from "./tools/users.js";
|
|
||||||
|
|
||||||
// Dictionnaires :
|
// Dictionnaires :
|
||||||
const { serverError } = require("../../lang/"+lang+"/general");
|
const { serverError } = require("../../lang/"+lang+"/general");
|
||||||
const { byebyeMessage } = require("../../lang/"+lang+"/user");
|
const { byebyeMessage } = require("../../lang/"+lang+"/user");
|
||||||
|
|
||||||
|
const divResponse = document.getElementById("response");
|
||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
const divResponse = document.getElementById("response");
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
config = await getConfig();
|
removeLocaly("user");
|
||||||
if(!config)
|
removeLocaly("url");
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
removeLocaly("message");
|
||||||
else
|
addElement(divResponse, "p", byebyeMessage, "", ["success"]);
|
||||||
{
|
|
||||||
removeLocaly("user");
|
|
||||||
removeLocaly("url");
|
|
||||||
removeLocaly("message");
|
|
||||||
addElement(divResponse, "p", byebyeMessage, "", ["success"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
// -- GESTION DE LA PAGE PERMETTANT DE VALIDER UN CHANGEMENT D'EMAIL OU DE MOT DE PASSE
|
// -- GESTION DE LA PAGE PERMETTANT DE VALIDER LA DEMANDE DE SUPPRESSION DE SON COMPTE
|
||||||
|
|
||||||
/// Un token est transmis en paramètre de l'Url. Il a une validité limité dans le temps.
|
/// Un token est transmis en paramètre de l'Url. Il a une validité limitée dans le temps.
|
||||||
/// Si le token est ok, on valide la suppression, supprime la session de l'utilisateur et affiche un message de confirmation
|
/// Si le token est ok, on valide la suppression, supprime la session de l'utilisateur et affiche un message de confirmation.
|
||||||
|
|
||||||
// Fichier de configuration côté client :
|
// Fichier de configuration côté client :
|
||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
const { accountPage } = require("../../views/"+theme+"/config/"+lang+".js");
|
||||||
|
const { checkDeleteLinkRoute, userRoutes } = require("../../config/users");
|
||||||
|
|
||||||
// Importation des fonctions utile au script :
|
// Importation des fonctions utile au script :
|
||||||
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
||||||
@ -14,7 +15,7 @@ import { addElement } from "./tools/dom.js";
|
|||||||
import { helloDev } from "./tools/everywhere.js";
|
import { helloDev } from "./tools/everywhere.js";
|
||||||
import { loadMatomo } from "./tools/matomo.js";
|
import { loadMatomo } from "./tools/matomo.js";
|
||||||
import { getUrlParams } from "./tools/url.js";
|
import { getUrlParams } from "./tools/url.js";
|
||||||
import { checkSession, getConfig, setSession } from "./tools/users.js";
|
import { checkSession, setSession } from "./tools/users.js";
|
||||||
|
|
||||||
// Dictionnaires :
|
// Dictionnaires :
|
||||||
const { serverError } = require("../../lang/"+lang+"/general");
|
const { serverError } = require("../../lang/"+lang+"/general");
|
||||||
@ -24,46 +25,39 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
config = await getConfig();
|
const datas=getUrlParams();
|
||||||
if(!config)
|
if(datas && datas.t!==undefined)
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
const datas=getUrlParams();
|
const xhr = new XMLHttpRequest();
|
||||||
if(datas && datas.t!==undefined)
|
xhr.open("GET", apiUrl+userRoutes+checkDeleteLinkRoute+datas.t);
|
||||||
|
xhr.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
xhr.open("GET", apiUrl+config.userRoutes+config.checkDeleteLinkRoute+datas.t);
|
|
||||||
xhr.onreadystatechange = function()
|
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
let response=JSON.parse(this.responseText);
|
||||||
|
if (this.status === 200 && response.message != undefined)
|
||||||
{
|
{
|
||||||
let response=JSON.parse(this.responseText);
|
addElement(divResponse, "p", response.message, "", ["success"]);
|
||||||
if (this.status === 200 && response.message != undefined)
|
removeLocaly("user");
|
||||||
{
|
|
||||||
addElement(divResponse, "p", response.message, "", ["success"]);
|
|
||||||
removeLocaly("user");
|
|
||||||
}
|
|
||||||
else if (this.status === 400 && response.errors != undefined)
|
|
||||||
{
|
|
||||||
if(Array.isArray(response.errors))
|
|
||||||
response.errors = response.errors.join("<br>");
|
|
||||||
else
|
|
||||||
response.errors = serverError;
|
|
||||||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", configFrontEnd.accountPage), "", ["error"]);
|
|
||||||
}
|
}
|
||||||
|
else if (this.status === 400 && response.errors != undefined)
|
||||||
|
{
|
||||||
|
if(Array.isArray(response.errors))
|
||||||
|
response.errors = response.errors.join("<br>");
|
||||||
|
else
|
||||||
|
response.errors = serverError;
|
||||||
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", accountPage), "", ["error"]);
|
||||||
}
|
}
|
||||||
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
|
||||||
xhr.send();
|
|
||||||
}
|
}
|
||||||
|
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
||||||
|
xhr.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
// Fichier de configuration côté client :
|
// Fichier de configuration côté client :
|
||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
const configTemplate = require("../../views/"+theme+"/config/"+lang+".js");
|
||||||
|
const { getQuestionnairesWithoutAnswer, getRandomQuestionnairesRoute, getStatsAnswers, questionnaireRoutes, searchQuestionnaires, searchQuestionnairesRoute } = require("../../config/questionnaires");
|
||||||
|
|
||||||
// Fonctions utiles au script :
|
// Fonctions utiles au script :
|
||||||
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
||||||
@ -18,7 +19,7 @@ import { addElement } from "./tools/dom.js";
|
|||||||
import { helloDev, updateAccountLink } from "./tools/everywhere.js";
|
import { helloDev, updateAccountLink } from "./tools/everywhere.js";
|
||||||
import { getDatasFromInputs, setAttributesToInputs } from "./tools/forms.js";
|
import { getDatasFromInputs, setAttributesToInputs } from "./tools/forms.js";
|
||||||
import { isEmpty, replaceAll } from "../../tools/main";
|
import { isEmpty, replaceAll } from "../../tools/main";
|
||||||
import { checkSession, getConfig } from "./tools/users.js";
|
import { checkSession } from "./tools/users.js";
|
||||||
|
|
||||||
// Dictionnaires :
|
// Dictionnaires :
|
||||||
const { nbQuestionnaireWithoudAnswer, noQuestionnaireWithoudAnswer, statsUser } = require("../../lang/"+lang+"/answer");
|
const { nbQuestionnaireWithoudAnswer, noQuestionnaireWithoudAnswer, statsUser } = require("../../lang/"+lang+"/answer");
|
||||||
@ -45,186 +46,180 @@ const initialise = async () =>
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const config = await getConfig();
|
// Si l'utilisateur n'est pas connecté, pas la peine d'aller + loin :
|
||||||
if(!config)
|
const isConnected=await checkSession(["user"], "/"+configTemplate.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
||||||
addElement(divCrash, "p", serverError, "", ["error"]);
|
if(isConnected)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Si l'utilisateur n'est pas connecté, pas la peine d'aller + loin :
|
const user=getLocaly("user", true);
|
||||||
const isConnected=await checkSession(["user"], "/"+configFrontEnd.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
updateAccountLink(user.status, configTemplate);
|
||||||
if(isConnected)
|
addElement(divMessage, "h1", welcomeMessage.replace("#NAME", user.name));
|
||||||
|
divMain.style.display="block";
|
||||||
|
if(!isEmpty(getLocaly("message")))
|
||||||
{
|
{
|
||||||
const user=getLocaly("user", true);
|
addElement(divMessage, "p", getLocaly("message", true).message, "", [getLocaly("message", true).color], "", false);
|
||||||
updateAccountLink(user.status, configFrontEnd);
|
removeLocaly("message");
|
||||||
addElement(divMessage, "h1", welcomeMessage.replace("#NAME", user.name));
|
}
|
||||||
divMain.style.display="block";
|
// Initialisation du formulaire de recherche :
|
||||||
if(!isEmpty(getLocaly("message")))
|
setAttributesToInputs({ "searchQuestionnaires": searchQuestionnaires }, formSearch);
|
||||||
|
// Les stats :
|
||||||
|
const xhrStats = new XMLHttpRequest();
|
||||||
|
xhrStats.open("GET", apiUrl+questionnaireRoutes+getStatsAnswers+user.id);
|
||||||
|
xhrStats.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
{
|
{
|
||||||
addElement(divMessage, "p", getLocaly("message", true).message, "", [getLocaly("message", true).color], "", false);
|
let response=JSON.parse(this.responseText);
|
||||||
removeLocaly("message");
|
if (this.status === 200 && !isEmpty(response.nbAnswers) && response.nbAnswers!==0)// pas de stats si aucune réponse !
|
||||||
}
|
|
||||||
// Initialisation du formulaire de recherche :
|
|
||||||
setAttributesToInputs(config, formSearch);
|
|
||||||
// Les stats :
|
|
||||||
const xhrStats = new XMLHttpRequest();
|
|
||||||
xhrStats.open("GET", apiUrl+config.questionnaireRoutes+config.getStatsAnswers+user.id);
|
|
||||||
xhrStats.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
|
||||||
{
|
{
|
||||||
let response=JSON.parse(this.responseText);
|
const mapText =
|
||||||
if (this.status === 200 && !isEmpty(response.nbAnswers) && response.nbAnswers!==0)// pas de stats si aucune réponse !
|
|
||||||
{
|
{
|
||||||
const mapText =
|
NBANSWERS : response.nbAnswers,
|
||||||
{
|
NBQUESTIONNAIRES : response.nbQuestionnaires,
|
||||||
NBANSWERS : response.nbAnswers,
|
NBTOTQUESTIONNAIRES : response.general.nbPublished,
|
||||||
NBQUESTIONNAIRES : response.nbQuestionnaires,
|
AVGDURATION : response.avgDuration,
|
||||||
NBTOTQUESTIONNAIRES : response.general.nbPublished,
|
AVGCORRECTANSWERS : response.avgCorrectAnswers
|
||||||
AVGDURATION : response.avgDuration,
|
};
|
||||||
AVGCORRECTANSWERS : response.avgCorrectAnswers
|
addElement(divMessage, "p", replaceAll(statsUser, mapText), "", "", "", false);
|
||||||
};
|
|
||||||
addElement(divMessage, "p", replaceAll(statsUser, mapText), "", "", "", false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhrStats.setRequestHeader("Authorization", "Bearer "+user.token);
|
}
|
||||||
xhrStats.send();
|
xhrStats.setRequestHeader("Authorization", "Bearer "+user.token);
|
||||||
|
xhrStats.send();
|
||||||
|
|
||||||
// Par défaut, on affiche des derniers quizs proposés sans réponse :
|
// Par défaut, on affiche des derniers quizs proposés sans réponse :
|
||||||
const xhrLastQuizs = new XMLHttpRequest();
|
const xhrLastQuizs = new XMLHttpRequest();
|
||||||
xhrLastQuizs.open("GET", apiUrl+config.questionnaireRoutes+config.getQuestionnairesWithoutAnswer+""+user.id+"/"+0+"/"+configFrontEnd.nbQuestionnairesUserHomePage+"/html");
|
xhrLastQuizs.open("GET", apiUrl+questionnaireRoutes+getQuestionnairesWithoutAnswer+""+user.id+"/"+0+"/"+configTemplate.nbQuestionnairesUserHomePage+"/html");
|
||||||
xhrLastQuizs.onreadystatechange = function()
|
xhrLastQuizs.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
|
{
|
||||||
|
let response=JSON.parse(this.responseText);
|
||||||
|
if (this.status === 200)
|
||||||
|
{
|
||||||
|
if(response.nbTot===0)
|
||||||
|
addElement(quizIntro, "p", noQuestionnaireWithoudAnswer, "", ["success"]);
|
||||||
|
else if(response.html)
|
||||||
|
{
|
||||||
|
addElement(quizIntro, "p", nbQuestionnaireWithoudAnswer.replace("#NB", response.questionnaires.length), "", ["info"]);
|
||||||
|
quizListing.innerHTML=response.html;
|
||||||
|
window.location.hash="";// sinon les hash s'enchaînent...
|
||||||
|
window.location.assign("#quizsTitle");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addElement(quizs, "p", serverError, "", ["error"]);// revoir si intérêt d'afficher quelque chose
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addElement(quizs, "p", serverError, "", ["error"]); // idem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhrLastQuizs.setRequestHeader("Authorization", "Bearer "+user.token);
|
||||||
|
xhrLastQuizs.send();
|
||||||
|
|
||||||
|
// Traitement du lancement d'une recherche
|
||||||
|
// La recherche peut être lancée via la bouton submit ou un lien de pagination
|
||||||
|
const sendSearch = (type="search") =>
|
||||||
|
{
|
||||||
|
quizTitle.innerHTML=searchQuestionnaireResultTitle;
|
||||||
|
quizListing.innerHTML=""+"";
|
||||||
|
let datas=getDatasFromInputs(formSearch);
|
||||||
|
const xhrSearch = new XMLHttpRequest();
|
||||||
|
if(type=="search")
|
||||||
|
xhrSearch.open("POST", apiUrl+questionnaireRoutes+searchQuestionnairesRoute);
|
||||||
|
else if(type=="random")
|
||||||
|
xhrSearch.open("POST", apiUrl+questionnaireRoutes+getRandomQuestionnairesRoute);
|
||||||
|
xhrSearch.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
{
|
{
|
||||||
let response=JSON.parse(this.responseText);
|
let response=JSON.parse(this.responseText);
|
||||||
if (this.status === 200)
|
if (this.status === 200 && !isEmpty(response.nbTot))
|
||||||
{
|
{
|
||||||
if(response.nbTot===0)
|
if(response.nbTot===0)
|
||||||
addElement(quizIntro, "p", noQuestionnaireWithoudAnswer, "", ["success"]);
|
|
||||||
else if(response.html)
|
|
||||||
{
|
{
|
||||||
addElement(quizIntro, "p", nbQuestionnaireWithoudAnswer.replace("#NB", response.questionnaires.length), "", ["info"]);
|
addElement(quizIntro, "p", searchQuestionnaireWithNoResult, "", ["info"]);
|
||||||
quizListing.innerHTML=response.html;
|
|
||||||
window.location.hash="";// sinon les hash s'enchaînent...
|
window.location.hash="";// sinon les hash s'enchaînent...
|
||||||
window.location.assign("#quizsTitle");
|
window.location.assign("#quizsTitle");
|
||||||
}
|
}
|
||||||
else
|
else if(response.html)
|
||||||
addElement(quizs, "p", serverError, "", ["error"]);// revoir si intérêt d'afficher quelque chose
|
|
||||||
}
|
|
||||||
else
|
|
||||||
addElement(quizs, "p", serverError, "", ["error"]); // idem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xhrLastQuizs.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
||||||
xhrLastQuizs.send();
|
|
||||||
|
|
||||||
// Traitement du lancement d'une recherche
|
|
||||||
// La recherche peut être lancée via la bouton submit ou un lien de pagination
|
|
||||||
const sendSearch = (type="search") =>
|
|
||||||
{
|
|
||||||
quizTitle.innerHTML=searchQuestionnaireResultTitle;
|
|
||||||
quizListing.innerHTML=""+"";
|
|
||||||
let datas=getDatasFromInputs(formSearch);
|
|
||||||
const xhrSearch = new XMLHttpRequest();
|
|
||||||
if(type=="search")
|
|
||||||
xhrSearch.open("POST", config.apiUrl+config.questionnaireRoutes+config.searchQuestionnairesRoute);
|
|
||||||
else if(type=="random")
|
|
||||||
xhrSearch.open("POST", config.apiUrl+config.questionnaireRoutes+"/getrandom");// revoir : changer par la variable getRandomQuestionnairesRoute du fichier de config
|
|
||||||
xhrSearch.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
|
||||||
{
|
|
||||||
let response=JSON.parse(this.responseText);
|
|
||||||
if (this.status === 200 && !isEmpty(response.nbTot))
|
|
||||||
{
|
{
|
||||||
if(response.nbTot===0)
|
addElement(quizIntro, "p", searchQuestionnaireWithResult.replace("#NB", response.nbTot) , "", ["success"]);
|
||||||
|
quizListing.innerHTML=response.html;
|
||||||
|
window.location.hash="";
|
||||||
|
window.location.assign("#quizsTitle");
|
||||||
|
// Pagination nécessaire ?
|
||||||
|
// on commence par vider...
|
||||||
|
quizPaginationPrevious.innerHTML="";
|
||||||
|
quizPaginationNext.innerHTML="";
|
||||||
|
if(response.begin != 0)// peut retourner "0" et non 0 !
|
||||||
{
|
{
|
||||||
addElement(quizIntro, "p", searchQuestionnaireWithNoResult, "", ["info"]);
|
addElement(quizPaginationPrevious, "a", "<< "+previousPage , "previousRes", ["button"], { href: "#search" }); // revoir, les "<<" pourraient être gérées par le CSS
|
||||||
window.location.hash="";// sinon les hash s'enchaînent...
|
const previousPageElt=document.getElementById("previousRes");
|
||||||
window.location.assign("#quizsTitle");
|
// le retour à la page précédente peut se faire en cliquant sur le bouton ou via l'historique du navigateur
|
||||||
|
const goBackRes = () =>
|
||||||
|
{
|
||||||
|
let newBegin=response.begin-configTemplate.nbQuestionnairesUserHomePage;
|
||||||
|
if(newBegin<0) // ne devrait pas être possible..
|
||||||
|
newBegin=0;
|
||||||
|
document.getElementById("begin").value=newBegin;
|
||||||
|
sendSearch();
|
||||||
|
window.location.hash="";
|
||||||
|
window.location.assign("#quizsTitle");// pour remonter
|
||||||
|
}
|
||||||
|
previousPageElt.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
goBackRes();
|
||||||
|
});
|
||||||
|
/* semble provoqué bug ???
|
||||||
|
window.onpopstate = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
goBackRes();
|
||||||
|
};*/
|
||||||
}
|
}
|
||||||
else if(response.html)
|
if(response.end < (response.nbTot-1))// -1, car tableau commence à 0 !
|
||||||
{
|
{
|
||||||
addElement(quizIntro, "p", searchQuestionnaireWithResult.replace("#NB", response.nbTot) , "", ["success"]);
|
addElement(quizPaginationNext, "a", nextPage+ " >>", "nextRes", ["button"], { href: "#search" }, false);
|
||||||
quizListing.innerHTML=response.html;
|
const nextPageElt=document.getElementById("nextRes");
|
||||||
window.location.hash="";
|
nextPageElt.addEventListener("click", function(e)
|
||||||
window.location.assign("#quizsTitle");
|
|
||||||
// Pagination nécessaire ?
|
|
||||||
// on commence par vider...
|
|
||||||
quizPaginationPrevious.innerHTML="";
|
|
||||||
quizPaginationNext.innerHTML="";
|
|
||||||
if(response.begin != 0)// peut retourner "0" et non 0 !
|
|
||||||
{
|
{
|
||||||
addElement(quizPaginationPrevious, "a", "<< "+previousPage , "previousRes", ["button"], { href: "#search" }); // revoir, les "<<" pourraient être gérées par le CSS
|
e.preventDefault();
|
||||||
const previousPage=document.getElementById("previousRes");
|
document.getElementById("begin").value=response.end+1;
|
||||||
// le retour à la page précédente peut se faire en cliquant sur le bouton ou via l'historique du navigateur
|
sendSearch();
|
||||||
const goBackRes = () =>
|
window.location.hash="";// sinon les hash s'enchaînent...
|
||||||
{
|
window.location.assign("#quizsTitle"); // pour remonter
|
||||||
let newBegin=response.begin-configFrontEnd.nbQuestionnairesUserHomePage;
|
});
|
||||||
if(newBegin<0) // ne devrait pas être possible..
|
|
||||||
newBegin=0;
|
|
||||||
document.getElementById("begin").value=newBegin;
|
|
||||||
sendSearch();
|
|
||||||
window.location.hash="";
|
|
||||||
window.location.assign("#quizsTitle");// pour remonter
|
|
||||||
}
|
|
||||||
previousPage.addEventListener("click", function(e)
|
|
||||||
{
|
|
||||||
e.preventDefault();
|
|
||||||
goBackRes();
|
|
||||||
});
|
|
||||||
/* semble provoqué bug ???
|
|
||||||
window.onpopstate = function(e)
|
|
||||||
{
|
|
||||||
e.preventDefault();
|
|
||||||
goBackRes();
|
|
||||||
};*/
|
|
||||||
}
|
|
||||||
if(response.end < (response.nbTot-1))// -1, car tableau commence à 0 !
|
|
||||||
{
|
|
||||||
addElement(quizPaginationNext, "a", nextPage+ " >>", "nextRes", ["button"], { href: "#search" }, false);
|
|
||||||
const nextPage=document.getElementById("nextRes");
|
|
||||||
nextPage.addEventListener("click", function(e)
|
|
||||||
{
|
|
||||||
e.preventDefault();
|
|
||||||
document.getElementById("begin").value=response.end+1;
|
|
||||||
sendSearch();
|
|
||||||
window.location.hash="";// sinon les hash s'enchaînent...
|
|
||||||
window.location.assign("#quizsTitle"); // pour remonter
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
addElement(quizs, "p", serverError, "", ["error"]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
addElement(quizs, "p", serverError, "", ["error"]);
|
addElement(quizs, "p", serverError, "", ["error"]);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
xhrSearch.setRequestHeader("Content-Type", "application/json");
|
addElement(quizs, "p", serverError, "", ["error"]);
|
||||||
xhrSearch.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
||||||
if(datas)
|
|
||||||
{
|
|
||||||
datas.output="html";
|
|
||||||
xhrSearch.send(JSON.stringify(datas));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xhrSearch.setRequestHeader("Content-Type", "application/json");
|
||||||
btnRandom.addEventListener("click", function(e)
|
xhrSearch.setRequestHeader("Authorization", "Bearer "+user.token);
|
||||||
|
if(datas)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
datas.output="html";
|
||||||
document.getElementById("begin").value=0;
|
xhrSearch.send(JSON.stringify(datas));
|
||||||
sendSearch("random");
|
}
|
||||||
});
|
|
||||||
|
|
||||||
formSearch.addEventListener("submit", function(e)
|
|
||||||
{
|
|
||||||
e.preventDefault();
|
|
||||||
document.getElementById("begin").value=0;
|
|
||||||
sendSearch();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btnRandom.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
document.getElementById("begin").value=0;
|
||||||
|
sendSearch("random");
|
||||||
|
});
|
||||||
|
|
||||||
|
formSearch.addEventListener("submit", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
document.getElementById("begin").value=0;
|
||||||
|
sendSearch();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
// Fichier de configuration côté client :
|
// Fichier de configuration côté client :
|
||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
const { connectionPage, userHomePage } = require("../../views/"+theme+"/config/"+lang+".js");
|
||||||
|
const { connectionWithLinkRoute, userRoutes } = require("../../config/users");
|
||||||
|
|
||||||
// Importation des fonctions utile au script :
|
// Importation des fonctions utile au script :
|
||||||
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
||||||
@ -17,7 +18,7 @@ import { addElement } from "./tools/dom.js";
|
|||||||
import { helloDev } from "./tools/everywhere.js";
|
import { helloDev } from "./tools/everywhere.js";
|
||||||
import { isEmpty } from "../../tools/main";
|
import { isEmpty } from "../../tools/main";
|
||||||
import { getUrlParams } from "./tools/url.js";
|
import { getUrlParams } from "./tools/url.js";
|
||||||
import { checkAnswerDatas, checkSession, getConfig, getTimeDifference, setSession } from "./tools/users.js";
|
import { checkAnswerDatas, checkSession, getTimeDifference, setSession } from "./tools/users.js";
|
||||||
|
|
||||||
// Dictionnaires :
|
// Dictionnaires :
|
||||||
const { serverError } = require("../../lang/"+lang+"/general");
|
const { serverError } = require("../../lang/"+lang+"/general");
|
||||||
@ -27,67 +28,59 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
config = await getConfig();
|
// si l'utilisateur est déjà connecté, pas la peine d'aller + loin :
|
||||||
if(!config)
|
const isConnected=await checkSession();
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
if(isConnected)
|
||||||
|
{
|
||||||
|
saveLocaly("message", { message: alreadyConnected, color:"info" });// pour l'afficher sur la page suivante
|
||||||
|
const user=getLocaly("user", true);
|
||||||
|
window.location.assign("/"+userHomePage);// type de connexion possible que pour les simples users
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// si l'utilisateur est déjà connecté, pas la peine d'aller + loin :
|
let datas=getUrlParams();
|
||||||
const isConnected=await checkSession();
|
if(datas && datas.t!==undefined)
|
||||||
if(isConnected)
|
|
||||||
{
|
{
|
||||||
saveLocaly("message", { message: alreadyConnected, color:"information" });// pour l'afficher sur la page suivante
|
const xhr = new XMLHttpRequest();
|
||||||
const user=getLocaly("user", true);
|
xhr.open("POST", apiUrl+userRoutes+connectionWithLinkRoute);
|
||||||
const homePage=user.status+"HomePage";
|
xhr.onreadystatechange = function()
|
||||||
window.location.assign("/"+configFrontEnd[homePage]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
let datas=getUrlParams();
|
|
||||||
if(datas && datas.t!==undefined)
|
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
xhr.open("POST", apiUrl+config.userRoutes+config.connectionWithLinkRoute);
|
|
||||||
xhr.onreadystatechange = function()
|
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
let response=JSON.parse(this.responseText);
|
||||||
|
if (this.status === 200 && !isEmpty(response.userId) && !isEmpty(response.connexionTime) && !isEmpty(response.token))
|
||||||
{
|
{
|
||||||
let response=JSON.parse(this.responseText);
|
let connexionMaxTime=Date.now();
|
||||||
if (this.status === 200 && !isEmpty(response.userId) && !isEmpty(response.connexionTime) && !isEmpty(response.token))
|
if(response.connexionTime.endsWith("days"))
|
||||||
{
|
connexionMaxTime+=parseInt(response.connexionTime,10)*24*3600*1000;
|
||||||
let connexionMaxTime=Date.now();
|
|
||||||
if(response.connexionTime.endsWith("days"))
|
|
||||||
connexionMaxTime+=parseInt(response.connexionTime,10)*24*3600*1000;
|
|
||||||
else
|
|
||||||
connexionMaxTime+=parseInt(response.connexionTime,10)*3600*1000;
|
|
||||||
setSession(response.userId, response.token, connexionMaxTime);
|
|
||||||
removeLocaly("lastAnswer");// ! important pour ne pas enregister plusieurs fois le résultat
|
|
||||||
addElement(divResponse, "p", validationMessage, "", ["success"]);// au cas où blocage redirection
|
|
||||||
window.location.assign("/"+configFrontEnd.userHomePage);// connexion par lien ne concerne que les simples "user"
|
|
||||||
}
|
|
||||||
else if ((this.status === 401 || this.status === 403) && response.errors != undefined)
|
|
||||||
{
|
|
||||||
if(Array.isArray(response.errors))
|
|
||||||
response.errors = response.errors.join("<br>");
|
|
||||||
else
|
|
||||||
response.errors = serverError;
|
|
||||||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", configFrontEnd.connectionPage), "", ["error"]);
|
connexionMaxTime+=parseInt(response.connexionTime,10)*3600*1000;
|
||||||
|
setSession(response.userId, response.token, connexionMaxTime);
|
||||||
|
removeLocaly("lastAnswer");// ! important pour ne pas enregister plusieurs fois le résultat
|
||||||
|
addElement(divResponse, "p", validationMessage, "", ["success"]);// au cas où blocage redirection
|
||||||
|
window.location.assign("/"+userHomePage);// connexion par lien ne concerne que les simples "user"
|
||||||
}
|
}
|
||||||
|
else if ((this.status === 401 || this.status === 403) && response.errors != undefined)
|
||||||
|
{
|
||||||
|
if(Array.isArray(response.errors))
|
||||||
|
response.errors = response.errors.join("<br>");
|
||||||
|
else
|
||||||
|
response.errors = serverError;
|
||||||
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", connectionPage), "", ["error"]);
|
||||||
}
|
}
|
||||||
datas.timeDifference=getTimeDifference(config);
|
|
||||||
// si l'utilisateur a précédement répondu à un quiz, j'ajoute les infos de son résultat :
|
|
||||||
datas=checkAnswerDatas(datas);
|
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
|
||||||
xhr.send(JSON.stringify(datas));
|
|
||||||
}
|
}
|
||||||
|
datas.timeDifference=getTimeDifference();
|
||||||
|
// si l'utilisateur a précédement répondu à un quiz, j'ajoute les infos de son résultat :
|
||||||
|
datas=checkAnswerDatas(datas);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
xhr.send(JSON.stringify(datas));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import { helloDev, updateAccountLink } from "./tools/everywhere.js";
|
|||||||
import { empyAndHideForm, getDatasFromInputs, setAttributesToInputs } from "./tools/forms.js";
|
import { empyAndHideForm, getDatasFromInputs, setAttributesToInputs } from "./tools/forms.js";
|
||||||
import { dateFormat, isEmpty } from "../../tools/main";
|
import { dateFormat, isEmpty } from "../../tools/main";
|
||||||
import { getUrlParams } from "./tools/url.js";
|
import { getUrlParams } from "./tools/url.js";
|
||||||
import { checkSession, getConfig } from "./tools/users.js";
|
import { checkSession } from "./tools/users.js";
|
||||||
|
|
||||||
// Dictionnaires :
|
// Dictionnaires :
|
||||||
const { addOkMessage, deleteBtnTxt, serverError, updateBtnTxt } = require("../../lang/"+lang+"/general");
|
const { addOkMessage, deleteBtnTxt, serverError, updateBtnTxt } = require("../../lang/"+lang+"/general");
|
||||||
|
@ -6,14 +6,15 @@
|
|||||||
// Fichier de configuration côté client :
|
// Fichier de configuration côté client :
|
||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
const { accountPage, userHomePage } = require("../../views/"+theme+"/config/"+lang+".js");
|
||||||
|
const { checkNewLoginLinkRoute, userRoutes } = require("../../config/users");
|
||||||
|
|
||||||
// Importation des fonctions utile au script :
|
// Importation des fonctions utile au script :
|
||||||
import { getLocaly, saveLocaly } from "./tools/clientstorage.js";
|
import { getLocaly, saveLocaly } from "./tools/clientstorage.js";
|
||||||
import { addElement } from "./tools/dom.js";
|
import { addElement } from "./tools/dom.js";
|
||||||
import { helloDev, updateAccountLink } from "./tools/everywhere.js";
|
import { helloDev, updateAccountLink } from "./tools/everywhere.js";
|
||||||
import { getUrlParams } from "./tools/url.js";
|
import { getUrlParams } from "./tools/url.js";
|
||||||
import { checkSession, getConfig, setSession } from "./tools/users.js";
|
import { checkSession, setSession } from "./tools/users.js";
|
||||||
|
|
||||||
// Dictionnaires :
|
// Dictionnaires :
|
||||||
const { serverError } = require("../../lang/"+lang+"/general");
|
const { serverError } = require("../../lang/"+lang+"/general");
|
||||||
@ -23,47 +24,40 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
config = await getConfig();
|
const datas=getUrlParams();
|
||||||
if(!config)
|
if(datas && datas.t!==undefined)
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
const datas=getUrlParams();
|
const xhr = new XMLHttpRequest();
|
||||||
if(datas && datas.t!==undefined)
|
xhr.open("GET", apiUrl+userRoutes+checkNewLoginLinkRoute+datas.t);
|
||||||
|
xhr.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
xhr.open("GET", apiUrl+config.userRoutes+config.checkNewLoginLinkRoute+datas.t);
|
|
||||||
xhr.onreadystatechange = function()
|
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
let response=JSON.parse(this.responseText);
|
||||||
|
if (this.status === 200 && response.message != undefined)
|
||||||
{
|
{
|
||||||
let response=JSON.parse(this.responseText);
|
saveLocaly("message", { message: response.message, color:"success" });// pour l'afficher sur la page suivante
|
||||||
if (this.status === 200 && response.message != undefined)
|
addElement(divResponse, "p", response.message, "", ["success"]);// au cas où blocage redirection
|
||||||
{
|
window.location.assign("/"+userHomePage);// que user possible ici
|
||||||
saveLocaly("message", { message: response.message, color:"success" });// pour l'afficher sur la page suivante
|
|
||||||
addElement(divResponse, "p", response.message, "", ["success"]);// au cas où blocage redirection
|
|
||||||
window.location.assign("/"+configFrontEnd.userHomePage);// que user possible ici
|
|
||||||
}
|
|
||||||
else if (this.status === 404 && response.errors != undefined)
|
|
||||||
{
|
|
||||||
if(Array.isArray(response.errors))
|
|
||||||
response.errors = response.errors.join("<br>");
|
|
||||||
else
|
|
||||||
response.errors = serverError;
|
|
||||||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", configFrontEnd.accountPage), "", ["error"]);
|
|
||||||
}
|
}
|
||||||
|
else if (this.status === 404 && response.errors != undefined)
|
||||||
|
{
|
||||||
|
if(Array.isArray(response.errors))
|
||||||
|
response.errors = response.errors.join("<br>");
|
||||||
|
else
|
||||||
|
response.errors = serverError;
|
||||||
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", accountPage), "", ["error"]);
|
||||||
}
|
}
|
||||||
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
|
||||||
xhr.send();
|
|
||||||
}
|
}
|
||||||
|
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
||||||
|
xhr.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
|
|
||||||
const configTemplate = require("../../views/"+theme+"/config/"+lang+".js");
|
const configTemplate = require("../../views/"+theme+"/config/"+lang+".js");// besoin de toutes les déclarations, car appel dynamique : configTemplate[homePage]
|
||||||
const configUsers = require("../../config/users");
|
const configUsers = require("../../config/users");// idem pour configurer formulaire
|
||||||
|
|
||||||
// Importation des fonctions utiles au script :
|
// Importation des fonctions utiles au script :
|
||||||
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
||||||
|
@ -8,27 +8,14 @@ import { checkLoginRoute, timeDifferenceMax, timeDifferenceMin, userRoutes } fr
|
|||||||
import { getLocaly, removeLocaly, saveLocaly } from "./clientstorage.js";
|
import { getLocaly, removeLocaly, saveLocaly } from "./clientstorage.js";
|
||||||
import { isEmpty } from "../../../tools/main";
|
import { isEmpty } from "../../../tools/main";
|
||||||
|
|
||||||
// Récupère les données de configuration des utilisateurs
|
|
||||||
// À terme, un fichier statique importable comme module devrait éviter une requête ajax
|
|
||||||
export const getConfig = async () =>
|
|
||||||
{
|
|
||||||
return new Promise((resolve, reject) =>
|
|
||||||
{
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("GET", apiUrl+"/user/getconfig");
|
|
||||||
xhr.onload = () => resolve(JSON.parse(xhr.responseText));
|
|
||||||
xhr.onerror = () => reject(xhr.statusText);
|
|
||||||
xhr.send();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getTimeDifference = () =>
|
export const getTimeDifference = () =>
|
||||||
{
|
{
|
||||||
// multiplier par -1, car c'est ce qu'il faut "ajouter" à l'heure UTC pour revenir en heure locale qui m'intéresse et non l'inverse
|
// multiplier par -1, car c'est ce qu'il faut "ajouter" à l'heure UTC pour revenir en heure locale qui m'intéresse et non l'inverse
|
||||||
const timeLocal=new Date().getTimezoneOffset()*-1;
|
const timeLocal=new Date().getTimezoneOffset()*-1;
|
||||||
if(timeLocal > timeDifferenceMax || timeLocal < timeDifferenceMin)
|
if(timeLocal > timeDifferenceMax || timeLocal < timeDifferenceMin)
|
||||||
return 0;
|
return 0;
|
||||||
else return timeLocal;
|
else
|
||||||
|
return timeLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On enlève volontairement les 0/O pour éviter les confusions !
|
// On enlève volontairement les 0/O pour éviter les confusions !
|
||||||
|
@ -7,14 +7,15 @@
|
|||||||
// Fichier de configuration côté client :
|
// Fichier de configuration côté client :
|
||||||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||||||
const lang=availableLangs[0];
|
const lang=availableLangs[0];
|
||||||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
const { accountPage } = require("../../views/"+theme+"/config/"+lang+".js");
|
||||||
|
const { userRoutes, unsubscribeRoute } = require("../../config/users");
|
||||||
|
|
||||||
// Importation des fonctions utile au script :
|
// Importation des fonctions utile au script :
|
||||||
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
||||||
import { addElement } from "./tools/dom.js";
|
import { addElement } from "./tools/dom.js";
|
||||||
import { helloDev } from "./tools/everywhere.js";
|
import { helloDev } from "./tools/everywhere.js";
|
||||||
import { getUrlParams } from "./tools/url.js";
|
import { getUrlParams } from "./tools/url.js";
|
||||||
import { checkSession, getConfig, setSession } from "./tools/users.js";
|
import { checkSession, setSession } from "./tools/users.js";
|
||||||
|
|
||||||
// Dictionnaires :
|
// Dictionnaires :
|
||||||
const { serverError } = require("../../lang/"+lang+"/general");
|
const { serverError } = require("../../lang/"+lang+"/general");
|
||||||
@ -24,34 +25,27 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
config = await getConfig();
|
const datas=getUrlParams();
|
||||||
if(!config)
|
if(datas && datas.t!==undefined)
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
const datas=getUrlParams();
|
const xhr = new XMLHttpRequest();
|
||||||
if(datas && datas.t!==undefined)
|
xhr.open("GET", apiUrl+userRoutes+unsubscribeRoute+datas.t);
|
||||||
|
xhr.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
xhr.open("GET", apiUrl+config.userRoutes+config.unsubscribeRoute+datas.t);
|
|
||||||
xhr.onreadystatechange = function()
|
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
let response=JSON.parse(this.responseText);
|
||||||
{
|
if (this.status === 200 && response.message != undefined)
|
||||||
let response=JSON.parse(this.responseText);
|
addElement(divResponse, "p", response.message.replace("#URL", accountPage), "", ["success"]);
|
||||||
if (this.status === 200 && response.message != undefined)
|
else
|
||||||
addElement(divResponse, "p", response.message.replace("#URL", configFrontEnd.accountPage), "", ["success"]);
|
addElement(divResponse, "p", unsubscriptionFail.replace("#URL", accountPage), "", ["error"]);
|
||||||
else
|
|
||||||
addElement(divResponse, "p", unsubscriptionFail.replace("#URL", configFrontEnd.accountPage), "", ["error"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xhr.send();
|
|
||||||
}
|
}
|
||||||
|
xhr.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
|
@ -7,7 +7,7 @@ const authAdmin = require("../middleware/authAdmin");
|
|||||||
const userCtrl = require("../controllers/user");
|
const userCtrl = require("../controllers/user");
|
||||||
const subscriptionCtrl = require("../controllers/subscription");
|
const subscriptionCtrl = require("../controllers/subscription");
|
||||||
|
|
||||||
router.get("/getconfig", userCtrl.getConfig); // ne devrait plus être utile !
|
//router.get("/getconfig", userCtrl.getConfig); // ne devrait plus être utile !
|
||||||
|
|
||||||
router.post("/getgodfatherid", userCtrl.getGodfatherId);
|
router.post("/getgodfatherid", userCtrl.getGodfatherId);
|
||||||
router.post("/isemailfree", userCtrl.checkEmailIsFree);
|
router.post("/isemailfree", userCtrl.checkEmailIsFree);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user