- aggiornato sistema per inviare le newsletter !
This commit is contained in:
@@ -6,6 +6,7 @@ const tools = require('../tools/general');
|
|||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
mongoose.level = "F";
|
mongoose.level = "F";
|
||||||
|
|
||||||
|
const { User } = require('./user');
|
||||||
|
|
||||||
// Resolving error Unknown modifier: $pushAll
|
// Resolving error Unknown modifier: $pushAll
|
||||||
mongoose.plugin(schema => {
|
mongoose.plugin(schema => {
|
||||||
@@ -13,115 +14,84 @@ mongoose.plugin(schema => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const MailingListSchema = new Schema({
|
const MailingListSchema = new Schema({
|
||||||
idapp: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
email: {
|
|
||||||
type: String,
|
|
||||||
trim: true,
|
|
||||||
},
|
|
||||||
hash: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: String,
|
|
||||||
trim: true,
|
|
||||||
},
|
|
||||||
surname: {
|
|
||||||
type: String,
|
|
||||||
trim: true,
|
|
||||||
},
|
|
||||||
statesub: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
wrongerr: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
lastid_newstosent: {
|
|
||||||
type: String
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
MailingListSchema.statics.getFieldsForSearch = function () {
|
|
||||||
return [{ field: 'name', type: tools.FieldType.string },
|
|
||||||
{ field: 'surname', type: tools.FieldType.string },
|
|
||||||
{ field: 'email', type: tools.FieldType.string }]
|
|
||||||
};
|
|
||||||
|
|
||||||
MailingListSchema.statics.executeQueryTable = function (idapp, params) {
|
MailingListSchema.statics.executeQueryTable = function (idapp, params) {
|
||||||
params.fieldsearch = this.getFieldsForSearch();
|
params.fieldsearch = User.getFieldsForSearch();
|
||||||
return tools.executeQueryTable(this, idapp, params);
|
return tools.executeQueryTable(this, idapp, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
MailingListSchema.statics.findAllIdAppSubscribed = function (idapp) {
|
MailingListSchema.statics.findAllIdAppSubscribed = function (idapp) {
|
||||||
const MailingList = this;
|
|
||||||
|
|
||||||
const myfind = { idapp, statesub: true, wrongerr: { $ne: true } };
|
const myfind = {
|
||||||
|
idapp,
|
||||||
|
news_on: true,
|
||||||
|
$or: [
|
||||||
|
{ deleted: { $exists: false } },
|
||||||
|
{ deleted: { $exists: true, $eq: false } }],
|
||||||
|
$or: [
|
||||||
|
{ email_errata: { $exists: false } },
|
||||||
|
{ email_errata: { $exists: true, $ne: true } }],
|
||||||
|
};
|
||||||
|
|
||||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||||
|
|
||||||
return MailingList.find(myfind, (err, arrrec) => {
|
return User.find(myfind, (err, arrrec) => {
|
||||||
return arrrec
|
return arrrec
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
MailingListSchema.statics.getnumSent = async function (idapp, idmailinglist) {
|
MailingListSchema.statics.getnumSent = async function (idapp, idUser) {
|
||||||
const MailingList = this;
|
|
||||||
|
|
||||||
const myfind = { idapp, statesub: true, lastid_newstosent: idmailinglist };
|
const myfind = { idapp, news_on: true, lastid_newstosent: idUser };
|
||||||
|
|
||||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||||
|
|
||||||
return await MailingList.countDocuments(myfind);
|
return await User.countDocuments(myfind);
|
||||||
};
|
};
|
||||||
|
|
||||||
MailingListSchema.statics.isOk = async function (idapp, iduser, idmailinglist) {
|
MailingListSchema.statics.isOk = async function (idapp, iduser, idUser) {
|
||||||
const MailingList = this;
|
|
||||||
|
|
||||||
const myfind = { idapp, _id: iduser, statesub: true, lastid_newstosent: { $ne: idmailinglist } };
|
|
||||||
|
const myfind = { idapp, _id: iduser, news_on: true, lastid_newstosent: { $ne: idUser } };
|
||||||
|
|
||||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||||
|
|
||||||
return await MailingList.countDocuments(myfind) > 0;
|
return await User.countDocuments(myfind) > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MailingListSchema.statics.findAllIdApp = async function (idapp) {
|
MailingListSchema.statics.findAllIdApp = async function (idapp) {
|
||||||
const MailingList = this;
|
|
||||||
|
|
||||||
const myfind = { idapp };
|
const myfind = { idapp };
|
||||||
|
|
||||||
return await MailingList.find(myfind, (err, arrrec) => {
|
return await User.find(myfind, (err, arrrec) => {
|
||||||
return arrrec
|
return arrrec
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
MailingListSchema.statics.isUnsubscribed = async function (idapp, hash) {
|
MailingListSchema.statics.isUnsubscribed = async function (idapp, hash) {
|
||||||
const MailingList = this;
|
|
||||||
|
|
||||||
let myperson = await MailingList.findOne({ idapp, hash });
|
let myperson = await User.findOne({ idapp, hash });
|
||||||
console.log('myperson', myperson);
|
|
||||||
if (!!myperson) {
|
if (!!myperson) {
|
||||||
return (!myperson.statesub)
|
return (!myperson.news_on)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MailingListSchema.statics.findByHash = function (idapp, hash) {
|
MailingListSchema.statics.findByHash = function (idapp, hash) {
|
||||||
const MailingList = this;
|
|
||||||
|
|
||||||
const myfind = { idapp, hash };
|
const myfind = { idapp, hash };
|
||||||
|
|
||||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||||
|
|
||||||
return MailingList.findOne(myfind, (err, rec) => {
|
return User.findOne(myfind, (err, rec) => {
|
||||||
return rec
|
return rec
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const MailingList = mongoose.model('MailingList', MailingListSchema);
|
const MailingList = mongoose.model('MailingList', MailingListSchema);
|
||||||
|
|
||||||
MailingList.createIndexes((err) => {
|
User.createIndexes((err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ const SiteSchema = new Schema({
|
|||||||
},
|
},
|
||||||
ecomm: {
|
ecomm: {
|
||||||
enablePreOrders: { type: Boolean, default: false },
|
enablePreOrders: { type: Boolean, default: false },
|
||||||
|
NoteExtraOnCart: { type: String, default: '' },
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ const UserSchema = new mongoose.Schema({
|
|||||||
message: '{VALUE} is not a valid email'
|
message: '{VALUE} is not a valid email'
|
||||||
}*/
|
}*/
|
||||||
},
|
},
|
||||||
|
hash: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
idapp: {
|
idapp: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -164,6 +167,12 @@ const UserSchema = new mongoose.Schema({
|
|||||||
news_on: {
|
news_on: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
|
email_errata: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
|
lastid_newstosent: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
aportador_solidario: { // da cancellare
|
aportador_solidario: { // da cancellare
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
@@ -1146,6 +1155,70 @@ UserSchema.statics.setaportador_solidario = async function (
|
|||||||
return !!myrec;
|
return !!myrec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.setNewsletter = async function (
|
||||||
|
idapp, username, newsletter_on) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
if (username === undefined)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const myquery = {
|
||||||
|
'idapp': idapp,
|
||||||
|
'username': username,
|
||||||
|
};
|
||||||
|
|
||||||
|
const myrec = await User.findOneAndUpdate(myquery,
|
||||||
|
{ $set: { 'news_on': newsletter_on } }, { new: false });
|
||||||
|
|
||||||
|
return !!myrec;
|
||||||
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.setEmailErrata = async function (
|
||||||
|
idapp, username, email_errata) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
if (username === undefined)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const myquery = {
|
||||||
|
'idapp': idapp,
|
||||||
|
'username': username,
|
||||||
|
};
|
||||||
|
|
||||||
|
const myrec = await User.findOneAndUpdate(myquery,
|
||||||
|
{ $set: { email_errata } }, { new: false });
|
||||||
|
|
||||||
|
return !!myrec;
|
||||||
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.isEmailErrata = async function (idapp, username) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
return await User.findOne({
|
||||||
|
idapp, username,
|
||||||
|
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||||
|
}).then((rec) => {
|
||||||
|
return ((rec) ? rec.email_errata : false);
|
||||||
|
}).catch((e) => {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
UserSchema.statics.isNewsletterOn = async function (idapp, username) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
return await User.findOne({
|
||||||
|
idapp, username,
|
||||||
|
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||||
|
}).then((rec) => {
|
||||||
|
return ((rec) ? rec.news_on : false);
|
||||||
|
}).catch((e) => {
|
||||||
|
console.error('isNewsletterOn', e);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UserSchema.statics.setVerifiedByAportadorToALL = async function () {
|
UserSchema.statics.setVerifiedByAportadorToALL = async function () {
|
||||||
|
|
||||||
return await User.updateMany({}, { $set: { 'verified_by_aportador': true } },
|
return await User.updateMany({}, { $set: { 'verified_by_aportador': true } },
|
||||||
@@ -1549,6 +1622,19 @@ UserSchema.statics.getUsernameById = async function (idapp, id) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.getUsernameByEmail = async function (idapp, email) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
return await User.findOne({
|
||||||
|
idapp, email,
|
||||||
|
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||||
|
}, { username: 1 }).then((myuser) => {
|
||||||
|
return ((myuser) ? myuser.username : '');
|
||||||
|
}).catch((e) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.getUserById = function (idapp, id) {
|
UserSchema.statics.getUserById = function (idapp, id) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ async function getDataNewsletter(lang, idapp) {
|
|||||||
|
|
||||||
for (const user of arrml) {
|
for (const user of arrml) {
|
||||||
data.totemail++;
|
data.totemail++;
|
||||||
if (user.statesub)
|
if (user.news_on)
|
||||||
data.totsubscribed++;
|
data.totsubscribed++;
|
||||||
else
|
else
|
||||||
data.totunsubscribed++;
|
data.totunsubscribed++;
|
||||||
@@ -284,6 +284,38 @@ router.post('/setactivate', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post('/unsubscribe_user', async (req, res) => {
|
||||||
|
hashemail = req.body.em;
|
||||||
|
email = req.body.email;
|
||||||
|
idapp = req.body.idapp;
|
||||||
|
locale = req.body.locale ?? 'it';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const myuser = await User.findOne({ idapp, email }).lean();
|
||||||
|
|
||||||
|
if (myuser) {
|
||||||
|
const hashcalc = tools.getHash(myuser.email + myuser.username);
|
||||||
|
|
||||||
|
if (hashcalc === hashemail) {
|
||||||
|
await User.setNewsletter(idapp, myuser.username, false);
|
||||||
|
|
||||||
|
return res.send({
|
||||||
|
code: server_constants.RIS_UNSUBSCRIBED_OK,
|
||||||
|
msg: server_constants.RIS_SUBSCRIBED_MSG[locale]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('err', e);
|
||||||
|
}
|
||||||
|
res.send({
|
||||||
|
code: server_constants.RIS_SUBSCRIBED_ERR
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
router.post('/unsubscribe', (req, res) => {
|
router.post('/unsubscribe', (req, res) => {
|
||||||
|
|
||||||
console.log('unsubscribe -> ', req.body);
|
console.log('unsubscribe -> ', req.body);
|
||||||
|
|||||||
@@ -1245,6 +1245,16 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
|||||||
|
|
||||||
} else if (mydata.dbop === 'updateReactionsCounts') {
|
} else if (mydata.dbop === 'updateReactionsCounts') {
|
||||||
await Reaction.updateReactionsCounts();
|
await Reaction.updateReactionsCounts();
|
||||||
|
} else if (mydata.dbop === 'AbilitaNewsletterALL') {
|
||||||
|
await User.updateMany({
|
||||||
|
$or: [
|
||||||
|
{ deleted: { $exists: false } },
|
||||||
|
{ deleted: { $exists: true, $eq: false } }],
|
||||||
|
|
||||||
|
},
|
||||||
|
{ $set: { news_on: true } },
|
||||||
|
{ new: false });
|
||||||
|
|
||||||
} else if (mydata.dbop === 'removeRegulations') {
|
} else if (mydata.dbop === 'removeRegulations') {
|
||||||
await Circuit.updateMany({}, { $set: { regulation: '' } });
|
await Circuit.updateMany({}, { $set: { regulation: '' } });
|
||||||
|
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ module.exports = {
|
|||||||
|
|
||||||
// Check if exist to the Mailing List
|
// Check if exist to the Mailing List
|
||||||
let myperson = await MailingList.findByHash(idapp, hash);
|
let myperson = await MailingList.findByHash(idapp, hash);
|
||||||
if (!myperson || !myperson.statesub || !myperson.wrongerr) {
|
if (!myperson || !myperson.news_on || !myperson.email_errata) {
|
||||||
if (!myperson) {
|
if (!myperson) {
|
||||||
myperson = new MailingList({
|
myperson = new MailingList({
|
||||||
name: mylocalsconf.name,
|
name: mylocalsconf.name,
|
||||||
@@ -557,8 +557,8 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
myperson.idapp = idapp;
|
myperson.idapp = idapp;
|
||||||
myperson.statesub = true; // subscription
|
myperson.news_on = true; // subscription
|
||||||
myperson.wrongerr = false;
|
myperson.email_errata = false;
|
||||||
|
|
||||||
// Add/save new record to the DB MailingList
|
// Add/save new record to the DB MailingList
|
||||||
const res = await myperson.save();
|
const res = await myperson.save();
|
||||||
@@ -597,9 +597,9 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fields_to_update = {
|
const fields_to_update = {
|
||||||
statesub: false,
|
news_on: false,
|
||||||
};
|
};
|
||||||
let myperson = await MailingList.findOneAndUpdate({
|
let myperson = await User.findOneAndUpdate({
|
||||||
idapp,
|
idapp,
|
||||||
hash: hashemail,
|
hash: hashemail,
|
||||||
}, { $set: fields_to_update }, { new: false });
|
}, { $set: fields_to_update }, { new: false });
|
||||||
@@ -618,16 +618,20 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
fieldsloop: function (mylocalsconf, myvar) {
|
fieldsloop: function (mylocalsconf, myvar) {
|
||||||
const baseurl = tools.getHostByIdApp(mylocalsconf.idapp);
|
let out = '';
|
||||||
const urlunsibscribe = baseurl + '/unsubscribe?em=' + mylocalsconf.hashemail + '&mc=' + mylocalsconf.dataemail.mailchimpactive +
|
try {
|
||||||
'&email=' + mylocalsconf.emailto;
|
out = myvar.replace('{urlunsubscribe}', tools.getUnsubsribeUrl(mylocalsconf));
|
||||||
|
out = out.replace('{urlunsubscribe_user}', tools.getUnsubsribeUrl_User({ idapp: mylocalsconf.idapp, email: mylocalsconf.emailto, username: mylocalsconf.username, name: mylocalsconf.name, surname: mylocalsconf.surname }));
|
||||||
|
|
||||||
let out = myvar.replace('{urlunsubscribe}', urlunsibscribe);
|
out = out.replace('{email}', mylocalsconf.emailto);
|
||||||
out = out.replace('{email}', mylocalsconf.emailto);
|
out = out.replace('{username}', mylocalsconf.username);
|
||||||
out = out.replace('{username}', mylocalsconf.username);
|
out = out.replace('{name}', mylocalsconf.name ? mylocalsconf.name : mylocalsconf.username);
|
||||||
out = out.replace('{name}', mylocalsconf.name ? mylocalsconf.name : mylocalsconf.username);
|
out = out.replace('{surname}', mylocalsconf.surname ? mylocalsconf.surname : '');
|
||||||
out = out.replace('{surname}', mylocalsconf.surname ? mylocalsconf.surname : '');
|
out = out.replace('{aportador_solidario}', mylocalsconf.aportador_solidario ? mylocalsconf.aportador_solidario : '');
|
||||||
out = out.replace('{aportador_solidario}', mylocalsconf.aportador_solidario ? mylocalsconf.aportador_solidario : '');
|
} catch (e) {
|
||||||
|
console.error('err fieldsloop', e);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
@@ -641,6 +645,10 @@ module.exports = {
|
|||||||
if (mylocalsconf.dataemail.templ)
|
if (mylocalsconf.dataemail.templ)
|
||||||
mylocalsconf.dataemail.templ.testoheadermail_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf,
|
mylocalsconf.dataemail.templ.testoheadermail_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf,
|
||||||
mylocalsconf.dataemail.templ.testoheadermail) : '';
|
mylocalsconf.dataemail.templ.testoheadermail) : '';
|
||||||
|
|
||||||
|
mylocalsconf.dataemail.templ.content = !!mylocalsconf.dataemail.templ.content ? this.fieldsloop(mylocalsconf,
|
||||||
|
mylocalsconf.dataemail.templ.content) : '';
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error replacefields: ' + e);
|
console.error('Error replacefields: ' + e);
|
||||||
}
|
}
|
||||||
@@ -896,7 +904,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Put the result in the database, to check if is sent or not.
|
//Put the result in the database, to check if is sent or not.
|
||||||
const updateml = await MailingList.findOneAndUpdate({
|
const updateml = await User.findOneAndUpdate({
|
||||||
idapp,
|
idapp,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
}, { $set: { lastid_newstosent: ObjectID(id_newstosent) } }, { new: false });
|
}, { $set: { lastid_newstosent: ObjectID(id_newstosent) } }, { new: false });
|
||||||
@@ -949,7 +957,7 @@ module.exports = {
|
|||||||
|
|
||||||
return await Newstosent.findNewsletter_To_Send(idapp).then((rec) => {
|
return await Newstosent.findNewsletter_To_Send(idapp).then((rec) => {
|
||||||
if (rec)
|
if (rec)
|
||||||
this.sendNewsletter(rec);
|
this.sendNewsletter(rec, idapp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
@@ -993,6 +1001,7 @@ module.exports = {
|
|||||||
arrevents: myarrevents,
|
arrevents: myarrevents,
|
||||||
name: 'TestNome',
|
name: 'TestNome',
|
||||||
surname: 'TestCognome',
|
surname: 'TestCognome',
|
||||||
|
username: await User.getUsernameByEmail(idapp, myemail),
|
||||||
emailto: myemail,
|
emailto: myemail,
|
||||||
baseurl: tools.getHostByIdApp(idapp),
|
baseurl: tools.getHostByIdApp(idapp),
|
||||||
hashemail: tools.getHash(myemail),
|
hashemail: tools.getHash(myemail),
|
||||||
@@ -1005,7 +1014,7 @@ module.exports = {
|
|||||||
|
|
||||||
mylocalsconf.dataemail.subject = mylocalsconf.dataemail && mylocalsconf.dataemail.templ ? mylocalsconf.dataemail.templ.subject : '',
|
mylocalsconf.dataemail.subject = mylocalsconf.dataemail && mylocalsconf.dataemail.templ ? mylocalsconf.dataemail.templ.subject : '',
|
||||||
|
|
||||||
this.replacefields(mylocalsconf);
|
this.replacefields(mylocalsconf);
|
||||||
|
|
||||||
const smtpTransport = this.getTransport(mylocalsconf);
|
const smtpTransport = this.getTransport(mylocalsconf);
|
||||||
|
|
||||||
|
|||||||
@@ -348,6 +348,7 @@ async function mystart() {
|
|||||||
console.log('decrypted:', decrypt);
|
console.log('decrypted:', decrypt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mycron();
|
||||||
if (!process.env.DEBUG) {
|
if (!process.env.DEBUG) {
|
||||||
mycron();
|
mycron();
|
||||||
}
|
}
|
||||||
@@ -394,14 +395,20 @@ function populateDBadmin() {
|
|||||||
let cfg = new CfgServer(cfgserv[0]).save();
|
let cfg = new CfgServer(cfgserv[0]).save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function mycron() {
|
async function mycron() {
|
||||||
|
|
||||||
const sendemail = require('./sendemail');
|
try {
|
||||||
|
const sendemail = require('./sendemail');
|
||||||
|
|
||||||
for (const app of tools.getApps()) {
|
const arr = await tools.getApps();
|
||||||
sendemail.checkifPendingNewsletter(app.idapp);
|
|
||||||
sendemail.checkifSentNewsletter(app.idapp);
|
|
||||||
|
|
||||||
|
for (const app of arr) {
|
||||||
|
sendemail.checkifPendingNewsletter(app.idapp);
|
||||||
|
sendemail.checkifSentNewsletter(app.idapp);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err mycron', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,11 +449,11 @@ function testmsgwebpush() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cron every X minutes
|
// Cron every X minutes
|
||||||
cron.schedule('*/2 * * * *', () => {
|
cron.schedule('*/1 * * * *', () => {
|
||||||
// console.log('Running Cron Job');
|
// console.log('Running Cron Job');
|
||||||
if (!process.env.DEBUG) {
|
// if (!process.env.DEBUG) {
|
||||||
mycron();
|
mycron();
|
||||||
}
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cron every X minutes
|
// Cron every X minutes
|
||||||
|
|||||||
@@ -4044,6 +4044,26 @@ module.exports = {
|
|||||||
return msg;
|
return msg;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getUnsubsribeUrl(mylocalsconf) {
|
||||||
|
|
||||||
|
if (mylocalsconf) {
|
||||||
|
const baseurl = this.getHostByIdApp(mylocalsconf.idapp);
|
||||||
|
const urlunsibscribe = baseurl + '/unsubscribe?em=' + mylocalsconf.hashemail + '&mc=' + mylocalsconf.dataemail.mailchimpactive +
|
||||||
|
'&email=' + mylocalsconf.emailto;
|
||||||
|
return urlunsibscribe;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
|
||||||
|
getUnsubsribeUrl_User(user) {
|
||||||
|
|
||||||
|
if (user && user.email) {
|
||||||
|
const hash = this.getHash(user.email + user.username);
|
||||||
|
return this.getHostByIdApp(user.idapp) + '/unsubscribe_user?em=' + hash + '&email=' + user.email;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
|
||||||
async convertSpecialTags(user, msg) {
|
async convertSpecialTags(user, msg) {
|
||||||
try {
|
try {
|
||||||
if (!msg)
|
if (!msg)
|
||||||
@@ -4060,6 +4080,9 @@ module.exports = {
|
|||||||
msg = await this.checkStr(msg, '{time_exp_reg}', user, 1);
|
msg = await this.checkStr(msg, '{time_exp_reg}', user, 1);
|
||||||
msg = msg.replace('{name}', user.name ? user.name : user.username);
|
msg = msg.replace('{name}', user.name ? user.name : user.username);
|
||||||
msg = msg.replace('{surname}', user.surname ? user.surname : '');
|
msg = msg.replace('{surname}', user.surname ? user.surname : '');
|
||||||
|
|
||||||
|
let out = myvar.replace('{urlunsubscribe_user}', this.getUnsubsribeUrl_User(user));
|
||||||
|
|
||||||
msg = msg.replace('{aportador_solidario}', user.aportador_solidario ? user.aportador_solidario : '');
|
msg = msg.replace('{aportador_solidario}', user.aportador_solidario ? user.aportador_solidario : '');
|
||||||
if (!!user.profile.link_payment)
|
if (!!user.profile.link_payment)
|
||||||
msg = msg.replace('{link_paypalme}', user.profile.link_payment);
|
msg = msg.replace('{link_paypalme}', user.profile.link_payment);
|
||||||
@@ -4413,7 +4436,7 @@ module.exports = {
|
|||||||
|
|
||||||
getWeightAndUnitByText(text) {
|
getWeightAndUnitByText(text) {
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
text = text.replace(",", ".");
|
text = text.replace(",", ".");
|
||||||
const regex = /^(\d+\.?\d*)\s*(ml|gr|l|kg)\s*$/; // Aggiunto un punto dopo \d+ per accettare anche i numeri con la virgola
|
const regex = /^(\d+\.?\d*)\s*(ml|gr|l|kg)\s*$/; // Aggiunto un punto dopo \d+ per accettare anche i numeri con la virgola
|
||||||
|
|
||||||
@@ -4466,13 +4489,13 @@ module.exports = {
|
|||||||
|
|
||||||
if (valstr === '' || valstr === undefined)
|
if (valstr === '' || valstr === undefined)
|
||||||
valstr = '0';
|
valstr = '0';
|
||||||
|
|
||||||
valstr = valstr + '';
|
valstr = valstr + '';
|
||||||
valstr = valstr.replace(',', '.');
|
valstr = valstr.replace(',', '.');
|
||||||
|
|
||||||
return parseFloat(valstr);
|
return parseFloat(valstr);
|
||||||
},
|
},
|
||||||
|
|
||||||
convertPriceEurToValue(inputString) {
|
convertPriceEurToValue(inputString) {
|
||||||
inputString = this.removeescape(this.addslashes(inputString))
|
inputString = this.removeescape(this.addslashes(inputString))
|
||||||
if (inputString === '')
|
if (inputString === '')
|
||||||
|
|||||||
Reference in New Issue
Block a user