new wco wwws compatible with new backeend

This commit is contained in:
2025-07-23 12:36:48 +02:00
parent bc76840707
commit b6ae865332
23 changed files with 1702 additions and 94 deletions

View File

@@ -6,15 +6,16 @@ apx.apxauth.loadwco = async (id, ctx) => {
// if (dayjs(apx.data.headers.xdays).diff(dayjs(), "hours") >= 24) apx.apxauth.checkisauth();
//load main.mustache of the component
//when wco-xxx change it run this function
console.log(`Load wconame:apxauth apx.apxauth.loadwco with id:${id} and ctx: ${JSON.stringify(ctx)}`);
console.log(
`Load wconame:apxauth apx.apxauth.loadwco with id:${id} and ctx: ${JSON.stringify(
ctx
)}`
);
const tpldataname = `${apx.data.pagename}_${id}_apxauth`;
const apxauthid = document.getElementById(id)
const apxauthid = document.getElementById(id);
const data = apx.apxauth.getdata(id, ctx);
if (apxauthid.innerHTML.trim() === "") {
apxauthid.innerHTML = Mustache.render(
apx.data.tpl.apxauthmain,
data
);
apxauthid.innerHTML = Mustache.render(apx.data.tpl.apxauthmain, data);
}
apxauthid.querySelector(`.screenaction`).innerHTML = Mustache.render(
apx.data.tpl[`apxauthscreen${ctx.link}`],
@@ -29,7 +30,10 @@ apx.apxauth.getdata = (id, ctx) => {
data.id = id;
data.xalias = apx.data.headers.xalias;
data.xtribe = apx.data.headers.xtribe;
data.emailssuport = apx.data.appdata.emailsupport;
data.emailssuport = apx.data.appdata.emailsupport
? apx.data.appdata.emailsupport
: "";
switch (ctx.link) {
case "logout":
if (!data.profils) data.profils = [];
@@ -55,34 +59,46 @@ apx.apxauth.getdata = (id, ctx) => {
break;
}
console.log("data for tpl:", data);
return data
return data;
};
apx.apxauth.redirecturlwithauth = (url, tribe, webapp, newwindow, windowname = '_blank') => {
url = url.replace(/_[a-zA-Z0-9]{2}\.html/, `_${apx.data.headers.xlang}.html`)
url += `?xtribe=${tribe}&xapp=${webapp}&xalias=${apx.data.headers.xalias}`
url += `&xdays=${apx.data.headers.xdays}&xhash=${apx.data.headers.xhash}`
url += `&xprofils=${apx.data.headers.xprofils.join(',')}`
url += `&xtrkversion=${apx.data.headers.xtrkversion}&xuuid=${apx.data.headers.xuuid}`
apx.apxauth.redirecturlwithauth = (
url,
tribe,
webapp,
newwindow,
windowname = "_blank"
) => {
url = url.replace(/_[a-zA-Z0-9]{2}\.html/, `_${apx.data.headers.xlang}.html`);
url += `?xtribe=${tribe}&xapp=${webapp}&xalias=${apx.data.headers.xalias}`;
url += `&xdays=${apx.data.headers.xdays}&xhash=${apx.data.headers.xhash}`;
url += `&xprofils=${apx.data.headers.xprofils.join(",")}`;
url += `&xtrkversion=${apx.data.headers.xtrkversion}&xuuid=${apx.data.headers.xuuid}`;
if (newwindow) {
try {
const newwin = window.open(url, windowname)
if (newwin === null || typeof newwin === 'undefined') {
console.warn("L'ouverture de la fenêtre a été bloquée par un bloqueur de pop-up.");
const newwin = window.open(url, windowname);
if (newwin === null || typeof newwin === "undefined") {
console.warn(
"L'ouverture de la fenêtre a été bloquée par un bloqueur de pop-up."
);
// Vous pouvez informer l'utilisateur ici qu'il doit désactiver son bloqueur de pop-up
alert("Votre navigateur a bloqué l'ouverture d'un nouvel onglet. Veuillez autoriser les pop-ups pour ce site.");
alert(
"Votre navigateur a bloqué l'ouverture d'un nouvel onglet. Veuillez autoriser les pop-ups pour ce site."
);
} else {
// Optionnel: Mettre le focus sur la nouvelle fenêtre/onglet
newwin.focus();
}
return newwin;
} catch (error) {
console.error("Une erreur est survenue lors de l'ouverture de l'onglet :", error);
console.error(
"Une erreur est survenue lors de l'ouverture de l'onglet :",
error
);
return null;
}
}
}
};
/**
* logout
@@ -148,7 +164,7 @@ apx.apxauth.setheadersauth = async (
apx.data.headers.xalias = alias;
apx.data.headers.xdays = dayjs().valueOf();
const msg = `${alias}_${apx.data.headers.xdays}`;
//console.log("pvk", privatekey);
try {
apx.data.headers.xhash = await apx.apxauth.clearmsgSignature(
publickey,
@@ -184,8 +200,11 @@ apx.apxauth.authentifyme = async (
//console.log(alias, passphrase);
//console.log(privatekey);
//clean previous answer if exist
const idparent=document.getElementById(id).parentElement?.closest('[wco-name]').getAttribute('id')
const idparent = document
.getElementById(id)
.parentElement?.closest("[wco-name]")
.getAttribute("id");
document.querySelector(`#${id} .msginfo`).innerHTML = "";
if (alias.length < 3 || privatekey.length < 200) {
apx.notification(`#${id} .msginfo`, {
@@ -218,10 +237,13 @@ apx.apxauth.authentifyme = async (
axios
.get(`/api/apxtri/pagans/isauth`, {
headers: apx.data.headers,
withCredentials: true,
})
.then((rep) => {
// Authenticate then store profils in header
// remove xhash for security this xhaskl is stored from the server as cookie http only.
apx.data.headers.xprofils = rep.data.data.xprofils;
delete apx.data.headers.xhash;
apx.save();
// if this page is call with apxid_fr.html?url=httpsxxx then it redirect to this page.
//alert(`${window.location.href.includes("/src/")?"/src/":""}${apx.pagecontext.hash.url}`)
@@ -229,14 +251,18 @@ apx.apxauth.authentifyme = async (
window.location.href = `${apx.pagecontext.hash.url}`;
} else {
//location.reload();
document.getElementById(idparent).setAttribute('wco-link','mytribes');
document
.getElementById(idparent)
.setAttribute("wco-link", "mytribes");
}
})
.catch((err) => {
console.log("Not authentify:", err);
delete apx.data.auth;
apx.save();
document.getElementById(idparent).setAttribute("wco-link", "signin")
document
.getElementById(idparent)
.setAttribute("wco-link", "signin");
if (err.response) {
apx.notification(`#${id} .msginfo`, err.response.data);
} else if (err.request) {
@@ -486,13 +512,8 @@ apx.apxauth.authenticatedetachedSignature = async (
return false;
}
};
apx.apxauth.createIdentity = async (
id,
alias,
recoemail,
passphrase = ""
) => {
document.querySelector(`#${id} .msginfo`).innerHTML = ""
apx.apxauth.createIdentity = async (id, alias, recoemail, passphrase = "") => {
document.querySelector(`#${id} .msginfo`).innerHTML = "";
const aliasregex = /^[a-z0-9]*$/;
//console.log(aliasregex.test(alias));
if (!(alias && alias.length > 3 && aliasregex.test(alias))) {
@@ -542,9 +563,7 @@ apx.apxauth.createIdentity = async (
//console.log(apx.data.tmpauth);
["publickey", "privatekey"].forEach((k) => {
console.log(`${id} button.signup${k}`);
const btn = document.querySelector(
`#${id} button.signup${k}`
);
const btn = document.querySelector(`#${id} button.signup${k}`);
btn.addEventListener("click", () => {
const blob = new Blob([keys[k]], { type: "text/plain" });
const url = URL.createObjectURL(blob);
@@ -561,12 +580,8 @@ apx.apxauth.createIdentity = async (
`#${id} .signupalias, #${id} .signupemailrecovery, #${id} .signuppassphrase`
)
.forEach((e) => e.setAttribute("disabled", "disabled"));
document
.querySelector(`#${id} .getmykeys`)
.classList.remove("hidden");
document
.querySelector(`#${id} .btncreatekey`)
.classList.add("hidden");
document.querySelector(`#${id} .getmykeys`).classList.remove("hidden");
document.querySelector(`#${id} .btncreatekey`).classList.add("hidden");
} else {
apx.notification(
`#${id} .msginfo`,
@@ -617,8 +632,14 @@ apx.apxauth.registerIdentity = async (id, trustedtribe) => {
const data = {};
data.alias = apx.data.tmpauth.keys.alias;
data.publickey = apx.data.tmpauth.keys.publickey;
console.log(apx.data.tmpauth.recoemail, Checkjson.testformat(apx.data.tmpauth.recoemail, "email"))
if (apx.data.tmpauth.recoemail && Checkjson.testformat(apx.data.tmpauth.recoemail, "email")) {
console.log(
apx.data.tmpauth.recoemail,
Checkjson.testformat(apx.data.tmpauth.recoemail, "email")
);
if (
apx.data.tmpauth.recoemail &&
Checkjson.testformat(apx.data.tmpauth.recoemail, "email")
) {
data.passphrase = apx.data.tmpauth.keyspassphrase;
data.privatekey = apx.data.tmpauth.keysprivatekey;
data.email = apx.data.tmpauth.recoemail;
@@ -629,10 +650,8 @@ apx.apxauth.registerIdentity = async (id, trustedtribe) => {
.then((reppagan) => {
//console.log(reppagan.data);
apx.notification(`#${id} .msginfo`, reppagan.data);
authid.querySelector(`.btncreateidentity`)
.classList.add("hidden");
authid.querySelector(`.signupbtnreload`)
.classList.remove("hidden");
authid.querySelector(`.btncreateidentity`).classList.add("hidden");
authid.querySelector(`.signupbtnreload`).classList.remove("hidden");
//remove tmp cause create phc change to keep tplauth in memory and avoid asking again the pasword
//delete apx.data.tmpauth;
//apx.save();