forked from apxtri/apxtri
modif notification to register email phone
This commit is contained in:
parent
011644eaab
commit
37403e9014
@ -2,9 +2,13 @@ const glob = require("glob");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
const dayjs = require("dayjs");
|
||||||
|
const Checkjson = require(`./Checkjson.js`);
|
||||||
//const smtp = require("smtp-client");
|
//const smtp = require("smtp-client");
|
||||||
const nodemailer = require("nodemailer");
|
const nodemailer = require("nodemailer");
|
||||||
const conf = require(`../../conf/townconf.json`);
|
const conf = require(`../../conf/townconf.json`);
|
||||||
|
const currentmod = "Notifications";
|
||||||
|
const log = conf.api.activelog.includes(currentmod);
|
||||||
/**
|
/**
|
||||||
* To manage any communication between Pagan
|
* To manage any communication between Pagan
|
||||||
* mayor druid emailing/sms/paper from tribe register smtp, simcard, mail api to Person(s) / Pagan(s)
|
* mayor druid emailing/sms/paper from tribe register smtp, simcard, mail api to Person(s) / Pagan(s)
|
||||||
@ -35,11 +39,13 @@ Notifications.registertolist = (key, typekey, tribe, mlist, srckey, uuid) => {
|
|||||||
return {
|
return {
|
||||||
status: 400,
|
status: 400,
|
||||||
ref: "Notifications",
|
ref: "Notifications",
|
||||||
msg: "formaterreur",
|
msg: "formaterror",
|
||||||
data: { fielderr: typekey, format: typekey },
|
data: { fielderr: typekey, format: typekey },
|
||||||
};
|
};
|
||||||
const destin = `../../../nationchains/tribes/${tribe}/contacts/${typecontact}_${mlist}.json`;
|
const destin = `../nationchains/tribes/${tribe}/objects/maillinglists/${typekey}_${mlist}.json`;
|
||||||
|
console.log(destin)
|
||||||
const filestorage = fs.existsSync(destin) ? fs.readJsonSync(destin) : {};
|
const filestorage = fs.existsSync(destin) ? fs.readJsonSync(destin) : {};
|
||||||
|
//if (log) console.log(currentmod,`filestorage`,filestorage, key, (filestorage[key]));
|
||||||
if (filestorage[key]) {
|
if (filestorage[key]) {
|
||||||
filestorage[key].dt_update = dayjs().toISOString();
|
filestorage[key].dt_update = dayjs().toISOString();
|
||||||
if (!filestorage[key].srckeys.includes(srckey))
|
if (!filestorage[key].srckeys.includes(srckey))
|
||||||
@ -47,12 +53,13 @@ Notifications.registertolist = (key, typekey, tribe, mlist, srckey, uuid) => {
|
|||||||
if (!filestorage[key].uuids.includes(uuid))
|
if (!filestorage[key].uuids.includes(uuid))
|
||||||
filestorage[key].uuids.push(uuid);
|
filestorage[key].uuids.push(uuid);
|
||||||
}else{
|
}else{
|
||||||
|
filestorage[key]={}
|
||||||
filestorage[key].dt_create=dayjs().toISOString();
|
filestorage[key].dt_create=dayjs().toISOString();
|
||||||
filestorage[key].srckeys=[srckey];
|
filestorage[key].srckeys=[srckey];
|
||||||
filestorage[key].uuids=[uuid]
|
filestorage[key].uuids=[uuid]
|
||||||
}
|
}
|
||||||
fs.outputJSONSync(destin, filestorage);
|
fs.outputJSONSync(destin, filestorage);
|
||||||
return {status:200,ref:"Notifications",msg:"register",data:{key, typekey, tribe, mlist, srckey, uuid}}
|
return {status:200,ref:"Notifications",msg:"registersuccess",data:{key, typekey, tribe, mlist, srckey, uuid}}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Unsubscribe an eamil or phone from a mailinglist for a tribe
|
* Unsubscribe an eamil or phone from a mailinglist for a tribe
|
||||||
|
@ -44,41 +44,77 @@ router.get("/:alias/:tribeId", (req, res) => {
|
|||||||
res.status(getalias.status).send(getalias);
|
res.status(getalias.status).send(getalias);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/registeranonymous", checkHeaders, (req, res) => {
|
|
||||||
|
|
||||||
['uuid','srckey','mlist'].forEach(k=>{
|
|
||||||
if (!req.body[k]){}
|
|
||||||
});
|
|
||||||
res.status().json({status:410, ref:"", msg:""})
|
|
||||||
let result;
|
|
||||||
if (req.body.email) {
|
|
||||||
result= Notifications.registertolist(
|
|
||||||
req.body.email,
|
|
||||||
"email",
|
|
||||||
req.session.header.xtribe,
|
|
||||||
req.body.mlist,
|
|
||||||
req.body.srckey,
|
|
||||||
req.body.uuid);
|
|
||||||
}
|
|
||||||
res(200).json({status:200})
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {POST} /actions/contactanonymous -Contact anonymous
|
* @api {GET} /notifications/registeranonymous/:tribe/:mlist/:typekey/:data -Contact anonymous
|
||||||
|
* @apiName register
|
||||||
|
* @apiGroup Notifications
|
||||||
|
* @apiDescription Register an email into a mailinglist mlist
|
||||||
|
* @apiParams {string} tribe an existing tribe
|
||||||
|
* @apiParams {string} mlist a mailing list name
|
||||||
|
* @apiParams {string} key email or phone
|
||||||
|
* @apiParams {string} srckey must exist in tribes/schema/lg/enumtrk_xx.json
|
||||||
|
* @apiParams {string} data the email or phone
|
||||||
|
* @apiSuccess {object} update mailinglist/{mlist}.json successfull
|
||||||
|
* @apiSuccessExample {json} successfullmessage
|
||||||
|
* HTTP/1.1 200 OK
|
||||||
|
* {"status":200, "ref":"Notifications", "msg":"registersuccess", "data":{data, typekey, tribe, mlist, srckey, uuid}}}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
router.get("/registeranonymous/:tribe/:mlist/:typekey/:srckey/:key", checkHeaders, (req, res) => {
|
||||||
|
console.log("pass ici")
|
||||||
|
//Notifications.registertolist = (typekey, tribe, mlist, srckey, uuid)
|
||||||
|
result= Notifications.registertolist(
|
||||||
|
req.params.key,
|
||||||
|
req.params.typekey,
|
||||||
|
req.params.tribe,
|
||||||
|
req.params.mlist,
|
||||||
|
req.params.srckey,
|
||||||
|
req.session.header.xuuid);
|
||||||
|
res.status(result.status).json(result)
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {GET} /notifications/unregister/:tribe/:mlist/:typekey/:data/:validation -Contact anonymous
|
||||||
* @apiName contactanonymous
|
* @apiName contactanonymous
|
||||||
* @apiGroup Notifications
|
* @apiGroup Notifications
|
||||||
* @apiDescription Run action store in body.order and update mailinglist or create contact message
|
* @apiDescription Register an email into a mailinglist mlist
|
||||||
*
|
* @apiParams {string} tribe an existing tribe
|
||||||
* @apiBody {string} order name of function for action in Actions.js example:registercontact ,
|
* @apiParams {string} mlist a mailing list name
|
||||||
* @apiBody {string} srckey: where it come from and eventualy email template name to use to send email ,
|
* @apiParams {string} key email or phone
|
||||||
* @apiBody {string} email to use
|
* @apiParams {string} srckey must exist in tribes/schema/lg/enumtrk_xx.json
|
||||||
* @apiBody {string} route /actions/contactanonymous
|
* @apiParams {string} data the email or phone
|
||||||
* @apiBody {string} [mlist] filename to store email registration /contacts/mlist.json if not => filename is quest_/contacts/email.json with {email:{dt_create,dt_update, src:[list of source]}} or add message in /contacts/quest_{email}.json {timestamp:{message,name,email,dt_create,emailcontact}}
|
* @apiParams {string} validation a key store in /tmp waiting to be approved, if "request" then send an email for confirmation, else if exist then remove email from list.
|
||||||
* @apiBody {string} others any other usefull key:value relevant for order action
|
* @apiSuccess {object} update mailinglist/{mlist}.json successfull
|
||||||
|
* @apiSuccessExample {json} successfullmessage
|
||||||
|
* HTTP/1.1 200 OK
|
||||||
|
* {"status":200, "ref":"Notifications", "msg":"registersuccess", "data":{data, typekey, tribe, mlist, srckey, uuid}}}
|
||||||
*
|
*
|
||||||
* @apiSuccess {object} update/contacts/{mlist}.json successfull
|
*/
|
||||||
|
|
||||||
|
router.get("/unregisteranonymous/:tribe/:mlist/:typekey/:srckey/:data/:validation", checkHeaders, (req, res) => {
|
||||||
|
Notifications.registertolist = (typekey, tribe, mlist, srckey, uuid)
|
||||||
|
result= Notifications.registertolist(
|
||||||
|
req.params.typekey,
|
||||||
|
req.params.tribe,
|
||||||
|
req.params.mlist,
|
||||||
|
req.params.srckey,
|
||||||
|
req.session.header.xuuid);
|
||||||
|
res.status(result.status).json(result)
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {POST} /notifications/contactanonymous/:tribe -Contact anonymous
|
||||||
|
* @apiName contactanonymous
|
||||||
|
* @apiGroup Notifications
|
||||||
|
* @apiDescription Register a contact in tribe and send a mail to admin of tribe
|
||||||
|
* @apiParams {string} tribe an existing tribe
|
||||||
|
* @apiBody {string} srckey: where it come from and eventualy email template name to use to send email ,
|
||||||
|
* @apiBody {string} email to recontact
|
||||||
|
* @apiBody {string} others any other usefull key:value
|
||||||
|
*
|
||||||
|
* @apiSuccess {object} create/update tribe/contacts/{}.json successfull
|
||||||
* @apiSuccessExample {json} successfullmessage
|
* @apiSuccessExample {json} successfullmessage
|
||||||
* HTTP/1.1 200 OK
|
* HTTP/1.1 200 OK
|
||||||
* {"status":200, "ref":"Contact", "msg":"success", "data":{"indexlist":[]}}
|
* {"status":200, "ref":"Contact", "msg":"success", "data":{"indexlist":[]}}
|
||||||
@ -94,7 +130,7 @@ router.post("/contactanonymous", checkHeaders, async (req, res) => {
|
|||||||
/**
|
/**
|
||||||
* Same as /copntactanonymous but for authenticated user => data are updated in persons/itm/alias.json
|
* Same as /copntactanonymous but for authenticated user => data are updated in persons/itm/alias.json
|
||||||
*/
|
*/
|
||||||
router.post("/contact", checkHeaders, isAuthenticated, (req, res) => {
|
router.post("/contact/:tribe/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||||
const done = Actions[req.body.order]
|
const done = Actions[req.body.order]
|
||||||
? Actions[req.body.order](req.body, req.session.header)
|
? Actions[req.body.order](req.body, req.session.header)
|
||||||
: { status: 406, ref: "Actions", msg: "bodyerror", data: req.body };
|
: { status: 406, ref: "Actions", msg: "bodyerror", data: req.body };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user