(- 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.
This commit is contained in:
Paolo Arena
2019-10-16 15:28:49 +02:00
parent 51ef3de29a
commit 3424b20e9a
4 changed files with 195 additions and 57 deletions

View File

@@ -16,34 +16,34 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"body-parser": "^1.15.2", "body-parser": "^1.19.0",
"cors": "^2.8.4", "cors": "^2.8.4",
"crypto-js": "^3.1.6", "crypto-js": "^3.1.6",
"dotenv": "^6.1.0", "dotenv": "^6.1.0",
"ejs": "^2.6.1", "ejs": "^2.7.1",
"email-templates": "^5.0.1", "email-templates": "^5.1.0",
"express": "^4.14.0", "express": "^4.17.1",
"i18n": "^0.8.3", "i18n": "^0.8.3",
"jade": "^1.11.0", "jade": "^1.11.0",
"js-md5": "^0.7.3", "js-md5": "^0.7.3",
"jsonwebtoken": "^7.1.9", "jsonwebtoken": "^7.1.9",
"lodash": "^4.15.0", "lodash": "^4.17.15",
"mongodb": "^2.2.5", "mongodb": "^2.2.5",
"mongoose": "^4.5.9", "mongoose": "^4.13.19",
"mysql": "^2.17.1",
"node-pre-gyp": "^0.11.0", "node-pre-gyp": "^0.11.0",
"nodemailer": "^4.6.8", "nodemailer": "^4.6.8",
"preview-email": "0.0.8", "preview-email": "0.0.8",
"pug": "^2.0.3", "pug": "^2.0.4",
"url-parse": "^1.4.4", "url-parse": "^1.4.7",
"validator": "^5.6.0", "validator": "^5.6.0",
"web-push": "^3.3.3", "web-push": "^3.4.0",
"xoauth2": "^1.2.0", "xoauth2": "^1.2.0"
"mysql": "^2.17.1"
}, },
"devDependencies": { "devDependencies": {
"expect": "^1.20.2", "expect": "^1.20.2",
"mocha": "^3.0.2", "mocha": "^6.2.1",
"nodemon": "^1.18.7", "nodemon": "^1.19.4",
"supertest": "^2.0.0" "supertest": "^2.0.0"
} }
} }

View File

@@ -16,25 +16,110 @@ process.env.DATABASE = process.env.DATABASE || 'FreePlanet';
process.env.MONGODB_URI = process.env.DOMAIN + process.env.DATABASE; process.env.MONGODB_URI = process.env.DOMAIN + process.env.DATABASE;
MYAPPS = [ if (process.env.NODE_ENV === 'production') {
{ MYAPPS = [
idapp: '1', {
name: 'FreePlanet', idapp: '1',
adminemail: 'paolo.arena77@gmail.com' name: 'FreePlanet',
}, adminemail: 'paolo.arena77@gmail.com',
{ manageremail: '',
idapp: '2', replyTo: 'paolo.arena77@gmail.com',
name: 'Associazione Shen', host: 'https://freeplanet.app',
adminemail: 'pao.loarena77@gmail.com' portapp: '0',
}, },
{ {
idapp: '3', idapp: '2',
name: 'Brigitte', name: 'Associazione Shen',
adminemail: '' adminemail: 'pao.loarena77@gmail.com',
}, manageremail: 'info@associazioneshen.it',
{ replyTo: 'info@associazioneshen.it',
idapp: '4', host: 'http://associazioneshen.it',
name: 'Mandala per l\'Anima', portapp: '0',
adminemail: '' },
} {
]; 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',
}
];
}

View File

