- Send email when new subscriber to the newsletter

This commit is contained in:
Paolo Arena
2019-11-01 19:59:31 +01:00
parent 93ccc73517
commit f787fd3cea
8 changed files with 92 additions and 22 deletions

View File

@@ -0,0 +1,3 @@
p #{name} #{surname} si è appena iscritto alla Newsletter di #{nomeapp} con email:
strong #{emailto}<br>
p <br>Saluti

View File

@@ -0,0 +1 @@
=`${name} ${surname} si è appena iscritto alla Newsletter con email: ${emailto} su ${nomeapp}`

View File

@@ -19,16 +19,35 @@ const OperatorSchema = new Schema({
username: {
type: String,
},
name: {
type: String,
trim: true,
},
surname: {
type: String,
trim: true,
},
email: {
type: String,
trim: true,
},
cell: {
type: String,
},
webpage: {
type: String,
trim: true,
},
img: {
type: String,
},
skype: {
qualification: { // President, Vice-President, ecc...
type: String,
},
disciplines: {
type: String,
},
certifications: {
type: String,
},
webpage: {
type: String,
},
days_working: {
@@ -37,15 +56,26 @@ const OperatorSchema = new Schema({
facebook: {
type: String,
},
disciplines: {
info: {
type: String,
},
intro: {
type: String,
},
offers: {
type: String,
},
skype: {
type: String,
},
});
OperatorSchema.statics.getFieldsForSearch = function () {
return ['name', 'surname', 'email', 'cell']
};
OperatorSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
@@ -54,6 +84,9 @@ OperatorSchema.statics.findAllIdApp = function (idapp) {
const myfind = { idapp };
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
return Operator.find(myfind, (err, arrrec) => {
return arrrec
});

View File

@@ -34,6 +34,9 @@ var UserSchema = new mongoose.Schema({
message: '{VALUE} is not a valid email'
}*/
},
cell: {
type: String,
},
idapp: {
type: String,
required: true,
@@ -359,7 +362,7 @@ UserSchema.statics.getUsersListByParams = function (params) {
*/
UserSchema.statics.getFieldsForSearch = function () {
return ['name', 'surname', 'email']
return ['name', 'surname', 'email', 'cell']
};
UserSchema.statics.executeQueryTable = function (idapp, params) {

View File

@@ -208,7 +208,7 @@ router.patch('/chval', authenticate, (req, res) => {
const mytable = getTableByTableName(mydata.table);
const fieldsvalue = mydata.fieldsvalue;
tools.mylogshow('PATCH CHVAL: ', id);
tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
if (!User.isAdmin(req.user) && !User.isManager(req.user)) {
// If without permissions, exit

View File

@@ -4,6 +4,8 @@ const express = require('express');
const router = express.Router();
const request = require('superagent');
const sendemail = require('../sendemail');
const newsletter = [
{
name: 'Paolo',
@@ -41,8 +43,17 @@ const newsletter = [
router.post('/', (req, res) => {
idwebsite = req.body.idwebsite;
idapp = req.body.idapp;
locale = req.body.locale;
const user = {
email: req.body.email,
name: req.body.firstName,
surname: req.body.lastName,
};
sendemail.sendEmail_Newsletter(locale, user, idapp);
request
.post('https://' + newsletter[idwebsite].mailchimpInstance + '.api.mailchimp.com/3.0/lists/' + newsletter[idwebsite].listUniqueId + '/members/')
.set('Content-Type', 'application/json;charset=utf-8')

View File

@@ -30,7 +30,7 @@ function checkifSendEmail() {
module.exports = {
sendEmail_base: function (template, user, to, mylocalsconf, replyTo) {
sendEmail_base: function (template, to, mylocalsconf, replyTo) {
console.log('mylocalsconf', mylocalsconf);
@@ -135,13 +135,13 @@ module.exports = {
emailto: emailto,
};
this.sendEmail_base('registration/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
this.sendEmail_base('registration/' + lang, 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, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '');
if (tools.isManagAndAdminDifferent(idapp)) {
this.sendEmail_base('admin/registration/' + lang, user, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
this.sendEmail_base('admin/registration/' + lang, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
}
},
sendEmail_RequestNewPassword: function (lang, emailto, idapp, tokenforgot) {
@@ -154,7 +154,7 @@ module.exports = {
emailto: emailto,
};
this.sendEmail_base('resetpwd/' + lang, user, emailto, mylocalsconf, '');
this.sendEmail_base('resetpwd/' + lang, emailto, mylocalsconf, '');
},
sendEmail_Booking: function (res, lang, emailto, user, idapp, recbooking) {
@@ -184,13 +184,13 @@ module.exports = {
texthtml = 'makebooking';
}
this.sendEmail_base('booking/'+texthtml+'/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
this.sendEmail_base('booking/'+texthtml+'/' + lang, 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, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '');
if (tools.isManagAndAdminDifferent(idapp)) {
this.sendEmail_base('admin/'+texthtml+'/' + lang, user, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
this.sendEmail_base('admin/'+texthtml+'/' + lang, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
}
},
@@ -213,13 +213,13 @@ module.exports = {
if (recbooking.numpeople > 1)
mylocalsconf.participants = recbooking.numpeople.toString() + ' ' + res.__("partecipanti");
this.sendEmail_base('booking/cancelbooking/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
this.sendEmail_base('booking/cancelbooking/' + lang, 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, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '');
if (tools.isManagAndAdminDifferent(idapp)) {
this.sendEmail_base('admin/cancelbooking/' + lang, user, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
this.sendEmail_base('admin/cancelbooking/' + lang, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
}
},
@@ -240,10 +240,29 @@ module.exports = {
strlinkreply: tools.getHostByIdApp(idapp) + '/messages/' + recmsg._id
};
return this.sendEmail_base('msg/sendmsg/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
return this.sendEmail_base('msg/sendmsg/' + lang, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
// Send Email also to the Admin
// this.sendEmail_base('admin/sendmsg/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
// this.sendEmail_base('admin/sendmsg/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
},
sendEmail_Newsletter: function (lang, user, idapp) {
console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
mylocalsconf = {
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
name: user.name,
surname: user.surname,
emailto: user.email,
};
// Send to the Admin an Email
this.sendEmail_base('admin/added_to_newsletter/' + lang, tools.getAdminEmailByIdApp(idapp), mylocalsconf, '');
if (tools.isManagAndAdminDifferent(idapp)) {
this.sendEmail_base('admin/added_to_newsletter/' + lang, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
}
},

View File

@@ -1,9 +1,9 @@
module.exports = {
Permissions: {
Normal: 0,
Admin: 1,
Manager: 2,
Teacher: 4,
},
MessageOptions: {
@@ -12,7 +12,7 @@ module.exports = {
},
fieldsUserToChange() {
return ['username', 'email', 'name', 'surname', 'perm', 'date_reg', 'verified_email', 'img', 'ipaddr', 'lasttimeonline']
return ['username', 'email', 'cell', 'name', 'surname', 'perm', 'date_reg', 'verified_email', 'img', 'ipaddr', 'lasttimeonline']
}
};