fix envoie email de check
This commit is contained in:
@@ -396,14 +396,18 @@ Notifications.manageemail = async (
|
||||
};
|
||||
}
|
||||
//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)) {
|
||||
return {
|
||||
status: 404,
|
||||
ref: "Notification",
|
||||
msg: "templatenotfound",
|
||||
data: { template: tplpath },
|
||||
};
|
||||
const fallbacktplpath = `../adminapi/template/${templatename}_${lg}.js`;
|
||||
if (!fs.existsSync(fallbacktplpath)) {
|
||||
return {
|
||||
status: 404,
|
||||
ref: "Notification",
|
||||
msg: "templatenotfound",
|
||||
data: { template: tplpath },
|
||||
};
|
||||
}
|
||||
tplpath = fallbacktplpath;
|
||||
}
|
||||
const results = { fail: [], success: [], simulated: [] };
|
||||
const emailtosend = {};
|
||||
@@ -574,7 +578,48 @@ Notifications.sendmail = async (data, tribe) => {
|
||||
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 {
|
||||
status: 412,
|
||||
ref: "Notifications",
|
||||
@@ -584,7 +629,7 @@ Notifications.sendmail = async (data, tribe) => {
|
||||
}
|
||||
|
||||
if (!data.from) {
|
||||
data.from = conf.emailcontact;
|
||||
data.from = confemailcontact;
|
||||
}
|
||||
|
||||
let missingk = [];
|
||||
@@ -601,32 +646,14 @@ Notifications.sendmail = async (data, tribe) => {
|
||||
data: { missingk: missingk },
|
||||
};
|
||||
}
|
||||
let confsmtp = conf.smtp;
|
||||
let confbrevoapikey = conf.BREVO.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 },
|
||||
};
|
||||
|
||||
if (confbrevo && confbrevo.APIKEY) {
|
||||
const toEmails = data.to.split(",");
|
||||
for (const email of toEmails) {
|
||||
await ensureContact(email, confbrevo.APIKEY);
|
||||
}
|
||||
confsmtp = conftrib.smtp;
|
||||
if (!data.from || data.from == conf.emailcontact)
|
||||
data.from = conftrib.emailcontact;
|
||||
if (conftrib.BREVO){
|
||||
const toEmails = data.to.split(",");
|
||||
for (const email of toEmails) {
|
||||
await ensureContact(email,conftrib.BREVO.APIKEY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (log) console.log(currentmod,"Warning: this conf does not exist:",path.resolve(conftribfile));
|
||||
}
|
||||
|
||||
|
||||
//console.log(confsmtp);
|
||||
const transporter = await nodemailer.createTransport(confsmtp);
|
||||
if (data.filelist) {
|
||||
|
||||
+17
-4
@@ -50,7 +50,7 @@ Pagans.logout = (alias, tribe, xdays, xhash) => {
|
||||
* @Param lg language to send email
|
||||
*/
|
||||
|
||||
Pagans.keyrecovery = (emailalias, tribe, search, lg) => {
|
||||
Pagans.keyrecovery = async (emailalias, tribe, search, lg) => {
|
||||
if (log)
|
||||
console.log(
|
||||
currentmod,
|
||||
@@ -108,16 +108,29 @@ Pagans.keyrecovery = (emailalias, tribe, search, lg) => {
|
||||
/* emaillist.forEach((e) => {
|
||||
const ret = Pagans.sendmailkey(e);
|
||||
});*/
|
||||
let numberemailsent = 0;
|
||||
let emailfail = 0;
|
||||
for (let i = 0; i < emaillist.length && i < 3; 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) {
|
||||
return {
|
||||
status: 200,
|
||||
ref: "Pagans",
|
||||
msg: "recoveryemailsent",
|
||||
data: { numberemailsent: emaillist.length },
|
||||
data: { numberemailsent, emailfail },
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -241,7 +254,7 @@ Pagans.sendmailkey = (data) => {
|
||||
person.avecpassphrase = person.passphrase != "";
|
||||
let tplfile = `../${data.tribe}/template/createidentity_${data.lg}.js`;
|
||||
if (!fs.existsSync(tplfile)) {
|
||||
tplfile = `../${data.tribe}/template/createidentity_${data.lg}.js`;
|
||||
tplfile = `../adminapi/template/createidentity_${data.lg}.js`;
|
||||
if (!fs.existsSync(tplfile)) {
|
||||
return {
|
||||
status: 406,
|
||||
|
||||
@@ -283,7 +283,7 @@ router.get("/checkemail/:email/:digit6", checkHeaders, async (req, res) => {
|
||||
emailsto: [{ to: email, code }]
|
||||
},
|
||||
"checkemail",
|
||||
"adminapi",
|
||||
req.session.header.xtribe,
|
||||
Notifications.recipientlang(null, req.session.header.xlang),
|
||||
1,
|
||||
["anonymous"]
|
||||
|
||||
+19
-4
@@ -157,7 +157,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
|
||||
alias: req.body.alias,
|
||||
privatekey: req.body.privatekey,
|
||||
tribe: req.session.header.xtribe,
|
||||
passprhase: req.body.passphrase,
|
||||
passphrase: req.body.passphrase,
|
||||
publickey: req.body.publickey,
|
||||
email: req.body.email,
|
||||
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 } }
|
||||
*
|
||||
*/
|
||||
router.post("/keyrecovery", checkHeaders, (req, res) => {
|
||||
const recores=Pagans.keyrecovery(req.body.emailalias,req.body.tribe,req.body.search,req.session.header.xlang)
|
||||
res.status(recores.status).json(recores);
|
||||
router.post("/keyrecovery", checkHeaders, async (req, res) => {
|
||||
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);
|
||||
} 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;
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@
|
||||
"name": "tribes",
|
||||
"keyval": "tribeId",
|
||||
"type": "view",
|
||||
"objkey": [],
|
||||
"objkey": ["dns","status","nationId","townId","activelog","wco","emailcontact"],
|
||||
"filter": "",
|
||||
"apxaccess": {
|
||||
"R": [
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const tplemail = {};
|
||||
tplemail.nofilterpreprod = true;
|
||||
tplemail.allowedprofils = ["anonymous", "druid"];
|
||||
tplemail.subject = "Verification code - Email verification";
|
||||
tplemail.html = `
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const tplemail = {};
|
||||
tplemail.nofilterpreprod = true;
|
||||
tplemail.allowedprofils = ["anonymous", "druid"];
|
||||
tplemail.subject = "Code de vérification - Vérification de votre email";
|
||||
tplemail.html = `
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// See https://nodemailer.com/message/ for available fields to add
|
||||
// email template to get key registration
|
||||
const tplemail={};
|
||||
tplemail.nofilterpreprod = true;
|
||||
tplemail.sender = "smatchtit<noreply@smatchit.io>"
|
||||
tplemail.replyTo="{{{name}}}<{{{email}}}>"
|
||||
tplemail.inreplyTo=""
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// See https://nodemailer.com/message/ for available fields to add
|
||||
// email template to get key registration
|
||||
const tplemail={};
|
||||
tplemail.nofilterpreprod = true;
|
||||
tplemail.sender = "smatchtit<noreply@smatchit.io>"
|
||||
tplemail.replyTo="{{{name}}}<{{{email}}}>"
|
||||
tplemail.inreplyTo=""
|
||||
|
||||
Reference in New Issue
Block a user