1
0
forked from apxtri/apxtri

modif recovery email

This commit is contained in:
philc 2024-04-15 09:26:54 +02:00
parent 16a93f2d33
commit 9bf76a17dc
2 changed files with 35 additions and 19 deletions

View File

@ -52,9 +52,7 @@ const isAuthenticated = async (req, res, next) => {
glob.sync(`../../tmp/tokens/*.json`).forEach((f) => {
const fsplit = f.split("_");
const elapse = tsday - parseInt(fsplit[2]);
console.log("##############################")
console.log(fsplit,"--",fsplit[2])
//24h 86400000 milliseconde 15mn 900000
//24h 86400000 milliseconde 15mn 900000
if (elapse && elapse > 86400000) {
fs.remove(f);
}

View File

@ -289,10 +289,13 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
});
/**
* @api {get} adminapi/pagans/keyrecovery/:tribe/:email - recovery keys by email
* @api {post} adminapi/pagans/keyrecovery - recovery keys
* @apiName recoveryKey
* @apiGroup Pagans
* @apiDescription Send mails with all registers identities (one per alias where recoveryauth.email is register)
* @apiDescription Send mails with all registers identities (one per alias where recoveryauth.email is register). Search can be request by email or by alias for a tribe. It is looking for in person.recoveryauth.email to send keys. One mail is sent by alias. So if n alias has the same recoveryaut.email then it will send n email.
* @apiBody {string} emailalias type of search (email or alias)
* @apiBody {string} tribe tribename into looking for
* @apiBody {string} search an email or an alias
*
* @apiSuccess {object} send recovery email
* @apiSuccessExample {json} Success-Response:
@ -304,22 +307,37 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
* {status: 404, ref:"pagans",msg:"emailnotfound",data: { tribe,email } }
*
*/
router.get("/keyrecovery/:tribe/:email", checkHeaders, (req, res) => {
const idxreco=`../../${req.params.tribe}/objects/persons/idx/emailrecovery_alias.json`;
if (fs.existsSync(idxreco)){
const emailreco = fs.readJSONSync(idxreco);
if (emailreco[req.params.email]){
let sentemails=0;
emailreco[req.params.email].forEach(alias=>{
const ret = Pagans.sendmailkey({alias:alias,tribe:req.params.tribe,lg:req.session.header.xlang})
sentemails = (ret.status==200)? sentemails+1:sentemails;
router.post("/keyrecovery", checkHeaders, (req, res) => {
let emailist=[]
let alias =req.body.search;
if (req.body.emailalias=="email"){
req.body.search=req.body.search.toLowerCase();
const idxreco=`../../${req.body.tribe}/objects/persons/idx/emailrecovery_alias.json`;
if (fs.existsSync(idxreco)){
const emailreco = fs.readJSONSync(idxreco);
const listalias = (emailreco[req.body.search])? emailreco[req.body.search]: [];
listalias.forEach(a=>{
emailist.push({alias:a,tribe:req.body.tribe,lg:req.session.header.xlang})
})
return {status:200,ref:"Pagans",msg:"recoveryemailsent",data:{email:req.params.email,tribe:req.params.tribe,nbalias:emailreco[req.params.email].length, nbsent:sentemails}}
}else{
return {status:404,ref:"Pagans",msg:"emailnotfound",data:{tribe:req.params.tribe,email:req.params.email}}
}
}else if (req.body.emailalias=="alias"){
const falias= `../../${req.body.tribe}/objects/persons/itm/${req.body.search}.json`;
if (fs.existsSync(falias)){
emailist.push({alias:req.body.search,tribe:req.body.tribe,lg:req.session.header.xlang})
}
}else{
return {status:404,ref:"Pagans",msg:"emailnotfound",data:{tribe:req.params.tribe,email:req.params.email}}
//console later
}
emailist.forEach(e => {
console.log(e)
const ret= Pagans.sendmailkey(e)
})
if (emailist.length>0) {
res.status(200).json({status:200,ref:"Pagans",msg:"recoveryemailsent",data:{numberemailsent:emailist.length}});
}else{
res.status(404).json({status:404,ref:"Pagans",msg:"recoveryemailnotfound",data:{tribe:req.body.tribe}});
}
});
/**