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";
|
||||||
@ -45,14 +47,9 @@ helloDev();
|
|||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
const config = await getConfig();
|
|
||||||
if(!config)
|
|
||||||
addElement(divCrash, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Si l'utilisateur n'est pas connecté avec le bon statut, pas la peine d'aller + loin :
|
// Si l'utilisateur n'est pas connecté avec le bon statut, pas la peine d'aller + loin :
|
||||||
const isConnected=await checkSession(["user"], "/"+configFrontEnd.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
const isConnected=await checkSession(["user"], "/"+configTemplate.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
||||||
if(isConnected)
|
if(isConnected)
|
||||||
{
|
{
|
||||||
divMain.style.display="block";
|
divMain.style.display="block";
|
||||||
@ -66,9 +63,9 @@ const initialise = async () =>
|
|||||||
removeLocaly("message");
|
removeLocaly("message");
|
||||||
}
|
}
|
||||||
const user=getLocaly("user", true);
|
const user=getLocaly("user", true);
|
||||||
updateAccountLink(user.status, configFrontEnd);
|
updateAccountLink(user.status, configTemplate);
|
||||||
// Initialise le formulaire permettant de mettre à jour les infos :
|
// Initialise le formulaire permettant de mettre à jour les infos :
|
||||||
setAttributesToInputs(config, formAccount);
|
setAttributesToInputs(configUsers, formAccount);
|
||||||
// Certains navigateurs remplissent les champs password :
|
// Certains navigateurs remplissent les champs password :
|
||||||
newPassword.value="";
|
newPassword.value="";
|
||||||
|
|
||||||
@ -76,7 +73,7 @@ const initialise = async () =>
|
|||||||
const getInfos = () =>
|
const getInfos = () =>
|
||||||
{
|
{
|
||||||
const xhrGetInfos = new XMLHttpRequest();
|
const xhrGetInfos = new XMLHttpRequest();
|
||||||
xhrGetInfos.open("GET", apiUrl+config.userRoutes+config.getUserInfos+user.id);
|
xhrGetInfos.open("GET", apiUrl+configUsers.userRoutes+configUsers.getUserInfos+user.id);
|
||||||
xhrGetInfos.onreadystatechange = function()
|
xhrGetInfos.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -102,7 +99,7 @@ const initialise = async () =>
|
|||||||
formAccount.elements["d"+response.Subscription.receiptDays[i]].checked="checked";
|
formAccount.elements["d"+response.Subscription.receiptDays[i]].checked="checked";
|
||||||
// "codes" possibles à transmettre pour parrainer d'autres utilisateurs
|
// "codes" possibles à transmettre pour parrainer d'autres utilisateurs
|
||||||
showGFEmail.innerHTML=response.User.email;
|
showGFEmail.innerHTML=response.User.email;
|
||||||
showGFCode.innerHTML=config.beginCodeGodfather+response.User.id;
|
showGFCode.innerHTML=beginCodeGodfather+response.User.id;
|
||||||
}
|
}
|
||||||
const beginSubTS=new Date(response.Subscription.createdAt).getTime();
|
const beginSubTS=new Date(response.Subscription.createdAt).getTime();
|
||||||
const nbDaysOk=response.Subscription.numberOfDays-Math.round((Date.now()-beginSubTS)/1000/3600/24);
|
const nbDaysOk=response.Subscription.numberOfDays-Math.round((Date.now()-beginSubTS)/1000/3600/24);
|
||||||
@ -138,12 +135,12 @@ const initialise = async () =>
|
|||||||
datas.noticeOk="false";
|
datas.noticeOk="false";
|
||||||
if(datas.newsletterOk===undefined)
|
if(datas.newsletterOk===undefined)
|
||||||
datas.newsletterOk="false";
|
datas.newsletterOk="false";
|
||||||
datas.timeDifference=getTimeDifference(config);
|
datas.timeDifference=getTimeDifference();
|
||||||
const xhrUserUpdate = new XMLHttpRequest();
|
const xhrUserUpdate = new XMLHttpRequest();
|
||||||
if(datas.deleteOk!==undefined)
|
if(datas.deleteOk!==undefined)
|
||||||
xhrUserUpdate.open("DELETE", apiUrl+config.userRoutes+"/"+user.id);
|
xhrUserUpdate.open("DELETE", apiUrl+configUsers.userRoutes+"/"+user.id);
|
||||||
else
|
else
|
||||||
xhrUserUpdate.open("PUT", apiUrl+config.userRoutes+config.updateUserInfos+user.id);
|
xhrUserUpdate.open("PUT", apiUrl+configUsers.userRoutes+configUsers.updateUserInfos+user.id);
|
||||||
xhrUserUpdate.onreadystatechange = function()
|
xhrUserUpdate.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -229,7 +226,7 @@ const initialise = async () =>
|
|||||||
|
|
||||||
// Liste des filleuls, si il y en a
|
// Liste des filleuls, si il y en a
|
||||||
const xhrGetGodchilds = new XMLHttpRequest();
|
const xhrGetGodchilds = new XMLHttpRequest();
|
||||||
xhrGetGodchilds.open("GET", apiUrl+config.userRoutes+config.getGodChilds);
|
xhrGetGodchilds.open("GET", apiUrl+configUsers.userRoutes+configUsers.getGodChilds);
|
||||||
xhrGetGodchilds.onreadystatechange = function()
|
xhrGetGodchilds.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -254,7 +251,6 @@ const initialise = async () =>
|
|||||||
xhrGetGodchilds.send();
|
xhrGetGodchilds.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
addElement(divCrash, "p", serverError, "", ["error"]);
|
addElement(divCrash, "p", serverError, "", ["error"]);
|
||||||
|
@ -5,37 +5,29 @@
|
|||||||
// 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();
|
|
||||||
if(!config)
|
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
removeLocaly("user");
|
removeLocaly("user");
|
||||||
removeLocaly("url");
|
removeLocaly("url");
|
||||||
removeLocaly("message");
|
removeLocaly("message");
|
||||||
addElement(divResponse, "p", byebyeMessage, "", ["success"]);
|
addElement(divResponse, "p", byebyeMessage, "", ["success"]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
||||||
|
@ -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,21 +25,15 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
config = await getConfig();
|
|
||||||
if(!config)
|
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
const datas=getUrlParams();
|
const datas=getUrlParams();
|
||||||
if(datas && datas.t!==undefined)
|
if(datas && datas.t!==undefined)
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", apiUrl+config.userRoutes+config.checkDeleteLinkRoute+datas.t);
|
xhr.open("GET", apiUrl+userRoutes+checkDeleteLinkRoute+datas.t);
|
||||||
xhr.onreadystatechange = function()
|
xhr.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -58,14 +53,13 @@ const initialise = async () =>
|
|||||||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", configFrontEnd.accountPage), "", ["error"]);
|
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", accountPage), "", ["error"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
||||||
|
@ -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");
|
||||||
@ -44,18 +45,13 @@ helloDev();
|
|||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
const config = await getConfig();
|
|
||||||
if(!config)
|
|
||||||
addElement(divCrash, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Si l'utilisateur n'est pas connecté, pas la peine d'aller + loin :
|
// Si l'utilisateur n'est pas connecté, pas la peine d'aller + loin :
|
||||||
const isConnected=await checkSession(["user"], "/"+configFrontEnd.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
const isConnected=await checkSession(["user"], "/"+configTemplate.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
||||||
if(isConnected)
|
if(isConnected)
|
||||||
{
|
{
|
||||||
const user=getLocaly("user", true);
|
const user=getLocaly("user", true);
|
||||||
updateAccountLink(user.status, configFrontEnd);
|
updateAccountLink(user.status, configTemplate);
|
||||||
addElement(divMessage, "h1", welcomeMessage.replace("#NAME", user.name));
|
addElement(divMessage, "h1", welcomeMessage.replace("#NAME", user.name));
|
||||||
divMain.style.display="block";
|
divMain.style.display="block";
|
||||||
if(!isEmpty(getLocaly("message")))
|
if(!isEmpty(getLocaly("message")))
|
||||||
@ -64,10 +60,10 @@ const initialise = async () =>
|
|||||||
removeLocaly("message");
|
removeLocaly("message");
|
||||||
}
|
}
|
||||||
// Initialisation du formulaire de recherche :
|
// Initialisation du formulaire de recherche :
|
||||||
setAttributesToInputs(config, formSearch);
|
setAttributesToInputs({ "searchQuestionnaires": searchQuestionnaires }, formSearch);
|
||||||
// Les stats :
|
// Les stats :
|
||||||
const xhrStats = new XMLHttpRequest();
|
const xhrStats = new XMLHttpRequest();
|
||||||
xhrStats.open("GET", apiUrl+config.questionnaireRoutes+config.getStatsAnswers+user.id);
|
xhrStats.open("GET", apiUrl+questionnaireRoutes+getStatsAnswers+user.id);
|
||||||
xhrStats.onreadystatechange = function()
|
xhrStats.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -92,7 +88,7 @@ const initialise = async () =>
|
|||||||
|
|
||||||
// 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)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -128,9 +124,9 @@ const initialise = async () =>
|
|||||||
let datas=getDatasFromInputs(formSearch);
|
let datas=getDatasFromInputs(formSearch);
|
||||||
const xhrSearch = new XMLHttpRequest();
|
const xhrSearch = new XMLHttpRequest();
|
||||||
if(type=="search")
|
if(type=="search")
|
||||||
xhrSearch.open("POST", config.apiUrl+config.questionnaireRoutes+config.searchQuestionnairesRoute);
|
xhrSearch.open("POST", apiUrl+questionnaireRoutes+searchQuestionnairesRoute);
|
||||||
else if(type=="random")
|
else if(type=="random")
|
||||||
xhrSearch.open("POST", config.apiUrl+config.questionnaireRoutes+"/getrandom");// revoir : changer par la variable getRandomQuestionnairesRoute du fichier de config
|
xhrSearch.open("POST", apiUrl+questionnaireRoutes+getRandomQuestionnairesRoute);
|
||||||
xhrSearch.onreadystatechange = function()
|
xhrSearch.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -157,11 +153,11 @@ const initialise = async () =>
|
|||||||
if(response.begin != 0)// peut retourner "0" et non 0 !
|
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
|
addElement(quizPaginationPrevious, "a", "<< "+previousPage , "previousRes", ["button"], { href: "#search" }); // revoir, les "<<" pourraient être gérées par le CSS
|
||||||
const previousPage=document.getElementById("previousRes");
|
const previousPageElt=document.getElementById("previousRes");
|
||||||
// le retour à la page précédente peut se faire en cliquant sur le bouton ou via l'historique du navigateur
|
// le retour à la page précédente peut se faire en cliquant sur le bouton ou via l'historique du navigateur
|
||||||
const goBackRes = () =>
|
const goBackRes = () =>
|
||||||
{
|
{
|
||||||
let newBegin=response.begin-configFrontEnd.nbQuestionnairesUserHomePage;
|
let newBegin=response.begin-configTemplate.nbQuestionnairesUserHomePage;
|
||||||
if(newBegin<0) // ne devrait pas être possible..
|
if(newBegin<0) // ne devrait pas être possible..
|
||||||
newBegin=0;
|
newBegin=0;
|
||||||
document.getElementById("begin").value=newBegin;
|
document.getElementById("begin").value=newBegin;
|
||||||
@ -169,7 +165,7 @@ const initialise = async () =>
|
|||||||
window.location.hash="";
|
window.location.hash="";
|
||||||
window.location.assign("#quizsTitle");// pour remonter
|
window.location.assign("#quizsTitle");// pour remonter
|
||||||
}
|
}
|
||||||
previousPage.addEventListener("click", function(e)
|
previousPageElt.addEventListener("click", function(e)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
goBackRes();
|
goBackRes();
|
||||||
@ -184,8 +180,8 @@ const initialise = async () =>
|
|||||||
if(response.end < (response.nbTot-1))// -1, car tableau commence à 0 !
|
if(response.end < (response.nbTot-1))// -1, car tableau commence à 0 !
|
||||||
{
|
{
|
||||||
addElement(quizPaginationNext, "a", nextPage+ " >>", "nextRes", ["button"], { href: "#search" }, false);
|
addElement(quizPaginationNext, "a", nextPage+ " >>", "nextRes", ["button"], { href: "#search" }, false);
|
||||||
const nextPage=document.getElementById("nextRes");
|
const nextPageElt=document.getElementById("nextRes");
|
||||||
nextPage.addEventListener("click", function(e)
|
nextPageElt.addEventListener("click", function(e)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
document.getElementById("begin").value=response.end+1;
|
document.getElementById("begin").value=response.end+1;
|
||||||
@ -226,7 +222,6 @@ const initialise = async () =>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
console.error(e);
|
console.error(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,24 +28,17 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
config = await getConfig();
|
|
||||||
if(!config)
|
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// si l'utilisateur est déjà connecté, pas la peine d'aller + loin :
|
// si l'utilisateur est déjà connecté, pas la peine d'aller + loin :
|
||||||
const isConnected=await checkSession();
|
const isConnected=await checkSession();
|
||||||
if(isConnected)
|
if(isConnected)
|
||||||
{
|
{
|
||||||
saveLocaly("message", { message: alreadyConnected, color:"information" });// pour l'afficher sur la page suivante
|
saveLocaly("message", { message: alreadyConnected, color:"info" });// pour l'afficher sur la page suivante
|
||||||
const user=getLocaly("user", true);
|
const user=getLocaly("user", true);
|
||||||
const homePage=user.status+"HomePage";
|
window.location.assign("/"+userHomePage);// type de connexion possible que pour les simples users
|
||||||
window.location.assign("/"+configFrontEnd[homePage]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -52,7 +46,7 @@ const initialise = async () =>
|
|||||||
if(datas && datas.t!==undefined)
|
if(datas && datas.t!==undefined)
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open("POST", apiUrl+config.userRoutes+config.connectionWithLinkRoute);
|
xhr.open("POST", apiUrl+userRoutes+connectionWithLinkRoute);
|
||||||
xhr.onreadystatechange = function()
|
xhr.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -68,7 +62,7 @@ const initialise = async () =>
|
|||||||
setSession(response.userId, response.token, connexionMaxTime);
|
setSession(response.userId, response.token, connexionMaxTime);
|
||||||
removeLocaly("lastAnswer");// ! important pour ne pas enregister plusieurs fois le résultat
|
removeLocaly("lastAnswer");// ! important pour ne pas enregister plusieurs fois le résultat
|
||||||
addElement(divResponse, "p", validationMessage, "", ["success"]);// au cas où blocage redirection
|
addElement(divResponse, "p", validationMessage, "", ["success"]);// au cas où blocage redirection
|
||||||
window.location.assign("/"+configFrontEnd.userHomePage);// connexion par lien ne concerne que les simples "user"
|
window.location.assign("/"+userHomePage);// connexion par lien ne concerne que les simples "user"
|
||||||
}
|
}
|
||||||
else if ((this.status === 401 || this.status === 403) && response.errors != undefined)
|
else if ((this.status === 401 || this.status === 403) && response.errors != undefined)
|
||||||
{
|
{
|
||||||
@ -79,10 +73,10 @@ const initialise = async () =>
|
|||||||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", configFrontEnd.connectionPage), "", ["error"]);
|
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", connectionPage), "", ["error"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
datas.timeDifference=getTimeDifference(config);
|
datas.timeDifference=getTimeDifference();
|
||||||
// si l'utilisateur a précédement répondu à un quiz, j'ajoute les infos de son résultat :
|
// si l'utilisateur a précédement répondu à un quiz, j'ajoute les infos de son résultat :
|
||||||
datas=checkAnswerDatas(datas);
|
datas=checkAnswerDatas(datas);
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
@ -90,7 +84,6 @@ const initialise = async () =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
||||||
|
@ -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,21 +24,15 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
config = await getConfig();
|
|
||||||
if(!config)
|
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
const datas=getUrlParams();
|
const datas=getUrlParams();
|
||||||
if(datas && datas.t!==undefined)
|
if(datas && datas.t!==undefined)
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", apiUrl+config.userRoutes+config.checkNewLoginLinkRoute+datas.t);
|
xhr.open("GET", apiUrl+userRoutes+checkNewLoginLinkRoute+datas.t);
|
||||||
xhr.onreadystatechange = function()
|
xhr.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (this.readyState == XMLHttpRequest.DONE)
|
if (this.readyState == XMLHttpRequest.DONE)
|
||||||
@ -47,7 +42,7 @@ const initialise = async () =>
|
|||||||
{
|
{
|
||||||
saveLocaly("message", { message: response.message, color:"success" });// pour l'afficher sur la page suivante
|
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
|
addElement(divResponse, "p", response.message, "", ["success"]);// au cas où blocage redirection
|
||||||
window.location.assign("/"+configFrontEnd.userHomePage);// que user possible ici
|
window.location.assign("/"+userHomePage);// que user possible ici
|
||||||
}
|
}
|
||||||
else if (this.status === 404 && response.errors != undefined)
|
else if (this.status === 404 && response.errors != undefined)
|
||||||
{
|
{
|
||||||
@ -58,14 +53,13 @@ const initialise = async () =>
|
|||||||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", configFrontEnd.accountPage), "", ["error"]);
|
addElement(divResponse, "p", badLinkValidationMessage.replace("#URL", accountPage), "", ["error"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
||||||
|
@ -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,36 +25,29 @@ const divResponse = document.getElementById("response");
|
|||||||
|
|
||||||
helloDev();
|
helloDev();
|
||||||
|
|
||||||
let config;
|
|
||||||
const initialise = async () =>
|
const initialise = async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
config = await getConfig();
|
|
||||||
if(!config)
|
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
const datas=getUrlParams();
|
const datas=getUrlParams();
|
||||||
if(datas && datas.t!==undefined)
|
if(datas && datas.t!==undefined)
|
||||||
{
|
{
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", apiUrl+config.userRoutes+config.unsubscribeRoute+datas.t);
|
xhr.open("GET", apiUrl+userRoutes+unsubscribeRoute+datas.t);
|
||||||
xhr.onreadystatechange = function()
|
xhr.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 && response.message != undefined)
|
if (this.status === 200 && response.message != undefined)
|
||||||
addElement(divResponse, "p", response.message.replace("#URL", configFrontEnd.accountPage), "", ["success"]);
|
addElement(divResponse, "p", response.message.replace("#URL", accountPage), "", ["success"]);
|
||||||
else
|
else
|
||||||
addElement(divResponse, "p", unsubscriptionFail.replace("#URL", configFrontEnd.accountPage), "", ["error"]);
|
addElement(divResponse, "p", unsubscriptionFail.replace("#URL", accountPage), "", ["error"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
addElement(divResponse, "p", serverError, "", ["error"]);
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
||||||
|
@ -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