@@ -29,13 +29,16 @@ function checkifSendEmail() {
} }
module.exports = { module.exports = {
sendEmail_base: function (template, username, to, mylocalsconf) { sendEmail_base: function (template, username, to, mylocalsconf, replyTo) {
// console.log("check EMAIL :" + checkifSendEmail()); // console.log("check EMAIL :" + checkifSendEmail());
const email = new Email({ const email = new Email({
message: { message: {
from: process.env.EMAIL_FROM, // sender address from: process.env.EMAIL_FROM, // sender address
headers: {
'Reply-To': replyTo
}
}, },
send: checkifSendEmail(), send: checkifSendEmail(),
preview: !checkifSendEmail(), preview: !checkifSendEmail(),
@@ -48,6 +51,7 @@ module.exports = {
}, },
}); });
email email
.send({ .send({
template: template, template: template,
@@ -60,7 +64,7 @@ module.exports = {
.catch(console.error); .catch(console.error);
}, },
sendEmail_Normale: function (to, subject, html) { sendEmail_Normale: function (to, subject, html, replyTo) {
// setup e-mail data with unicode symbols // setup e-mail data with unicode symbols
var mailOptions = { var mailOptions = {
@@ -71,6 +75,9 @@ module.exports = {
html: html, html: html,
}; };
if (replyTo)
mailOptions['reply-to'] = replyTo;
if (process.env.SEND_EMAIL === 1) { if (process.env.SEND_EMAIL === 1) {
console.log("SEND EMAIL smtpTransport"); console.log("SEND EMAIL smtpTransport");
// send mail with defined transport object // send mail with defined transport object
@@ -88,21 +95,21 @@ module.exports = {
transport_preview.sendMail(mailOptions).then(console.log).catch(console.error); transport_preview.sendMail(mailOptions).then(console.log).catch(console.error);
} }
}, },
getHostByIdApp: function (idapp) { // getHostByIdApp: function (idapp) {
if (idapp === 1) { // if (idapp === 1) {
let siteport = (process.env.PORT_APP1 !== "0") ? (':' + process.env.PORT_APP1) : ""; // let siteport = (process.env.PORT_APP1 !== "0") ? (':' + process.env.PORT_APP1) : "";
return process.env.URLBASE_APP1 + siteport; // return process.env.URLBASE_APP1 + siteport;
} else { // } else {
return "" // return ""
} // }
}, // },
getlinkReg: function (idapp, idreg) { 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; return strlinkreg;
}, },
getlinkRequestNewPassword: function (idapp, user, tokenforgot) { 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; return strlinkreg;
}, },
sendEmail_Registration: function (lang, emailto, user, idapp, idreg) { sendEmail_Registration: function (lang, emailto, user, idapp, idreg) {
@@ -120,10 +127,14 @@ module.exports = {
emailto: emailto, 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 // 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) { sendEmail_RequestNewPassword: function (lang, emailto, idapp, tokenforgot) {
@@ -135,7 +146,7 @@ module.exports = {
emailto: emailto, 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) { sendEmail_Booking: function (res, lang, emailto, user, idapp, recbooking) {
@@ -165,10 +176,15 @@ module.exports = {
texthtml = 'makebooking'; 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 // 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) { sendEmail_CancelBooking: function (res, lang, emailto, user, idapp, recbooking) {
@@ -189,10 +205,14 @@ module.exports = {
if (recbooking.numpeople > 1) if (recbooking.numpeople > 1)
mylocalsconf.participants = recbooking.numpeople.toString() + ' ' + res.__("partecipanti"); 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 // 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) { sendEmail_Msg: function (res, lang, emailto, user, idapp, recbooking) {
@@ -211,7 +231,7 @@ module.exports = {
event: recbooking.infoevent, 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 // Send Email also to the Admin
// this.sendEmail_base('admin/sendmsg/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf); // this.sendEmail_base('admin/sendmsg/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf);

View File

@@ -296,13 +296,26 @@ module.exports = {
getNomeAppByIdApp: function (idapp) { getNomeAppByIdApp: function (idapp) {
const myapp = MYAPPS.find(item => item.idapp === idapp); const myapp =
MYAPPS.find(item => item.idapp === idapp);
if (myapp) if (myapp)
return myapp.name; return myapp.name;
else else
return ''; 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) { getAdminEmailByIdApp: function (idapp) {
const myapp = MYAPPS.find((item) => item.idapp === idapp); const myapp = MYAPPS.find((item) => item.idapp === idapp);
if (myapp) if (myapp)
@@ -311,6 +324,26 @@ module.exports = {
return ''; 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 '';
},
}; };