Versione 1.0.21 - RIS ITALIA

This commit is contained in:
Surya Paolo
2023-12-02 15:23:35 +01:00
parent 8e42baf79e
commit 6edba03eff
11 changed files with 180 additions and 99 deletions

25
.env.test.pcb Normal file
View File

@@ -0,0 +1,25 @@
DATABASE=FreePlanet
UDB=paofreeplanet
PDB=suerteFreePlanet@1A
SEND_EMAIL=1
PORT=3001
ENABLE_PUSHNOTIFICATION=1
DIRECTORY_SERVER=freeplanet_serverside
SERVERDIR_WEBSITE=test.freeplanet_server
PORT_APP1="0"
DOMAIN=mongodb://localhost:27018/
SIGNCODE=abc123
DEBUG=0
LOCALE=0
DELAY_SENDEMAIL=1000
VAPI_KEY_SUBJECT="mailto:surya@riso.app"
PUBLIC_VAPI_KEY="BJgo8XR_upbnbMLWgCAUELo6DK7dRXffYAnFOxbaMMz5favBgcQBKT-eISqouO-jRad4Sw8l5nd2wCF6KorGiTc"
PRIVATE_VAPI_KEY="LVpFDJuKscdHuQr5pe20dFuYuWX1-ZRb6x72PP-Pp4I"
GCM_API_KEY="AIzaSyD7w1jztfVV05mX1iyxoI-r1pZWxuxdUK8"
PATH_CERT_KEY=key.pem
PATH_SERVER_CRT=cert.pem
PATH_SSL_ROOT_PEM=root.pem
PATH_SSL_CHAIN_PEM=chain.pem
PROD=0
PROJECT_DESCR_MAIN='__PROJECTS'
SECRK=iUUb38v23jjDFaosWj92axkBOXCQ

20
deploynode_on_pcb.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
source ./.env.test.pcb
echo "Sincronizzazione in corso PCB ... /var/www/$SERVERDIR_WEBSITE/"
echo ""
rsync -avz -e 'ssh -p 8822' css pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 8822' docs pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 8822' emails pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 8822' images pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 8822' plugins pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 8822' sass pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 8822' src pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/
rsync -avz -e 'ssh -p 8822' .env.production pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/.env.production
rsync -avz -e 'ssh -p 8822' .env.test.pcb pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/.env.test
rsync -avz -e 'ssh -p 8822' .env.test.pcb pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/.env.test.pcb
rsync -avz -e 'ssh -p 8822' package.json pcbuser@pcb:/var/www/$SERVERDIR_WEBSITE/package.json
echo "Sincronizzazione TERMINATA! - SERVER PCB!"

View File

@@ -25,3 +25,5 @@ Mar 03/10 ORE 22:49: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)! ✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
Sab 04/11 ORE 15:17: 🤖: Da Sùrya (Paolo) undefined (paoloar77): Sab 04/11 ORE 15:17: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)! ✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
Sab 02/12 ORE 14:15: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!

View File

@@ -14,7 +14,7 @@
"test-watch": "nodemon --exec 'npm test'" "test-watch": "nodemon --exec 'npm test'"
}, },
"engines": { "engines": {
"node": "^16.19.0" "node": "^18.17.0"
}, },
"author": "Paolo Arena", "author": "Paolo Arena",
"license": "MIT", "license": "MIT",

View File

