- Dynamic Pages (MyPage)

- Uploading files to the Server FTP.
This commit is contained in:
Paolo Arena
2019-12-27 12:41:39 +01:00
parent 9d0e6136ac
commit e62cc62d88
11 changed files with 343 additions and 64 deletions

View File

@@ -86,7 +86,7 @@ module.exports = {
return !!ris
})
.catch((err) => {
console.error(err);
console.error('Error: ', err);
return false
});
},
@@ -298,7 +298,7 @@ module.exports = {
// Check if exist to the Mailing List
let myperson = await MailingList.findByHash(idapp, hash);
if (!myperson || !myperson.statesub) {
if (!myperson || !myperson.statesub || !myperson.wrongerr) {
if (!myperson) {
myperson = new MailingList({
name: mylocalsconf.name,
@@ -316,6 +316,7 @@ module.exports = {
myperson.idapp = idapp;
myperson.statesub = true; // subscription
myperson.wrongerr = false;
// Add/save new record to the DB MailingList
const res = await myperson.save();
@@ -374,7 +375,7 @@ module.exports = {
},
fieldsloop: function (myvar) {
fieldsloop: function (mylocalsconf, myvar) {
const baseurl = tools.getHostByIdApp(mylocalsconf.idapp);
const urlunsibscribe = baseurl + '/unsubscribe?em=' + mylocalsconf.hashemail + '&mc=' + mylocalsconf.dataemail.mailchimpactive + '&email=' + mylocalsconf.emailto;
@@ -388,14 +389,15 @@ module.exports = {
replacefields: function (mylocalsconf) {
mylocalsconf.dataemail.disclaimer_out = this.fieldsloop(mylocalsconf.dataemail.disclaimer);
mylocalsconf.dataemail.disc_bottom_out = this.fieldsloop(mylocalsconf.dataemail.disc_bottom);
mylocalsconf.dataemail.templ.testoheadermail = this.fieldsloop(mylocalsconf.dataemail.templ.testoheadermail);
mylocalsconf.dataemail.disclaimer_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disclaimer);
mylocalsconf.dataemail.disc_bottom_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disc_bottom);
mylocalsconf.dataemail.templ.testoheadermail_out = this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.testoheadermail);
return mylocalsconf
},
getdataemail: async (idapp) => {
console.log('getdataemail');
// console.log('getdataemail');
const mydata = {
content_after_events: await Settings.getValDbSettings(idapp, 'TEXT_AFTER_EV'),
mailchimpactive: tools.BoolToInt(await Settings.getValDbSettings(idapp, 'MAILCHIMP_ON')),
@@ -435,8 +437,8 @@ module.exports = {
host: mylocalsconf.dataemail.email_service,
port: mylocalsconf.dataemail.email_port,
auth: {
user: process.env.EMAIL_FROM,
pass: process.env.EMAIL_PW
user: mylocalsconf.dataemail.from,
pass: mylocalsconf.dataemail.pwd_from
}
});
} else if (mylocalsconf.dataemail.email_service === 'gmail') {
@@ -478,73 +480,79 @@ module.exports = {
dataemail: await this.getdataemail(idapp)
};
await Newstosent.processingJob(id_newstosent, true);
const mynewsrec = await Newstosent.findOne({ _id: id_newstosent });
mynewsrec.numemail_tot = userstosend.length;
mynewsrec.templemail_str = mylocalsconf.dataemail.templ.subject;
mynewsrec.numemail_sent = await MailingList.getnumSent(idapp, id_newstosent);
const smtpTransport = this.getTransport();
let secpause = await Settings.getValDbSettings(idapp, 'MSEC_PAUSE_SEND', process.env.DELAY_SENDEMAIL);
if (secpause > process.env.DELAY_SENDEMAIL)
secpause = process.env.DELAY_SENDEMAIL;
// LOOP USERS EMAIL
for (const user of userstosend) {
if (process.env.DEBUG)
await tools.snooze(30000);
const isok = await MailingList.isOk(idapp, user._id, id_newstosent);
if (isok) {
let secpause = await Settings.getValDbSettings(idapp, 'MSEC_PAUSE_SEND', process.env.DELAY_SENDEMAIL);
if (secpause > process.env.DELAY_SENDEMAIL)
secpause = process.env.DELAY_SENDEMAIL;
activate = await Newstosent.isActivated(id_newstosent);
activate = await Newstosent.isActivated(id_newstosent);
if (!activate) {
// Invio Newsletter Abortito!
mynewsrec.error_job = 'Invio Newsletter abortito alle ore ' + new Date().toDateString();
await mynewsrec.save();
console.log('*** L\'Invio della Newsletter è stato fermato ! ');
return false
}
if (!activate) {
// Invio Newsletter Abortito!
mynewsrec.error_job = 'Invio Newsletter abortito alle ore ' + new Date().toDateString() + new Date().toTimeString();
await mynewsrec.save();
await Newstosent.processingJob(id_newstosent, false);
console.log('*** L\'Invio della Newsletter è stato fermato ! ');
return false
}
mylocalsconf.name = user.name;
mylocalsconf.surname = user.surname;
mylocalsconf.emailto = user.email;
mylocalsconf.hashemail = tools.getHash(user.email);
mylocalsconf.name = user.name;
mylocalsconf.surname = user.surname;
mylocalsconf.emailto = user.email;
mylocalsconf.hashemail = tools.getHash(user.email);
await this.replacefields(mylocalsconf);
// If has already sent, don't send it again!
if (user.lastid_newstosent !== id_newstosent.toString()) {
// Send Email to the User
console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')');
const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply, smtpTransport);
//Put the result in the database, to check if is sent or not.
const updateml = await MailingList.findOneAndUpdate({
idapp,
email: user.email
}, { $set: { lastid_newstosent: ObjectID(id_newstosent) } }, { new: false });
mylocalsconf = this.replacefields(mylocalsconf);
//Delay for send email...
await tools.snooze(secpause);
// If has already sent, don't send it again!
if (user.lastid_newstosent !== id_newstosent.toString()) {
console.log('@@@@@ COMPARE DIVERSI: lastid', user.lastid_newstosent, 'idsent', id_newstosent.toString());
if (process.env.DEBUG)
await tools.snooze(5000);
// Send Email to the User
console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')');
const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply, smtpTransport);
//Put the result in the database, to check if is sent or not.
const updateml = await MailingList.findOneAndUpdate({
idapp,
email: user.email
}, { $set: { lastid_newstosent: ObjectID(id_newstosent) } }, { new: false });
mynewsrec.lastemailsent_Job = new Date();
mynewsrec.numemail_sent += 1;
//Delay for send email...
await tools.snooze(secpause);
const recsaved = await mynewsrec.save();
mynewsrec.lastemailsent_Job = new Date();
mynewsrec.numemail_sent = await MailingList.getnumSent(idapp, id_newstosent);
if (mynewsrec.numemail_sent === mynewsrec.numemail_tot) {
mynewsrec.datefinishJob = new Date();
mynewsrec.finish_job = true;
await mynewsrec.save().then((ris) => {
console.log('****', tools.getNomeAppByIdApp(idapp), mynewsrec.numemail_sent, 'Email inviate');
});
const recsaved = await mynewsrec.save();
} else {
console.log('*** COMPARE: UGUALI !!!!! lastid', user.lastid_newstosent, 'idsent', id_newstosent.toString());
}
}
}
await Newstosent.endJob(id_newstosent);
await Newstosent.processingJob(id_newstosent, false);
console.log('****', tools.getNomeAppByIdApp(idapp), mynewsrec.numemail_sent, 'Email inviate');
console.log('FINE (esco da funz) - sendEmail_Newsletter_Events', tools.getNomeAppByIdApp(idapp));
},