From 3424b20e9a993acd0c92e804109c02c600f9cb80 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Wed, 16 Oct 2019 15:28:49 +0200 Subject: [PATCH] (- Booking not available if is in the past - Delete record only if "Active Edit" is on - Image stretch width reduced. - Signin more dense) - Email also to Manager person - added "Reply-To" in the header of the email. --- package.json | 26 ++++---- server/config/config.js | 129 +++++++++++++++++++++++++++++++++------- server/sendemail.js | 62 ++++++++++++------- server/tools/general.js | 35 ++++++++++- 4 files changed, 195 insertions(+), 57 deletions(-) diff --git a/package.json b/package.json index 1cea874..0dbcda9 100644 --- a/package.json +++ b/package.json @@ -16,34 +16,34 @@ "license": "MIT", "dependencies": { "bcryptjs": "^2.4.3", - "body-parser": "^1.15.2", + "body-parser": "^1.19.0", "cors": "^2.8.4", "crypto-js": "^3.1.6", "dotenv": "^6.1.0", - "ejs": "^2.6.1", - "email-templates": "^5.0.1", - "express": "^4.14.0", + "ejs": "^2.7.1", + "email-templates": "^5.1.0", + "express": "^4.17.1", "i18n": "^0.8.3", "jade": "^1.11.0", "js-md5": "^0.7.3", "jsonwebtoken": "^7.1.9", - "lodash": "^4.15.0", + "lodash": "^4.17.15", "mongodb": "^2.2.5", - "mongoose": "^4.5.9", + "mongoose": "^4.13.19", + "mysql": "^2.17.1", "node-pre-gyp": "^0.11.0", "nodemailer": "^4.6.8", "preview-email": "0.0.8", - "pug": "^2.0.3", - "url-parse": "^1.4.4", + "pug": "^2.0.4", + "url-parse": "^1.4.7", "validator": "^5.6.0", - "web-push": "^3.3.3", - "xoauth2": "^1.2.0", - "mysql": "^2.17.1" + "web-push": "^3.4.0", + "xoauth2": "^1.2.0" }, "devDependencies": { "expect": "^1.20.2", - "mocha": "^3.0.2", - "nodemon": "^1.18.7", + "mocha": "^6.2.1", + "nodemon": "^1.19.4", "supertest": "^2.0.0" } } diff --git a/server/config/config.js b/server/config/config.js index c8f90a6..1d709e6 100644 --- a/server/config/config.js +++ b/server/config/config.js @@ -16,25 +16,110 @@ process.env.DATABASE = process.env.DATABASE || 'FreePlanet'; process.env.MONGODB_URI = process.env.DOMAIN + process.env.DATABASE; -MYAPPS = [ - { - idapp: '1', - name: 'FreePlanet', - adminemail: 'paolo.arena77@gmail.com' - }, - { - idapp: '2', - name: 'Associazione Shen', - adminemail: 'pao.loarena77@gmail.com' - }, - { - idapp: '3', - name: 'Brigitte', - adminemail: '' - }, - { - idapp: '4', - name: 'Mandala per l\'Anima', - adminemail: '' - } -]; +if (process.env.NODE_ENV === 'production') { + MYAPPS = [ + { + idapp: '1', + name: 'FreePlanet', + adminemail: 'paolo.arena77@gmail.com', + manageremail: '', + replyTo: 'paolo.arena77@gmail.com', + host: 'https://freeplanet.app', + portapp: '0', + }, + { + idapp: '2', + name: 'Associazione Shen', + adminemail: 'pao.loarena77@gmail.com', + manageremail: 'info@associazioneshen.it', + replyTo: 'info@associazioneshen.it', + host: 'http://associazioneshen.it', + portapp: '0', + }, + { + idapp: '3', + name: 'Brigitte MG Dumont', + adminemail: '', + manageremail: '', + replyTo: '', + host: 'http://brigittemgdumont.com', + portapp: '0', + }, + { + idapp: '4', + name: 'Mandala per l\'Anima', + adminemail: '', + manageremail: '', + replyTo: '', + host: 'http://mandalaperlanima.eu', + portapp: '0', + } + ]; +} else if (process.env.NODE_ENV === 'test') { + MYAPPS = [ + { + idapp: '1', + name: 'FreePlanet', + adminemail: 'paolo.arena77@gmail.com', + replyTo: 'paolo.arena77@gmail.com', + host: 'https://test.freeplanet.app', + portapp: '0', + }, + { + idapp: '2', + name: 'Associazione Shen', + adminemail: 'pao.loarena77@gmail.com', + replyTo: 'info@associazioneshen.it', + host: 'http://test.associazioneshen.it', + portapp: '0', + }, + { + idapp: '3', + name: 'Brigitte MG Dumont', + adminemail: '', + host: 'http://test.brigittemgdumont.com', + portapp: '0', + }, + { + idapp: '4', + name: 'Mandala per l\'Anima', + adminemail: '', + host: 'http://test.mandalaperlanima.eu', + portapp: '0', + } + ]; +} else { + MYAPPS = [ + { + idapp: '1', + name: 'FreePlanet', + adminemail: 'paolo.arena77@gmail.com', + replyTo: 'paolo.arena77@gmail.com', + host: 'http://localhost', + portapp: '8080', + }, + { + idapp: '2', + name: 'Associazione Shen', + adminemail: 'paolo.arena77@gmail.com', + replyTo: 'info@associazioneshen.it', + host: 'http://localhost', + portapp: '8081', + }, + { + idapp: '3', + name: 'Brigitte', + adminemail: 'paolo.arena77@gmail.com', + host: 'http://localhost', + portapp: '8082', + }, + { + idapp: '4', + name: 'Mandala per l\'Anima', + adminemail: 'paolo.arena77@gmail.com', + host: 'http://localhost', + portapp: '8083', + } + ]; + +} diff --git a/server/sendemail.js b/server/sendemail.js index b61c290..c1e8df0 100644 --- a/server/sendemail.js +++ b/server/sendemail.js @@ -29,13 +29,16 @@ function checkifSendEmail() { } module.exports = { - sendEmail_base: function (template, username, to, mylocalsconf) { + sendEmail_base: function (template, username, to, mylocalsconf, replyTo) { // console.log("check EMAIL :" + checkifSendEmail()); const email = new Email({ message: { from: process.env.EMAIL_FROM, // sender address + headers: { + 'Reply-To': replyTo + } }, send: checkifSendEmail(), preview: !checkifSendEmail(), @@ -48,6 +51,7 @@ module.exports = { }, }); + email .send({ template: template, @@ -60,7 +64,7 @@ module.exports = { .catch(console.error); }, - sendEmail_Normale: function (to, subject, html) { + sendEmail_Normale: function (to, subject, html, replyTo) { // setup e-mail data with unicode symbols var mailOptions = { @@ -71,6 +75,9 @@ module.exports = { html: html, }; + if (replyTo) + mailOptions['reply-to'] = replyTo; + if (process.env.SEND_EMAIL === 1) { console.log("SEND EMAIL smtpTransport"); // send mail with defined transport object @@ -88,21 +95,21 @@ module.exports = { transport_preview.sendMail(mailOptions).then(console.log).catch(console.error); } }, - getHostByIdApp: function (idapp) { - if (idapp === 1) { - let siteport = (process.env.PORT_APP1 !== "0") ? (':' + process.env.PORT_APP1) : ""; - return process.env.URLBASE_APP1 + siteport; - } else { - return "" - } - }, + // getHostByIdApp: function (idapp) { + // if (idapp === 1) { + // let siteport = (process.env.PORT_APP1 !== "0") ? (':' + process.env.PORT_APP1) : ""; + // return process.env.URLBASE_APP1 + siteport; + // } else { + // return "" + // } + // }, getlinkReg: function (idapp, idreg) { - strlinkreg = this.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `?idapp=${idapp}&idlink=${idreg}`; + strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `?idapp=${idapp}&idlink=${idreg}`; return strlinkreg; }, getlinkRequestNewPassword: function (idapp, user, tokenforgot) { - strlinkreg = this.getHostByIdApp(idapp) + "/#" + process.env.LINK_REQUEST_NEWPASSWORD + `?idapp=${idapp}&username=${user}&=tokenforgot=${tokenforgot}`; + strlinkreg = tools.getHostByIdApp(idapp) + "/#" + process.env.LINK_REQUEST_NEWPASSWORD + `?idapp=${idapp}&username=${user}&=tokenforgot=${tokenforgot}`; return strlinkreg; }, sendEmail_Registration: function (lang, emailto, user, idapp, idreg) { @@ -120,10 +127,14 @@ module.exports = { emailto: emailto, }; - this.sendEmail_base('registration/' + lang, user, emailto, mylocalsconf); + this.sendEmail_base('registration/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp)); // Send to the Admin an Email - this.sendEmail_base('admin/registration/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf); + this.sendEmail_base('admin/registration/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf, ''); + + if (tools.getManagerEmailByIdApp(idapp) !== '' && tools.isManagAndAdminDifferent(idapp)) { + this.sendEmail_base('admin/registration/' + lang, user, tools.getManagerEmailByIdApp(idapp), mylocalsconf, ''); + } }, sendEmail_RequestNewPassword: function (lang, emailto, idapp, tokenforgot) { @@ -135,7 +146,7 @@ module.exports = { emailto: emailto, }; - this.sendEmail_base('resetpwd/' + lang, user, emailto, mylocalsconf); + this.sendEmail_base('resetpwd/' + lang, user, emailto, mylocalsconf, ''); }, sendEmail_Booking: function (res, lang, emailto, user, idapp, recbooking) { @@ -165,10 +176,15 @@ module.exports = { texthtml = 'makebooking'; } - this.sendEmail_base('booking/'+texthtml+'/' + lang, user, emailto, mylocalsconf); + this.sendEmail_base('booking/'+texthtml+'/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp)); // Send Email also to the Admin - this.sendEmail_base('admin/'+texthtml+'/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf); + this.sendEmail_base('admin/'+texthtml+'/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf, ''); + + if (tools.getManagerEmailByIdApp(idapp) !== '' && tools.isManagAndAdminDifferent(idapp)) { + this.sendEmail_base('admin/'+texthtml+'/' + lang, user, tools.getManagerEmailByIdApp(idapp), mylocalsconf, ''); + } + }, sendEmail_CancelBooking: function (res, lang, emailto, user, idapp, recbooking) { @@ -189,10 +205,14 @@ module.exports = { if (recbooking.numpeople > 1) mylocalsconf.participants = recbooking.numpeople.toString() + ' ' + res.__("partecipanti"); - this.sendEmail_base('booking/cancelbooking/' + lang, user, emailto, mylocalsconf); + this.sendEmail_base('booking/cancelbooking/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp)); // Send Email also to the Admin - this.sendEmail_base('admin/cancelbooking/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf); + this.sendEmail_base('admin/cancelbooking/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf, ''); + + if (tools.getManagerEmailByIdApp(idapp) !== '' && tools.isManagAndAdminDifferent(idapp)) { + this.sendEmail_base('admin/cancelbooking/' + lang, user, tools.getManagerEmailByIdApp(idapp), mylocalsconf, ''); + } }, sendEmail_Msg: function (res, lang, emailto, user, idapp, recbooking) { @@ -211,8 +231,8 @@ module.exports = { event: recbooking.infoevent, }; - this.sendEmail_base('msg/sendmsg/' + lang, user, emailto, mylocalsconf); - + this.sendEmail_base('msg/sendmsg/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp)); + // Send Email also to the Admin // this.sendEmail_base('admin/sendmsg/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf); }, diff --git a/server/tools/general.js b/server/tools/general.js index 3c44346..ae9e79e 100644 --- a/server/tools/general.js +++ b/server/tools/general.js @@ -296,13 +296,26 @@ module.exports = { getNomeAppByIdApp: function (idapp) { - const myapp = MYAPPS.find(item => item.idapp === idapp); + const myapp = + MYAPPS.find(item => item.idapp === idapp); if (myapp) return myapp.name; else return ''; }, + getHostByIdApp: function (idapp) { + + const myapp = + MYAPPS.find(item => item.idapp === idapp); + if (myapp) { + let siteport = (myapp.portapp !== "0") ? (':' + myapp.portapp) : ""; + + return myapp.host + siteport; + } else + return ''; + }, + getAdminEmailByIdApp: function (idapp) { const myapp = MYAPPS.find((item) => item.idapp === idapp); if (myapp) @@ -311,6 +324,26 @@ module.exports = { return ''; }, + getreplyToEmailByIdApp: function (idapp) { + const myapp = MYAPPS.find((item) => item.idapp === idapp); + if (myapp) + return myapp.replyTo; + else + return ''; + }, + + isManagAndAdminDifferent(idapp) { + return this.getManagerEmailByIdApp(idapp) !== this.getAdminEmailByIdApp(idapp) + }, + + getManagerEmailByIdApp: function (idapp) { + const myapp = MYAPPS.find((item) => item.idapp === idapp); + if (myapp) + return myapp.manageremail; + else + return ''; + }, + };