69 lines
2.7 KiB
JavaScript
69 lines
2.7 KiB
JavaScript
// -- 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é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.
|
|
|
|
// Fichier de configuration côté client :
|
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
|
const lang=availableLangs[0];
|
|
const { accountPage } = require("../../views/"+theme+"/config/"+lang+".js");
|
|
const { checkDeleteLinkRoute, userRoutes } = require("../../config/users");
|
|
|
|
// Importation des fonctions utile au script :
|
|
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
|
|
import { addElement } from "./tools/dom.js";
|
|
import { helloDev } from "./tools/everywhere.js";
|
|
import { loadMatomo } from "./tools/matomo.js";
|
|
import { getUrlParams } from "./tools/url.js";
|
|
import { checkSession, setSession } from "./tools/users.js";
|
|
|
|
// Dictionnaires :
|
|
const { serverError } = require("../../lang/"+lang+"/general");
|
|
const { badLinkValidationMessage } = require("../../lang/"+lang+"/user");
|
|
|
|
const divResponse = document.getElementById("response");
|
|
|
|
helloDev();
|
|
|
|
const initialise = async () =>
|
|
{
|
|
try
|
|
{
|
|
const datas=getUrlParams();
|
|
if(datas && datas.t!==undefined)
|
|
{
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open("GET", apiUrl+userRoutes+checkDeleteLinkRoute+datas.t);
|
|
xhr.onreadystatechange = function()
|
|
{
|
|
if (this.readyState == XMLHttpRequest.DONE)
|
|
{
|
|
let response=JSON.parse(this.responseText);
|
|
if (this.status === 200 && response.message != undefined)
|
|
{
|
|
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", accountPage), "", ["error"]);
|
|
}
|
|
}
|
|
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
|
xhr.send();
|
|
}
|
|
}
|
|
catch(e)
|
|
{
|
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
|
console.error(e);
|
|
}
|
|
}
|
|
initialise(); |