fix envoie email de check
This commit is contained in:
@@ -396,8 +396,10 @@ Notifications.manageemail = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
//if (typeof data.emailsto === "string") data.emailsto = [data.emailsto];
|
//if (typeof data.emailsto === "string") data.emailsto = [data.emailsto];
|
||||||
const tplpath = `../${tribe}/template/${templatename}_${lg}.js`;
|
let tplpath = `../${tribe}/template/${templatename}_${lg}.js`;
|
||||||
if (!fs.existsSync(tplpath)) {
|
if (!fs.existsSync(tplpath)) {
|
||||||
|
const fallbacktplpath = `../adminapi/template/${templatename}_${lg}.js`;
|
||||||
|
if (!fs.existsSync(fallbacktplpath)) {
|
||||||
return {
|
return {
|
||||||
status: 404,
|
status: 404,
|
||||||
ref: "Notification",
|
ref: "Notification",
|
||||||
@@ -405,6 +407,8 @@ Notifications.manageemail = async (
|
|||||||
data: { template: tplpath },
|
data: { template: tplpath },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
tplpath = fallbacktplpath;
|
||||||
|
}
|
||||||
const results = { fail: [], success: [], simulated: [] };
|
const results = { fail: [], success: [], simulated: [] };
|
||||||
const emailtosend = {};
|
const emailtosend = {};
|
||||||
// init with common propertie
|
// init with common propertie
|
||||||
@@ -574,7 +578,48 @@ Notifications.sendmail = async (data, tribe) => {
|
|||||||
console.log("Brevo contact error:", err.response?.data || err.message);
|
console.log("Brevo contact error:", err.response?.data || err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!conf.smtp || !conf.emailcontact) {
|
// Resolve the mail configuration key by key: the tribe config wins, and any
|
||||||
|
// key it does not define ("" / {} / [] treated as unset) falls back to the
|
||||||
|
// global adminapi config.
|
||||||
|
const isunset = (v) =>
|
||||||
|
v === undefined ||
|
||||||
|
v === null ||
|
||||||
|
(typeof v === "string" && v.trim() === "") ||
|
||||||
|
(Array.isArray(v) && v.length === 0) ||
|
||||||
|
(typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 0);
|
||||||
|
|
||||||
|
let conftrib = {};
|
||||||
|
const conftribfile = `../adminapi/objects/tribes/itm/${tribe}.json`;
|
||||||
|
if (fs.existsSync(conftribfile)) {
|
||||||
|
conftrib = fs.readJSONSync(conftribfile);
|
||||||
|
} else if (log) {
|
||||||
|
console.log(
|
||||||
|
currentmod,
|
||||||
|
"Warning: this conf does not exist:",
|
||||||
|
path.resolve(conftribfile),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolveconf = (key) =>
|
||||||
|
!isunset(conftrib[key])
|
||||||
|
? conftrib[key]
|
||||||
|
: !isunset(conf[key])
|
||||||
|
? conf[key]
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const confemailcontact = resolveconf("emailcontact");
|
||||||
|
const confsmtp = resolveconf("smtp");
|
||||||
|
const confbrevo = resolveconf("BREVO");
|
||||||
|
|
||||||
|
if (!confemailcontact) {
|
||||||
|
return {
|
||||||
|
status: 428,
|
||||||
|
ref: "Notifications",
|
||||||
|
msg: "missingemailcontactinconf",
|
||||||
|
data: { tribe },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (!confsmtp) {
|
||||||
return {
|
return {
|
||||||
status: 412,
|
status: 412,
|
||||||
ref: "Notifications",
|
ref: "Notifications",
|
||||||
@@ -584,7 +629,7 @@ Notifications.sendmail = async (data, tribe) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!data.from) {
|
if (!data.from) {
|
||||||
data.from = conf.emailcontact;
|
data.from = confemailcontact;
|
||||||
}
|
}
|
||||||
|
|
||||||
let missingk = [];
|
let missingk = [];
|
||||||
@@ -601,31 +646,13 @@ Notifications.sendmail = async (data, tribe) => {
|
|||||||
data: { missingk: missingk },
|
data: { missingk: missingk },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let confsmtp = conf.smtp;
|
|
||||||
let confbrevoapikey = conf.BREVO.APIKEY;
|
if (confbrevo && confbrevo.APIKEY) {
|
||||||
const conftribfile = `../adminapi/objects/tribes/itm/${tribe}.json`;
|
|
||||||
if (fs.existsSync(conftribfile)) {
|
|
||||||
const conftrib = fs.readJSONSync(conftribfile);
|
|
||||||
if (!conftrib.emailcontact) {
|
|
||||||
return {
|
|
||||||
status: 428,
|
|
||||||
ref: "Notifications",
|
|
||||||
msg: "missingemailcontactinconf",
|
|
||||||
data: { tribe },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
confsmtp = conftrib.smtp;
|
|
||||||
if (!data.from || data.from == conf.emailcontact)
|
|
||||||
data.from = conftrib.emailcontact;
|
|
||||||
if (conftrib.BREVO){
|
|
||||||
const toEmails = data.to.split(",");
|
const toEmails = data.to.split(",");
|
||||||
for (const email of toEmails) {
|
for (const email of toEmails) {
|
||||||
await ensureContact(email,conftrib.BREVO.APIKEY);
|
await ensureContact(email, confbrevo.APIKEY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (log) console.log(currentmod,"Warning: this conf does not exist:",path.resolve(conftribfile));
|
|
||||||
}
|
|
||||||
|
|
||||||
//console.log(confsmtp);
|
//console.log(confsmtp);
|
||||||
const transporter = await nodemailer.createTransport(confsmtp);
|
const transporter = await nodemailer.createTransport(confsmtp);
|
||||||
|
|||||||
+17
-4
@@ -50,7 +50,7 @@ Pagans.logout = (alias, tribe, xdays, xhash) => {
|
|||||||
* @Param lg language to send email
|
* @Param lg language to send email
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Pagans.keyrecovery = (emailalias, tribe, search, lg) => {
|
Pagans.keyrecovery = async (emailalias, tribe, search, lg) => {
|
||||||
if (log)
|
if (log)
|
||||||
console.log(
|
console.log(
|
||||||
currentmod,
|
currentmod,
|
||||||
@@ -108,16 +108,29 @@ Pagans.keyrecovery = (emailalias, tribe, search, lg) => {
|
|||||||
/* emaillist.forEach((e) => {
|
/* emaillist.forEach((e) => {
|
||||||
const ret = Pagans.sendmailkey(e);
|
const ret = Pagans.sendmailkey(e);
|
||||||
});*/
|
});*/
|
||||||
|
let numberemailsent = 0;
|
||||||
|
let emailfail = 0;
|
||||||
for (let i = 0; i < emaillist.length && i < 3; i++) {
|
for (let i = 0; i < emaillist.length && i < 3; i++) {
|
||||||
const e = emaillist[i];
|
const e = emaillist[i];
|
||||||
const ret = Pagans.sendmailkey(e);
|
try {
|
||||||
|
const ret = await Pagans.sendmailkey(e);
|
||||||
|
if (ret && ret.status == 200) {
|
||||||
|
numberemailsent++;
|
||||||
|
} else {
|
||||||
|
emailfail++;
|
||||||
|
if (log) console.log(currentmod, "keyrecovery sendmailkey failed:", ret);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
emailfail++;
|
||||||
|
console.log(currentmod, "keyrecovery sendmailkey error:", err.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (emaillist.length > 0) {
|
if (emaillist.length > 0) {
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
ref: "Pagans",
|
ref: "Pagans",
|
||||||
msg: "recoveryemailsent",
|
msg: "recoveryemailsent",
|
||||||
data: { numberemailsent: emaillist.length },
|
data: { numberemailsent, emailfail },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -241,7 +254,7 @@ Pagans.sendmailkey = (data) => {
|
|||||||
person.avecpassphrase = person.passphrase != "";
|
person.avecpassphrase = person.passphrase != "";
|
||||||
let tplfile = `../${data.tribe}/template/createidentity_${data.lg}.js`;
|
let tplfile = `../${data.tribe}/template/createidentity_${data.lg}.js`;
|
||||||
if (!fs.existsSync(tplfile)) {
|
if (!fs.existsSync(tplfile)) {
|
||||||
tplfile = `../${data.tribe}/template/createidentity_${data.lg}.js`;
|
tplfile = `../adminapi/template/createidentity_${data.lg}.js`;
|
||||||
if (!fs.existsSync(tplfile)) {
|
if (!fs.existsSync(tplfile)) {
|
||||||
return {
|
return {
|
||||||
status: 406,
|
status: 406,
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ router.get("/checkemail/:email/:digit6", checkHeaders, async (req, res) => {
|
|||||||
emailsto: [{ to: email, code }]
|
emailsto: [{ to: email, code }]
|
||||||
},
|
},
|
||||||
"checkemail",
|
"checkemail",
|
||||||
"adminapi",
|
req.session.header.xtribe,
|
||||||
Notifications.recipientlang(null, req.session.header.xlang),
|
Notifications.recipientlang(null, req.session.header.xlang),
|
||||||
1,
|
1,
|
||||||
["anonymous"]
|
["anonymous"]
|
||||||
|
|||||||
+18
-3
@@ -157,7 +157,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
|
|||||||
alias: req.body.alias,
|
alias: req.body.alias,
|
||||||
privatekey: req.body.privatekey,
|
privatekey: req.body.privatekey,
|
||||||
tribe: req.session.header.xtribe,
|
tribe: req.session.header.xtribe,
|
||||||
passprhase: req.body.passphrase,
|
passphrase: req.body.passphrase,
|
||||||
publickey: req.body.publickey,
|
publickey: req.body.publickey,
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
lg: req.session.header.xlang,
|
lg: req.session.header.xlang,
|
||||||
@@ -414,9 +414,24 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
|
|||||||
* {status: 404, ref:"pagans",msg:"recoveryemailnotfound",data: { tribe,email } }
|
* {status: 404, ref:"pagans",msg:"recoveryemailnotfound",data: { tribe,email } }
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
router.post("/keyrecovery", checkHeaders, (req, res) => {
|
router.post("/keyrecovery", checkHeaders, async (req, res) => {
|
||||||
const recores=Pagans.keyrecovery(req.body.emailalias,req.body.tribe,req.body.search,req.session.header.xlang)
|
try {
|
||||||
|
const recores = await Pagans.keyrecovery(
|
||||||
|
req.body.emailalias,
|
||||||
|
req.body.tribe,
|
||||||
|
req.body.search,
|
||||||
|
req.session.header.xlang,
|
||||||
|
);
|
||||||
res.status(recores.status).json(recores);
|
res.status(recores.status).json(recores);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("keyrecovery error:", err.message);
|
||||||
|
res.status(500).json({
|
||||||
|
status: 500,
|
||||||
|
ref: "Pagans",
|
||||||
|
msg: "keyrecoveryerror",
|
||||||
|
data: { error: err.message },
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@
|
|||||||
"name": "tribes",
|
"name": "tribes",
|
||||||
"keyval": "tribeId",
|
"keyval": "tribeId",
|
||||||
"type": "view",
|
"type": "view",
|
||||||
"objkey": [],
|
"objkey": ["dns","status","nationId","townId","activelog","wco","emailcontact"],
|
||||||
"filter": "",
|
"filter": "",
|
||||||
"apxaccess": {
|
"apxaccess": {
|
||||||
"R": [
|
"R": [
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const tplemail = {};
|
const tplemail = {};
|
||||||
|
tplemail.nofilterpreprod = true;
|
||||||
tplemail.allowedprofils = ["anonymous", "druid"];
|
tplemail.allowedprofils = ["anonymous", "druid"];
|
||||||
tplemail.subject = "Verification code - Email verification";
|
tplemail.subject = "Verification code - Email verification";
|
||||||
tplemail.html = `
|
tplemail.html = `
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const tplemail = {};
|
const tplemail = {};
|
||||||
|
tplemail.nofilterpreprod = true;
|
||||||
tplemail.allowedprofils = ["anonymous", "druid"];
|
tplemail.allowedprofils = ["anonymous", "druid"];
|
||||||
tplemail.subject = "Code de vérification - Vérification de votre email";
|
tplemail.subject = "Code de vérification - Vérification de votre email";
|
||||||
tplemail.html = `
|
tplemail.html = `
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// See https://nodemailer.com/message/ for available fields to add
|
// See https://nodemailer.com/message/ for available fields to add
|
||||||
// email template to get key registration
|
// email template to get key registration
|
||||||
const tplemail={};
|
const tplemail={};
|
||||||
|
tplemail.nofilterpreprod = true;
|
||||||
tplemail.sender = "smatchtit<noreply@smatchit.io>"
|
tplemail.sender = "smatchtit<noreply@smatchit.io>"
|
||||||
tplemail.replyTo="{{{name}}}<{{{email}}}>"
|
tplemail.replyTo="{{{name}}}<{{{email}}}>"
|
||||||
tplemail.inreplyTo=""
|
tplemail.inreplyTo=""
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// See https://nodemailer.com/message/ for available fields to add
|
// See https://nodemailer.com/message/ for available fields to add
|
||||||
// email template to get key registration
|
// email template to get key registration
|
||||||
const tplemail={};
|
const tplemail={};
|
||||||
|
tplemail.nofilterpreprod = true;
|
||||||
tplemail.sender = "smatchtit<noreply@smatchit.io>"
|
tplemail.sender = "smatchtit<noreply@smatchit.io>"
|
||||||
tplemail.replyTo="{{{name}}}<{{{email}}}>"
|
tplemail.replyTo="{{{name}}}<{{{email}}}>"
|
||||||
tplemail.inreplyTo=""
|
tplemail.inreplyTo=""
|
||||||
|
|||||||
Reference in New Issue
Block a user