75 lines
3.1 KiB
JavaScript
75 lines
3.1 KiB
JavaScript
// -- PAGE PERMETTANT DE VALIDER UN CHANGEMENT D'EMAIL OU DE MOT DE PASSE
|
||
|
||
/// Un token est transmis en paramètre de l'Url. Il a une validité limité dans le temps.
|
||
/// Si le token est ok, on valide la mise à jour et redirige l'utilisateur vers sa page d'accueil
|
||
|
||
// Fichier de configuration côté client :
|
||
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
||
const lang=availableLangs[0];
|
||
const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
|
||
|
||
// Importation des fonctions utile au script :
|
||
import { getLocaly, saveLocaly } from "./tools/clientstorage.js";
|
||
import { addElement } from "./tools/dom.js";
|
||
import { helloDev, updateAccountLink } from "./tools/everywhere.js";
|
||
import { getUrlParams } from "./tools/url.js";
|
||
import { checkSession, getConfig, setSession } from "./tools/users.js";
|
||
|
||
// Dictionnaires :
|
||
const txt = require("../../lang/"+lang+"/general");
|
||
const txtUsers = require("../../lang/"+lang+"/user");
|
||
|
||
const divResponse = document.getElementById("response");
|
||
|
||
helloDev();
|
||
|
||
let config;
|
||
const initialise = async () =>
|
||
{
|
||
try
|
||
{
|
||
config = await getConfig();
|
||
if(!config)
|
||
addElement(divResponse, "p", txt.serverError, "", ["error"]);
|
||
else
|
||
{
|
||
const datas=getUrlParams();
|
||
if(datas && datas.t!==undefined)
|
||
{
|
||
const xhr = new XMLHttpRequest();
|
||
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)
|
||
{
|
||
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 = txt.serverError;
|
||
addElement(divResponse, "p", response.errors, "", ["error"]);
|
||
}
|
||
else
|
||
addElement(divResponse, "p", txtUsers.badLinkValidationMessage.replace("#URL", configFrontEnd.accountPage), "", ["error"]);
|
||
}
|
||
}
|
||
xhr.setRequestHeader("Authorization", "Bearer "+datas.t);
|
||
xhr.send();
|
||
}
|
||
}
|
||
}
|
||
catch(e)
|
||
{
|
||
addElement(divResponse, "p", txt.serverError, "", ["error"]);
|
||
console.error(e);
|
||
}
|
||
}
|
||
initialise(); |