@@ -1161,7 +1161,7 @@ CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, va
CircuitSchema.statics.setFido = async function (idapp, username, circuitName, groupname) { CircuitSchema.statics.setFido = async function (idapp, username, circuitName, groupname) {
mycircuit = await Circuit.findOne({ idapp, name: circuitName }); mycircuit = await Circuit.findOne({ idapp, name: circuitName }).lean();
if (mycircuit) { if (mycircuit) {
const circuitId = mycircuit._id; const circuitId = mycircuit._id;
let account = null; let account = null;
@@ -1178,7 +1178,7 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
const accountsuser = await Account.getUserAccounts(idapp, username); const accountsuser = await Account.getUserAccounts(idapp, username);
if (accountsuser) { if (accountsuser) {
// Se lo trovo della mia provincia, prendo quello // Se lo trovo della mia provincia, prendo quello
account = accountsuser.find((account) => account.circuit.strProv === myuser.profile.resid_province && account.circuit.card === myuser.profile.resid_card) account = accountsuser.find((account) => account.circuit.strProv === myuser.profile.resid_province && ((account.circuit.card === myuser.profile.resid_card) || !myuser.profile.resid_card))
if (!account && accountsuser.length > 0) { if (!account && accountsuser.length > 0) {
// Se non lo trovo, prendo il primo in cui sono entrato ! // Se non lo trovo, prendo il primo in cui sono entrato !
account = accountsuser[0]; account = accountsuser[0];

View File

@@ -4696,7 +4696,7 @@ UserSchema.statics.calcnumRegUntilDay = async function (idapp) {
UserSchema.statics.calcRegDaily = async function (idapp) { UserSchema.statics.calcRegDaily = async function (idapp) {
const User = this; const User = this;
return await User.aggregate(User.getUsersRegDaily(idapp, 90)).then(ris => { return await User.aggregate(User.getUsersRegDaily(idapp, 120)).then(ris => {
// console.table(ris); // console.table(ris);
return ris; return ris;
}); });

View File

@@ -271,6 +271,7 @@ router.post('/', async (req, res) => {
return 1; return 1;
} }
if (utentenonancoraVerificato) { if (utentenonancoraVerificato) {
if (id_aportador) { if (id_aportador) {
// Se mi sono registrato ma l'invitante non mi abilita, allora il posso registrarmi nuovamente, con lo stesso username e password, // Se mi sono registrato ma l'invitante non mi abilita, allora il posso registrarmi nuovamente, con lo stesso username e password,
@@ -1405,6 +1406,9 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
} else if (mydata.dbop === 'updateSaldoAndTransato_AllAccounts') { } else if (mydata.dbop === 'updateSaldoAndTransato_AllAccounts') {
await Account.updateSaldoAndTransato_AllAccounts(idapp); await Account.updateSaldoAndTransato_AllAccounts(idapp);
} else if (mydata.dbop === 'GenerateVapiKey') {
await tools.generateVapiKey();
/*} else if (mydata.dbop === 'visuNave') { /*} else if (mydata.dbop === 'visuNave') {
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col)); mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
@@ -1634,5 +1638,4 @@ router.post('/mgt', authenticate, async (req, res) => {
}); });
module.exports = router; module.exports = router;

View File

@@ -7,25 +7,25 @@ const Email = require('email-templates');
const i18n = require('i18n'); const i18n = require('i18n');
const {ObjectID} = require('mongodb'); const { ObjectID } = require('mongodb');
const {Settings} = require('./models/settings'); const { Settings } = require('./models/settings');
const {TemplEmail} = require('./models/templemail'); const { TemplEmail } = require('./models/templemail');
const {Discipline} = require('./models/discipline'); const { Discipline } = require('./models/discipline');
const previewEmail = require('preview-email'); const previewEmail = require('preview-email');
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');
const OrdersCart = require('./models/orderscart'); const OrdersCart = require('./models/orderscart');
const {MyEvent} = require('./models/myevent'); const { MyEvent } = require('./models/myevent');
const {MailingList} = require('./models/mailinglist'); const { MailingList } = require('./models/mailinglist');
const {Newstosent} = require('./models/newstosent'); const { Newstosent } = require('./models/newstosent');
const server_constants = require('./tools/server_constants'); const server_constants = require('./tools/server_constants');
const shared_consts = require('./tools/shared_nodejs'); const shared_consts = require('./tools/shared_nodejs');
const {User} = require('./models/user'); const { User } = require('./models/user');
const { MsgTemplate } = require('./models/msg_template'); const { MsgTemplate } = require('./models/msg_template');
@@ -39,7 +39,7 @@ function checkifSendEmail() {
} }
module.exports = { module.exports = {
sendEmail_base_e_manager: function(idapp, template, to, mylocalsconf, replyTo, transport, previewonly) { sendEmail_base_e_manager: function (idapp, template, to, mylocalsconf, replyTo, transport, previewonly) {
this.sendEmail_base(template, to, mylocalsconf, replyTo, transport, previewonly); this.sendEmail_base(template, to, mylocalsconf, replyTo, transport, previewonly);
this.sendEmail_base(template, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '', transport, previewonly); this.sendEmail_base(template, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '', transport, previewonly);
@@ -51,7 +51,7 @@ module.exports = {
}, },
sendEmail_base: function(template, to, mylocalsconf, replyTo, transport, previewonly) { sendEmail_base: function (template, to, mylocalsconf, replyTo, transport, previewonly) {
if (to === '') if (to === '')
return false; return false;
@@ -127,7 +127,7 @@ module.exports = {
}); });
}, },
sendEmail_Normale: async function(to, subject, html, replyTo) { sendEmail_Normale: async function (to, subject, html, replyTo) {
// setup e-mail data with unicode symbols // setup e-mail data with unicode symbols
var mailOptions = { var mailOptions = {
@@ -147,7 +147,7 @@ module.exports = {
if (process.env.SEND_EMAIL === '1') { if (process.env.SEND_EMAIL === '1') {
// console.log("SEND EMAIL..."); // console.log("SEND EMAIL...");
// send mail with defined transport object // send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response) { smtpTransport.sendMail(mailOptions, function (error, response) {
if (error) { if (error) {
console.log('Email Inviata ERRORE RISPOSTA: ' + error); console.log('Email Inviata ERRORE RISPOSTA: ' + error);
} else { } else {
@@ -162,52 +162,58 @@ module.exports = {
} }
}, },
getlinkReg: function(idapp, idreg) { getlinkReg: function (idapp, idreg) {
const strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `/?idapp=${idapp}&idlink=${idreg}`; const strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `/?idapp=${idapp}&idlink=${idreg}`;
return strlinkreg; return strlinkreg;
}, },
sendEmail_Registration: async function(lang, emailto, user, idapp, idreg) { sendEmail_Registration: async function (lang, emailto, user, idapp, idreg) {
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp)); try {
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
// ++ estrai l'html da mettere sulla email: // ++ estrai l'html da mettere sulla email:
// const msghtml = await MsgTemplate.getMsgByLang(idapp, user, shared_consts.TypeMsgTemplate.MSG_BENV_REGISTRATO, user.lang); // const msghtml = await MsgTemplate.getMsgByLang(idapp, user, shared_consts.TypeMsgTemplate.MSG_BENV_REGISTRATO, user.lang);
let mylocalsconf = { let mylocalsconf = {
idapp, idapp,
dataemail: await this.getdataemail(idapp), dataemail: await this.getdataemail(idapp),
locale: lang, locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp), nomeapp: tools.getNomeAppByIdApp(idapp),
strlinksito: tools.getHostByIdApp(idapp), strlinksito: tools.getHostByIdApp(idapp),
strlinkreg: this.getlinkReg(idapp, idreg), strlinkreg: this.getlinkReg(idapp, idreg),
forgetpwd: tools.getHostByIdApp(idapp) + '/requestresetpwd', forgetpwd: tools.getHostByIdApp(idapp) + '/requestresetpwd',
emailto: emailto, emailto: emailto,
user, user,
}; };
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf); mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
this.sendEmail_base(tools.getpathregByIdApp(idapp, lang), emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp)); this.sendEmail_base(tools.getpathregByIdApp(idapp, lang), emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
// Send to the Admin an Email // Send to the Admin an Email
this.sendEmail_base('admin/registration/' + tools.LANGADMIN, tools.getAdminEmailByIdApp(idapp), mylocalsconf, ''); this.sendEmail_base('admin/registration/' + tools.LANGADMIN, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '');
await telegrambot.notifyToTelegram(telegrambot.phase.REGISTRATION, mylocalsconf); await telegrambot.notifyToTelegram(telegrambot.phase.REGISTRATION, mylocalsconf);
if (tools.getConfSiteOptionEnabledByIdApp(mylocalsconf.idapp, shared_consts.ConfSite.Notif_Reg_Push_Admin)) { if (tools.getConfSiteOptionEnabledByIdApp(mylocalsconf.idapp, shared_consts.ConfSite.Notif_Reg_Push_Admin)) {
const nometot = tools.getNomeCognomeEUserNameByUser(mylocalsconf); const nometot = tools.getNomeCognomeEUserNameByUser(mylocalsconf);
let aportador = mylocalsconf.aportador_solidario ? ' (da ' + mylocalsconf.aportador_solidario + ')' : ''; let aportador = mylocalsconf.aportador_solidario ? ' (da ' + mylocalsconf.aportador_solidario + ')' : '';
const numutenti = await User.getNumUsers(mylocalsconf.idapp); const numutenti = await User.getNumUsers(mylocalsconf.idapp);
tools.sendNotifToAdmin(mylocalsconf.idapp, true, '++Reg [' + numutenti + '] ' + nometot + aportador); tools.sendNotifToAdmin(mylocalsconf.idapp, true, '++Reg [' + numutenti + '] ' + nometot + aportador);
}
} catch (e) {
console.error('Err sendEmail_Registration', e);
} }
// if (tools.isManagAndAdminDifferent(idapp)) { // if (tools.isManagAndAdminDifferent(idapp)) {
// this.sendEmail_base('admin/registration/' + tools.LANGADMIN, tools.getManagerEmailByIdApp(idapp), mylocalsconf, ''); // this.sendEmail_base('admin/registration/' + tools.LANGADMIN, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
// } // }
}, },
sendEmail_IscrizioneConacreis: async function(lang, emailto, iscritto, idapp) {
sendEmail_IscrizioneConacreis: async function (lang, emailto, iscritto, idapp) {
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp)); // console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
@@ -239,7 +245,7 @@ module.exports = {
} }
}, },
sendEmail_IscrizioneArcadei: async function(lang, emailto, iscritto, idapp) { sendEmail_IscrizioneArcadei: async function (lang, emailto, iscritto, idapp) {
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp)); // console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
try { try {
@@ -275,7 +281,7 @@ module.exports = {
} }
}, },
sendEmail_RequestNewPassword: async function(lang, user, emailto, idapp, tokenforgot, tokenforgot_code) { sendEmail_RequestNewPassword: async function (lang, user, emailto, idapp, tokenforgot, tokenforgot_code) {
console.log('sendEmail_RequestNewPassword'); console.log('sendEmail_RequestNewPassword');
let mylocalsconf = { let mylocalsconf = {
@@ -293,7 +299,7 @@ module.exports = {
this.sendEmail_base('resetpwd/' + lang, emailto, mylocalsconf, ''); this.sendEmail_base('resetpwd/' + lang, emailto, mylocalsconf, '');
}, },
sendEmail_Booking: async function(res, lang, emailto, user, idapp, recbooking) { sendEmail_Booking: async function (res, lang, emailto, user, idapp, recbooking) {
tools.mylog('sendEmail_Booking'); tools.mylog('sendEmail_Booking');
tools.mylog('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp); tools.mylog('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp);
@@ -340,11 +346,11 @@ module.exports = {
}, },
preparaConfPerBooking: async function(res, idapp, mylocalsconf, recbooking, title) { preparaConfPerBooking: async function (res, idapp, mylocalsconf, recbooking, title) {
let texthtml = ''; let texthtml = '';
let msgtelegram = title + ' Evento [' + mylocalsconf.username + ' (' + mylocalsconf.name + ' ' + mylocalsconf.surname + ')] ' + let msgtelegram = title + ' Evento [' + mylocalsconf.username + ' (' + mylocalsconf.name + ' ' + mylocalsconf.surname + ')] ' +
mylocalsconf.eventtextplain; mylocalsconf.eventtextplain;
if (recbooking.modified) { if (recbooking.modified) {
msgtelegram += ' (modificato) '; msgtelegram += ' (modificato) ';
} else { } else {
@@ -374,7 +380,7 @@ module.exports = {
if (recbooking.numpeopleDinnerShared > 0) { if (recbooking.numpeopleDinnerShared > 0) {
mylocalsconf.participantsDinnerShared = recbooking.numpeopleDinnerShared.toString() + ' ' + mylocalsconf.participantsDinnerShared = recbooking.numpeopleDinnerShared.toString() + ' ' +
tools.getres__('partecipanti a Cena Condivisa', res); tools.getres__('partecipanti a Cena Condivisa', res);
msgtelegram += mylocalsconf.participantsDinnerShared + '\n'; msgtelegram += mylocalsconf.participantsDinnerShared + '\n';
} }
@@ -384,11 +390,11 @@ module.exports = {
}, },
getName: function(mylocalsconf) { getName: function (mylocalsconf) {
return mylocalsconf.name ? (mylocalsconf.surname ? (mylocalsconf.name + ' ' + mylocalsconf.surname) : mylocalsconf.name) : mylocalsconf.username return mylocalsconf.name ? (mylocalsconf.surname ? (mylocalsconf.name + ' ' + mylocalsconf.surname) : mylocalsconf.name) : mylocalsconf.username
}, },
sendEmail_CancelBooking: async function(res, lang, emailto, user, idapp, recbooking) { sendEmail_CancelBooking: async function (res, lang, emailto, user, idapp, recbooking) {
tools.mylog('sendEmail_CancelBooking'); tools.mylog('sendEmail_CancelBooking');
@@ -425,7 +431,7 @@ module.exports = {
} }
}, },
sendEmail_Msg: async function(res, lang, emailto, user, idapp, recmsg) { sendEmail_Msg: async function (res, lang, emailto, user, idapp, recmsg) {
tools.mylog('sendEmail_Msg'); tools.mylog('sendEmail_Msg');
tools.mylog('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp); tools.mylog('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp);
@@ -456,7 +462,7 @@ module.exports = {
// this.sendEmail_base('admin/sendmsg/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf); // this.sendEmail_base('admin/sendmsg/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
}, },
sendEmail_ByText: async function(lang, emailto, user, idapp, rec) { sendEmail_ByText: async function (lang, emailto, user, idapp, rec) {
tools.mylog('sendEmail_ByText'); tools.mylog('sendEmail_ByText');
@@ -485,7 +491,7 @@ module.exports = {
// this.sendEmail_base('admin/sendmsg/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf); // this.sendEmail_base('admin/sendmsg/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
}, },
sendEmail_ByNotif: async function(lang, emailto, user, idapp, recnotif) { sendEmail_ByNotif: async function (lang, emailto, user, idapp, recnotif) {
tools.mylog('sendEmail_ByNotif'); tools.mylog('sendEmail_ByNotif');
@@ -514,7 +520,7 @@ module.exports = {
// this.sendEmail_base('admin/sendmsg/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf); // this.sendEmail_base('admin/sendmsg/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
}, },
Add_to_MailingList_AndSendEmailNotify: async function(lang, user, idapp, sendnews) { Add_to_MailingList_AndSendEmailNotify: async function (lang, user, idapp, sendnews) {
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp)); // console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
@@ -563,7 +569,7 @@ module.exports = {
} }
} }
return {code: server_constants.RIS_SUBSCRIBED_OK, msg: server_constants.RIS_SUBSCRIBED_MSG[lang]}; return { code: server_constants.RIS_SUBSCRIBED_OK, msg: server_constants.RIS_SUBSCRIBED_MSG[lang] };
} else { } else {
// Already Esist // Already Esist
return { return {
@@ -574,7 +580,7 @@ module.exports = {
}, },
Remove_from_MailingList: async function(lang, hashemail, idapp) { Remove_from_MailingList: async function (lang, hashemail, idapp) {
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp)); // console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
@@ -593,9 +599,9 @@ module.exports = {
let myperson = await MailingList.findOneAndUpdate({ let myperson = await MailingList.findOneAndUpdate({
idapp, idapp,
hash: hashemail, hash: hashemail,
}, {$set: fields_to_update}, {new: false}); }, { $set: fields_to_update }, { new: false });
if (myperson) { if (myperson) {
return {myperson, code: server_constants.RIS_UNSUBSCRIBED_OK, msg: ''}; return { myperson, code: server_constants.RIS_UNSUBSCRIBED_OK, msg: '' };
} else { } else {
// Not found ! // Not found !
@@ -608,10 +614,10 @@ module.exports = {
}, },
fieldsloop: function(mylocalsconf, myvar) { fieldsloop: function (mylocalsconf, myvar) {
const baseurl = tools.getHostByIdApp(mylocalsconf.idapp); const baseurl = tools.getHostByIdApp(mylocalsconf.idapp);
const urlunsibscribe = baseurl + '/unsubscribe?em=' + mylocalsconf.hashemail + '&mc=' + mylocalsconf.dataemail.mailchimpactive + const urlunsibscribe = baseurl + '/unsubscribe?em=' + mylocalsconf.hashemail + '&mc=' + mylocalsconf.dataemail.mailchimpactive +
'&email=' + mylocalsconf.emailto; '&email=' + mylocalsconf.emailto;
let out = myvar.replace('{urlunsubscribe}', urlunsibscribe); let out = myvar.replace('{urlunsubscribe}', urlunsibscribe);
out = out.replace('{email}', mylocalsconf.emailto); out = out.replace('{email}', mylocalsconf.emailto);
@@ -623,15 +629,15 @@ module.exports = {
return out; return out;
}, },
replacefields: function(mylocalsconf) { replacefields: function (mylocalsconf) {
try { try {
mylocalsconf.dataemail.disclaimer_out = !!mylocalsconf.dataemail.disclaimer ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disclaimer_out = !!mylocalsconf.dataemail.disclaimer ? this.fieldsloop(mylocalsconf,
mylocalsconf.dataemail.disclaimer) : ''; mylocalsconf.dataemail.disclaimer) : '';
mylocalsconf.dataemail.disc_bottom_out = !!mylocalsconf.dataemail.disc_bottom ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disc_bottom_out = !!mylocalsconf.dataemail.disc_bottom ? this.fieldsloop(mylocalsconf,
mylocalsconf.dataemail.disc_bottom) : ''; mylocalsconf.dataemail.disc_bottom) : '';
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) : '';
} catch (e) { } catch (e) {
console.error('Error replacefields: ' + e); console.error('Error replacefields: ' + e);
} }
@@ -665,7 +671,7 @@ module.exports = {
}; };
// console.log(mydata.templemail_id); // console.log(mydata.templemail_id);
mydata.templ = await TemplEmail.findOne({_id: mydata.templemail_id}); mydata.templ = await TemplEmail.findOne({ _id: mydata.templemail_id });
// console.log(mydata.templ); // console.log(mydata.templ);
return mydata; return mydata;
@@ -678,12 +684,12 @@ module.exports = {
// console.log('mylocalsconf.dataemail', mylocalsconf.dataemail); // console.log('mylocalsconf.dataemail', mylocalsconf.dataemail);
if (mylocalsconf.dataemail.email_service !== 'gmail' && mylocalsconf.dataemail.email_service !== undefined && if (mylocalsconf.dataemail.email_service !== 'gmail' && mylocalsconf.dataemail.email_service !== undefined &&
mylocalsconf.dataemail.email_service !== '') { mylocalsconf.dataemail.email_service !== '') {
smtpTransport = nodemailer.createTransport({ smtpTransport = nodemailer.createTransport({
host: mylocalsconf.dataemail.email_service, host: mylocalsconf.dataemail.email_service,
port: mylocalsconf.dataemail.email_port, port: mylocalsconf.dataemail.email_port,
secureConnection: true, secureConnection: true,
tls: {cipher: 'SSLv3'}, tls: { cipher: 'SSLv3' },
auth: { auth: {
user: mylocalsconf.dataemail.from, user: mylocalsconf.dataemail.from,
pass: tools.decryptdata(mylocalsconf.dataemail.pwd_from), pass: tools.decryptdata(mylocalsconf.dataemail.pwd_from),
@@ -715,7 +721,7 @@ module.exports = {
return smtpTransport; return smtpTransport;
}, },
setParamsForTemplate: function(user, mylocalsconf) { setParamsForTemplate: function (user, mylocalsconf) {
try { try {
mylocalsconf.username = user.username; mylocalsconf.username = user.username;
@@ -734,7 +740,7 @@ module.exports = {
return mylocalsconf; return mylocalsconf;
}, },
sendEmail_OrderProduct: async function(lang, idapp, orders, user) { sendEmail_OrderProduct: async function (lang, idapp, orders, user) {
const msginizio = 'Ordine n: ' + orders.numorder + ' ' + user.name + ' ' + user.surname; const msginizio = 'Ordine n: ' + orders.numorder + ' ' + user.name + ' ' + user.surname;
console.log(msginizio); console.log(msginizio);
@@ -755,10 +761,10 @@ module.exports = {
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf); mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
this.sendEmail_base_e_manager(idapp, 'ecommerce/makeorder/' + lang, mylocalsconf.emailto, mylocalsconf, this.sendEmail_base_e_manager(idapp, 'ecommerce/makeorder/' + lang, mylocalsconf.emailto, mylocalsconf,
mylocalsconf.dataemail.email_reply); mylocalsconf.dataemail.email_reply);
}, },
sendEmail_Order: async function(lang, idapp, orders, user, ordertype, status) { sendEmail_Order: async function (lang, idapp, orders, user, ordertype, status) {
const msginizio = 'INIZIO - sendEmail_Order ' + ordertype + ': ' + tools.getNomeAppByIdApp(idapp); const msginizio = 'INIZIO - sendEmail_Order ' + ordertype + ': ' + tools.getNomeAppByIdApp(idapp);
console.log(msginizio); console.log(msginizio);
@@ -780,7 +786,7 @@ module.exports = {
if ((status !== shared_consts.OrderStatus.CANCELED) && (status !== shared_consts.OrderStatus.RECEIVED)) { if ((status !== shared_consts.OrderStatus.CANCELED) && (status !== shared_consts.OrderStatus.RECEIVED)) {
const esito = this.sendEmail_base('ecommerce/' + ordertype + '/' + lang, mylocalsconf.emailto, mylocalsconf, const esito = this.sendEmail_base('ecommerce/' + ordertype + '/' + lang, mylocalsconf.emailto, mylocalsconf,
mylocalsconf.dataemail.email_reply); mylocalsconf.dataemail.email_reply);
this.sendEmail_base('ecommerce/' + ordertype + '/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf, ''); this.sendEmail_base('ecommerce/' + ordertype + '/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '');
@@ -791,7 +797,7 @@ module.exports = {
}, },
sendEmail_Newsletter_Events: async function(lang, idapp, id_newstosent) { sendEmail_Newsletter_Events: async function (lang, idapp, id_newstosent) {
const msginizio = 'INIZIO - sendEmail_Newsletter_Events: ' + tools.getNomeAppByIdApp(idapp); const msginizio = 'INIZIO - sendEmail_Newsletter_Events: ' + tools.getNomeAppByIdApp(idapp);
console.log(msginizio); console.log(msginizio);
@@ -814,7 +820,7 @@ module.exports = {
await Newstosent.processingJob(id_newstosent, true); await Newstosent.processingJob(id_newstosent, true);
const mynewsrec = await Newstosent.findOne({_id: id_newstosent}); const mynewsrec = await Newstosent.findOne({ _id: id_newstosent });
try { try {
mynewsrec.numemail_tot = userstosend.length; mynewsrec.numemail_tot = userstosend.length;
@@ -858,7 +864,7 @@ module.exports = {
// Send Email to the User // Send Email to the User
// console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')'); // console.log('-> Invio Email (', mynewsrec.numemail_sent, '/', mynewsrec.numemail_tot, ')');
const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, const esito = this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf,
mylocalsconf.dataemail.email_reply, smtpTransport); mylocalsconf.dataemail.email_reply, smtpTransport);
if ((mynewsrec.numemail_sent % 100) === 0) { if ((mynewsrec.numemail_sent % 100) === 0) {
const msgproc = 'In Corso ' + mynewsrec.numemail_sent + ' / ' + mynewsrec.numemail_tot + ' Email inviate...'; const msgproc = 'In Corso ' + mynewsrec.numemail_sent + ' / ' + mynewsrec.numemail_tot + ' Email inviate...';
@@ -869,7 +875,7 @@ module.exports = {
const updateml = await MailingList.findOneAndUpdate({ const updateml = await MailingList.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 });
//Delay for send email... //Delay for send email...
await tools.snooze(secpause); await tools.snooze(secpause);
@@ -914,7 +920,7 @@ module.exports = {
}, },
checkifSentNewsletter: async function(idapp) { checkifSentNewsletter: async function (idapp) {
// Check if is the time to send the Newsletter // Check if is the time to send the Newsletter
return await Newstosent.findNewsletter_To_Send(idapp).then((rec) => { return await Newstosent.findNewsletter_To_Send(idapp).then((rec) => {
@@ -924,7 +930,7 @@ module.exports = {
} }
, ,
checkifPendingNewsletter: async function(idapp) { checkifPendingNewsletter: async function (idapp) {
// Check if is the time to send the Newsletter // Check if is the time to send the Newsletter
// Only newsletter pending en 8 hour last email sent. // Only newsletter pending en 8 hour last email sent.
@@ -933,10 +939,10 @@ module.exports = {
}); });
}, },
sendNewsletter: async function(rec, idapp) { sendNewsletter: async function (rec, idapp) {
if (rec) { if (rec) {
// Start the job // Start the job
let myjobnews = await Newstosent.findOne({_id: rec._id}); let myjobnews = await Newstosent.findOne({ _id: rec._id });
if (!!myjobnews) { if (!!myjobnews) {
myjobnews.starting_job = true; myjobnews.starting_job = true;
myjobnews.datestartJob = new Date(); myjobnews.datestartJob = new Date();
@@ -951,7 +957,7 @@ module.exports = {
} }
}, },
testemail: async function(idapp, lang, previewonly) { testemail: async function (idapp, lang, previewonly) {
const myarrevents = await MyEvent.getLastEvents(idapp); const myarrevents = await MyEvent.getLastEvents(idapp);
const myemail = await Settings.getValDbSettings(idapp, 'EMAIL_TEST'); const myemail = await Settings.getValDbSettings(idapp, 'EMAIL_TEST');
@@ -979,14 +985,14 @@ module.exports = {
const smtpTransport = this.getTransport(mylocalsconf); const smtpTransport = this.getTransport(mylocalsconf);
console.log('-> Invio Email TEST a', mylocalsconf.emailto, 'previewonly', console.log('-> Invio Email TEST a', mylocalsconf.emailto, 'previewonly',
previewonly); previewonly);
return await this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, return await this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto,
mylocalsconf, '', smtpTransport, previewonly); mylocalsconf, '', smtpTransport, previewonly);
} }
}, },
testemailHtml: async function(idapp, lang, email, myuser) { testemailHtml: async function (idapp, lang, email, myuser) {
let mytitle = 'Prova msg'; let mytitle = 'Prova msg';
let messaggio = '<br><b>Ciao!</b><div>Come stai?</div><br>Tutto Bene?<br><a href="https://ayni.gifteconomy.app/">Prova Link</a><br><i>Corsivo</i></i>&nbsp;'; let messaggio = '<br><b>Ciao!</b><div>Come stai?</div><br>Tutto Bene?<br><a href="https://ayni.gifteconomy.app/">Prova Link</a><br><i>Corsivo</i></i>&nbsp;';
@@ -1008,4 +1014,4 @@ module.exports = {
}, },
} }
; ;

View File

@@ -250,6 +250,7 @@ myLoad().then(ris => {
cert: certificate, cert: certificate,
}; };
} else { } else {
// NON USATO !
credentials = { credentials = {
key: privateKey, key: privateKey,
cert: certificate, cert: certificate,
@@ -656,7 +657,6 @@ async function faitest() {
idapp: '1', idapp: '1',
username: 'paoloar77', username: 'paoloar77',
}); });
const langdest = 'it'; const langdest = 'it';
telegrambot.askConfirmationUser(myuser.idapp, shared_consts.CallFunz.REGISTRATION, myuser); telegrambot.askConfirmationUser(myuser.idapp, shared_consts.CallFunz.REGISTRATION, myuser);

View File

@@ -842,14 +842,19 @@ const MyTelegramBot = {
const langdest = myuser.lang; const langdest = myuser.lang;
const telegid = myuser.profile.teleg_id; const telegid = myuser.profile.teleg_id;
if (!userDest) {
userDest = myuser.username;
}
let userrecDest = await User.getUserShortDataByUsername(idapp, userDest); let userrecDest = await User.getUserShortDataByUsername(idapp, userDest);
let userId = userrecDest._id; let userId = userrecDest._id;
let title = this.getNomeAppByIdApp(idapp); let title = tools.getNomeAppByIdApp(idapp);
let keyb = null; let keyb = null;
let openUrl = '';
let domanda = ''; let domanda = '';
let msg_notifpush = '';
let send_notif = false; let send_notif = false;
let actions = []; let actions = [];
let tag = '';
const struserinfomsg = tools.getUserInfoMsg(idapp, myuser); const struserinfomsg = tools.getUserInfoMsg(idapp, myuser);
@@ -880,6 +885,7 @@ const MyTelegramBot = {
await setVerifiedReg(myuser.idapp, myuser.lang, myuser.username, userDest); await setVerifiedReg(myuser.idapp, myuser.lang, myuser.username, userDest);
} else { } else {
msg_notifpush = getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM', myuser.username);
domanda = getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM', myuser.username) + '<br>' + struserinfomsg; domanda = getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM', myuser.username) + '<br>' + struserinfomsg;
keyb = cl.getInlineKeyboard(myuser.lang, [ keyb = cl.getInlineKeyboard(myuser.lang, [
@@ -897,6 +903,7 @@ const MyTelegramBot = {
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_GRUPPO) { } else if (myfunc === shared_consts.CallFunz.RICHIESTA_GRUPPO) {
msg_notifpush = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), name);
domanda = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), name) + '<br>' + struserinfomsg; domanda = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), name) + '<br>' + struserinfomsg;
keyb = cl.getInlineKeyboard(myuser.lang, [ keyb = cl.getInlineKeyboard(myuser.lang, [
@@ -912,6 +919,7 @@ const MyTelegramBot = {
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_FIDO) { } else if (myfunc === shared_consts.CallFunz.RICHIESTA_FIDO) {
if (groupname) { if (groupname) {
msg_notifpush = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY_BYGROUP', locale: langdest }, groupname);
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY_BYGROUP', locale: langdest }, groupname) + '<br>' + struserinfomsg; domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY_BYGROUP', locale: langdest }, groupname) + '<br>' + struserinfomsg;
keyb = cl.getInlineKeyboard(myuser.lang, [ keyb = cl.getInlineKeyboard(myuser.lang, [
@@ -929,9 +937,10 @@ const MyTelegramBot = {
send_notif = true; send_notif = true;
} else { } else {
msg_notifpush = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest }, myuser.username, name);
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest }, myuser.username, name) + '<br>' + struserinfomsg; domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest }, myuser.username, name) + '<br>' + struserinfomsg;
const keyb = cl.getInlineKeyboard(myuser.lang, [ keyb = cl.getInlineKeyboard(myuser.lang, [
{ {
text: '✅ Abilita fido a ' + myuser.username, text: '✅ Abilita fido a ' + myuser.username,
callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP + callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
@@ -947,17 +956,18 @@ const MyTelegramBot = {
} }
} }
if (send_notif) {
// SEND PUSH NOTIFICATION
await this.sendNotificationToUser(userId, title, descr, openUrl, '', tag, actions);
}
// Invia Msg // Invia Msg
if (domanda) { if (domanda) {
const teleg_id = await User.TelegIdByUsername(idapp, userDest); const teleg_id = await User.TelegIdByUsername(idapp, userDest);
await this.local_sendMsgTelegramByIdTelegram(idapp, teleg_id, domanda, undefined, undefined, true, keyb); await this.local_sendMsgTelegramByIdTelegram(idapp, teleg_id, domanda, undefined, undefined, true, keyb);
} }
if (send_notif && msg_notifpush) {
// SEND PUSH NOTIFICATION
await tools.sendNotificationToUser(userId, title, msg_notifpush, openUrl, '', tag, actions);
}
} catch (e) { } catch (e) {
console.error('Error askConfirmationUser', e); console.error('Error askConfirmationUser', e);
} }

View File

@@ -4304,5 +4304,20 @@ module.exports = {
} }
}, },
generateVapiKey() {
const webpush = require('web-push');
const vapidKeys = webpush.generateVAPIDKeys();
const msg1 = 'VAPID Public Key:' + vapidKeys.publicKey;
const msg2 = 'VAPID Private Key:' + vapidKeys.privateKey;
console.log(msg1);
console.log(msg2);
return { msg: msg1 + ' ' + msg2 };
},
}; };