forked from apxtri/apxtri
modif recovery email
This commit is contained in:
parent
16a93f2d33
commit
9bf76a17dc
@ -52,9 +52,7 @@ const isAuthenticated = async (req, res, next) => {
|
|||||||
glob.sync(`../../tmp/tokens/*.json`).forEach((f) => {
|
glob.sync(`../../tmp/tokens/*.json`).forEach((f) => {
|
||||||
const fsplit = f.split("_");
|
const fsplit = f.split("_");
|
||||||
const elapse = tsday - parseInt(fsplit[2]);
|
const elapse = tsday - parseInt(fsplit[2]);
|
||||||
console.log("##############################")
|
//24h 86400000 milliseconde 15mn 900000
|
||||||
console.log(fsplit,"--",fsplit[2])
|
|
||||||
//24h 86400000 milliseconde 15mn 900000
|
|
||||||
if (elapse && elapse > 86400000) {
|
if (elapse && elapse > 86400000) {
|
||||||
fs.remove(f);
|
fs.remove(f);
|
||||||
}
|
}
|
||||||
|
@ -289,11 +289,14 @@ 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
|
* @apiName recoveryKey
|
||||||
* @apiGroup Pagans
|
* @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
|
* @apiSuccess {object} send recovery email
|
||||||
* @apiSuccessExample {json} Success-Response:
|
* @apiSuccessExample {json} Success-Response:
|
||||||
* HTTP/1.1 200 OK
|
* HTTP/1.1 200 OK
|
||||||
@ -304,22 +307,37 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
|
|||||||
* {status: 404, ref:"pagans",msg:"emailnotfound",data: { tribe,email } }
|
* {status: 404, ref:"pagans",msg:"emailnotfound",data: { tribe,email } }
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
router.get("/keyrecovery/:tribe/:email", checkHeaders, (req, res) => {
|
router.post("/keyrecovery", checkHeaders, (req, res) => {
|
||||||
const idxreco=`../../${req.params.tribe}/objects/persons/idx/emailrecovery_alias.json`;
|
let emailist=[]
|
||||||
if (fs.existsSync(idxreco)){
|
let alias =req.body.search;
|
||||||
const emailreco = fs.readJSONSync(idxreco);
|
if (req.body.emailalias=="email"){
|
||||||
if (emailreco[req.params.email]){
|
req.body.search=req.body.search.toLowerCase();
|
||||||
let sentemails=0;
|
const idxreco=`../../${req.body.tribe}/objects/persons/idx/emailrecovery_alias.json`;
|
||||||
emailreco[req.params.email].forEach(alias=>{
|
if (fs.existsSync(idxreco)){
|
||||||
const ret = Pagans.sendmailkey({alias:alias,tribe:req.params.tribe,lg:req.session.header.xlang})
|
const emailreco = fs.readJSONSync(idxreco);
|
||||||
sentemails = (ret.status==200)? sentemails+1:sentemails;
|
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{
|
}else if (req.body.emailalias=="alias"){
|
||||||
return {status:404,ref:"Pagans",msg:"emailnotfound",data:{tribe:req.params.tribe,email:req.params.email}}
|
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{
|
}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}});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user