- Booking Event (with email to user and admin)
- Cancel Event (with email to user and admin) - Store into mongodb
This commit is contained in:
29
emails/admin/cancelbooking/it/html.pug
Normal file
29
emails/admin/cancelbooking/it/html.pug
Normal file
@@ -0,0 +1,29 @@
|
||||
p Ciao,
|
||||
p Ti avvisiamo che #{name} #{surname} ha appena cancellato la prenotazione per l'evento #{event}:
|
||||
span #{participants}
|
||||
|
||||
p Cordiali Saluti
|
||||
p Supporto #{nomeapp}
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/admin/cancelbooking/it/subject.pug
Normal file
1
emails/admin/cancelbooking/it/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`${name} ${surname} ha cancellato la prenotazione all'evento ${eventtextplain}`
|
||||
29
emails/admin/makebookingadmin/it/html.pug
Normal file
29
emails/admin/makebookingadmin/it/html.pug
Normal file
@@ -0,0 +1,29 @@
|
||||
p Ciao,
|
||||
p Ti confermiamo che #{name} #{surname} ha appena inviato una richiesta di prenotazione per l'evento #{event}
|
||||
span #{participants}
|
||||
|
||||
p Cordiali Saluti
|
||||
p Supporto #{nomeapp}
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/admin/makebookingadmin/it/subject.pug
Normal file
1
emails/admin/makebookingadmin/it/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`${name} ${surname} si è prenotato per l'evento ${eventtextplain}`
|
||||
30
emails/admin/registration/enUs/html.pug
Normal file
30
emails/admin/registration/enUs/html.pug
Normal file
@@ -0,0 +1,30 @@
|
||||
p #{name} #{surname} has just registered on #{nomeapp}
|
||||
p With the following access datao:
|
||||
span Username:
|
||||
strong #{username}<br>
|
||||
span Email:
|
||||
strong #{emailto}<br>
|
||||
p <br>Regards
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/admin/registration/enUs/subject.pug
Normal file
1
emails/admin/registration/enUs/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`New Registration of ${name} ${surname} (${username}) in ${nomeapp}`
|
||||
30
emails/admin/registration/esEs/html.pug
Normal file
30
emails/admin/registration/esEs/html.pug
Normal file
@@ -0,0 +1,30 @@
|
||||
p #{name} #{surname} acaba de registrarse en #{nomeapp}
|
||||
p Con los siguientes datos de acceso:
|
||||
span Username:
|
||||
strong #{username}<br>
|
||||
span Email:
|
||||
strong #{emailto}<br>
|
||||
p <br>Saludos
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/admin/registration/esEs/subject.pug
Normal file
1
emails/admin/registration/esEs/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`Nuevo registro de ${name} ${surname} (${username}) en ${nomeapp}`
|
||||
30
emails/admin/registration/it/html.pug
Normal file
30
emails/admin/registration/it/html.pug
Normal file
@@ -0,0 +1,30 @@
|
||||
p #{name} #{surname} si è appena Registrato su #{nomeapp}
|
||||
p Con i seguenti dati di accesso:
|
||||
span Username:
|
||||
strong #{username}<br>
|
||||
span Email:
|
||||
strong #{emailto}<br>
|
||||
p <br>Saluti
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/admin/registration/it/subject.pug
Normal file
1
emails/admin/registration/it/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`Nuova Registrazione di ${name} ${surname} (${username}) su ${nomeapp}`
|
||||
29
emails/booking/cancelbooking/it/html.pug
Normal file
29
emails/booking/cancelbooking/it/html.pug
Normal file
@@ -0,0 +1,29 @@
|
||||
p Ciao #{name},
|
||||
p Ti confermiamo che la prenotazione per l'evento "#{event}" è stata cancellata.
|
||||
span #{participants}
|
||||
|
||||
p Cordiali Saluti
|
||||
p Supporto #{nomeapp}
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/booking/cancelbooking/it/subject.pug
Normal file
1
emails/booking/cancelbooking/it/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`Cancellazione prenotazione di ${eventtextplain}`
|
||||
29
emails/booking/makebooking/it/html.pug
Normal file
29
emails/booking/makebooking/it/html.pug
Normal file
@@ -0,0 +1,29 @@
|
||||
p Ciao #{name},
|
||||
p Ti confermiamo che hai appena inviato una richiesta di prenotazione per l'evento #{event}
|
||||
span #{participants}
|
||||
|
||||
p Cordiali Saluti
|
||||
p Supporto #{nomeapp}
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/booking/makebooking/it/subject.pug
Normal file
1
emails/booking/makebooking/it/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`Prenotazione per l'evento ${eventtextplain}`
|
||||
@@ -1,7 +1,7 @@
|
||||
p Welcome #{user} to the portal #{nomeapp}!
|
||||
p Welcome #{name} to the portal #{nomeapp}!
|
||||
p Your access data to remember are:
|
||||
span Username:
|
||||
strong #{user}<br>
|
||||
strong #{username}<br>
|
||||
span Forgot your Password? :
|
||||
strong <a href=#{forgetpwd} target="_blank">Find it here</a><br>
|
||||
span Email:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
p ¡Bienvenido #{user} al portal #{nomeapp}!
|
||||
p ¡Bienvenido #{name} al portal #{nomeapp}!
|
||||
p Sus datos de acceso a recordar son:
|
||||
Nombre Usuario:
|
||||
strong #{user}<br>
|
||||
strong #{username}<br>
|
||||
span ¿Olvidaste tu contraseña? :
|
||||
strong <a href=#{forgetpwd} target="_blank">Encuéntrelo aquí</a><br>
|
||||
span Email:
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
p Benvenuto #{user} nel portale di #{nomeapp}!
|
||||
p Benvenuto #{name} nel portale di #{nomeapp}!
|
||||
p I tuoi dati di accesso da ricordare sono:
|
||||
span Username:
|
||||
strong #{user}<br>
|
||||
strong #{username}<br>
|
||||
span hai dimenticato la Password? :
|
||||
strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br>
|
||||
span Email:
|
||||
strong #{emailto}<br>
|
||||
p Per confermare la registrazione clicca sul bottone:
|
||||
div.divbtn <a href=#{strlinkreg} target="_blank">
|
||||
button.btn.btn-lg Verify Registration</a>
|
||||
button.btn.btn-lg Verifica Registrazione</a>
|
||||
|
||||
p Potrai cosi' accedere al sito digitando i tuoi dati di accesso.
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
"url-parse": "^1.4.4",
|
||||
"validator": "^5.6.0",
|
||||
"web-push": "^3.3.3",
|
||||
"xoauth2": "^1.2.0"
|
||||
"xoauth2": "^1.2.0",
|
||||
"mysql": "^2.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"expect": "^1.20.2",
|
||||
|
||||
@@ -7,7 +7,6 @@ process.env.LINKVERIF_REG = '/vreg';
|
||||
process.env.LINK_REQUEST_NEWPASSWORD = '/requestnewpwd';
|
||||
process.env.LINK_CHECK_UPDATES = '/checkupdates';
|
||||
process.env.LINK_UPDATE_PASSWORD = '/updatepwd';
|
||||
process.env.NOME_APP1 = 'FreePlanet';
|
||||
process.env.KEY_APP_ID = 'KKPPAA5KJK435J3KSS9F9D8S9F8SD98F9SDF';
|
||||
|
||||
console.log("FILE : " + file);
|
||||
@@ -16,3 +15,26 @@ require('dotenv').config({path: file});
|
||||
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: ''
|
||||
}
|
||||
];
|
||||
|
||||
@@ -40,6 +40,7 @@ var options = {
|
||||
mongoose.connect(process.env.MONGODB_URI, options)
|
||||
.then(() =>
|
||||
console.log('connection succesful ' + process.env.MONGODB_URI + ' db: ' + process.env.DATABASE)
|
||||
|
||||
)
|
||||
.catch((err) => console.error(err));
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
{
|
||||
"L'Email è già stata Verificata": "Email was already verified",
|
||||
"Email Verificata!": "Email Verified!",
|
||||
|
||||
|
||||
"a": "a"
|
||||
"Email Verificata!": "Email Verificata!",
|
||||
"partecipanti": "partecipanti"
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"L'Email è già stata Verificata": "El email ya ha sido verificado",
|
||||
"Email Verificata!": "Email Verificada!",
|
||||
"L'Email è già stata Verificata": "El email ya ha sido verificado"
|
||||
"a": "a",
|
||||
"Nuova Registrazione": "Nuevo Registro",
|
||||
"Effettuata una Nuova Registrazione": "Se ha realizado un nuevo registro"
|
||||
"partecipanti": "participantes"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"L'Email è già stata Verificata": "L'Email è già stata Verificata",
|
||||
"Email Verificata!": "Email Verificata!",
|
||||
"a": "a",
|
||||
"Nuova Registrazione": "Nuova Registrazione",
|
||||
"Effettuata una Nuova Registrazione": "Effettuata una Nuova Registrazione",
|
||||
"partecipanti": "partecipanti"
|
||||
}
|
||||
|
||||
54
server/models/booking.js
Normal file
54
server/models/booking.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const bookingSchema = new Schema({
|
||||
idapp: {
|
||||
type: Number,
|
||||
},
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
id_bookedevent: {
|
||||
type: Number,
|
||||
},
|
||||
numpeople: {
|
||||
type: Number,
|
||||
},
|
||||
infoevent: {
|
||||
type: String,
|
||||
},
|
||||
msgbooking: {
|
||||
type: String,
|
||||
},
|
||||
datebooked: {
|
||||
type: Date,
|
||||
},
|
||||
booked: {
|
||||
type: Boolean,
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
bookingSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp) {
|
||||
const Booking = this;
|
||||
|
||||
return Booking.find({userId, idapp, booked: true}, (err, arrbooked) => {
|
||||
console.log('ris Booking:', arrbooked);
|
||||
return arrbooked
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var Booking = mongoose.model('Booking', bookingSchema);
|
||||
|
||||
module.exports = { Booking };
|
||||
@@ -42,6 +42,14 @@ var UserSchema = new mongoose.Schema({
|
||||
minlength: 6,
|
||||
unique: true,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
surname: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
require: true,
|
||||
@@ -88,7 +96,7 @@ UserSchema.methods.toJSON = function () {
|
||||
var user = this;
|
||||
var userObject = user.toObject();
|
||||
|
||||
return _.pick(userObject, ['_id', 'email', 'verified_email', 'username', 'userId']);
|
||||
return _.pick(userObject, ['_id', 'email', 'verified_email', 'username', 'userId', 'name', 'surname']);
|
||||
};
|
||||
|
||||
UserSchema.methods.generateAuthToken = function (req) {
|
||||
|
||||
39
server/mysql/mysql_func.js
Normal file
39
server/mysql/mysql_func.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const mysql = require('mysql');
|
||||
|
||||
|
||||
const mySqlConn_Shen = mysql.createConnection({
|
||||
host : '198.136.49.34',
|
||||
user : 'assoc499_user',
|
||||
password : 'mypassmysql@1A',
|
||||
database : 'assoc499_1',
|
||||
debug: true
|
||||
});
|
||||
|
||||
|
||||
module.exports = { mySqlConn_Shen };
|
||||
|
||||
|
||||
// POOL:
|
||||
// const pool = mysql.createPool({
|
||||
// connectionLimit : 100, //important
|
||||
// host : '198.136.49.34',
|
||||
// user : 'assoc499_user',
|
||||
// password : 'mypassmysql@1A',
|
||||
// database : 'assoc499_1',
|
||||
// debug : false
|
||||
// });
|
||||
//
|
||||
//
|
||||
// function pool_queryRow(tablename, fieldID, IdValue) {
|
||||
// let selectQuery = 'SELECT * FROM ?? WHERE ?? = ?';
|
||||
// let query = mysql.format(selectQuery,[tablename,fieldID, IdValue]);
|
||||
// // query = SELECT * FROM `tablename` where `fieldID` = 'IdValue'
|
||||
// pool.query(query,(err, data) => {
|
||||
// if(err) {
|
||||
// console.error(err);
|
||||
// return;
|
||||
// }
|
||||
// // rows fetch
|
||||
// console.log(data);
|
||||
// });
|
||||
// }
|
||||
101
server/router/booking_router.js
Normal file
101
server/router/booking_router.js
Normal file
@@ -0,0 +1,101 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const { Booking } = require('../models/booking');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
function sendNotif(res, idapp, user, recbooking) {
|
||||
//++Todo: tools.sendNotificationToUser
|
||||
|
||||
// Send Email
|
||||
if (recbooking.booked)
|
||||
sendemail.sendEmail_Booking(res, user.lang, user.email, user, idapp, recbooking);
|
||||
else
|
||||
sendemail.sendEmail_CancelBooking(res, user.lang, user.email, user, idapp, recbooking);
|
||||
}
|
||||
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
tools.mylog('INIZIO - booking');
|
||||
// tools.mylog('req.body', req.body);
|
||||
const body = _.pick(req.body, tools.allfieldBooking());
|
||||
const id = body.id_bookedevent;
|
||||
const fieldtochange = _.pick(req.body, tools.allfieldBookingChange());
|
||||
|
||||
tools.mylog('crea Booking');
|
||||
const booking = new Booking(body);
|
||||
|
||||
const check = tools.checkUserOk(booking.userId, req.user._id);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
// console.log('fieldtochange', fieldtochange);
|
||||
|
||||
return Booking.findOne({ id_bookedevent: id })
|
||||
.then(trovato => {
|
||||
// console.log('trovato', trovato);
|
||||
if (trovato) {
|
||||
return Booking.findOneAndUpdate({ id_bookedevent: id }, { $set: fieldtochange }, {
|
||||
new: true,
|
||||
upsert: true
|
||||
}).then((recbooking) => {
|
||||
// tools.mylog('booking:', booking);
|
||||
// tools.mylog('already exist');
|
||||
sendNotif(res, body.idapp, req.user, recbooking);
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recbooking._id });
|
||||
});
|
||||
} else {
|
||||
// save to database a new record
|
||||
tools.mylog('save to database a new record');
|
||||
booking._id = new ObjectID();
|
||||
return booking.save().then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
|
||||
Booking.findById(idobj)
|
||||
.then((recbooking) => {
|
||||
sendNotif(res, body.idapp, req.user, recbooking);
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recbooking._id });
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
router.get('/:userId/:idapp', authenticate, (req, res) => {
|
||||
const userId = req.params.userId;
|
||||
const idapp = req.params.idapp;
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET BOOKINGS : ', req.params);
|
||||
|
||||
if (!ObjectID.isValid(userId)) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
if (userId !== String(req.user._id)) {
|
||||
// I'm trying to write something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
Booking.findAllByUserIdAndIdApp(userId, idapp).then((bookedevent) => {
|
||||
res.send({ bookedevent });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
73
server/router/newsletter_router.js
Normal file
73
server/router/newsletter_router.js
Normal file
@@ -0,0 +1,73 @@
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const request = require('superagent');
|
||||
|
||||
const newsletter = [
|
||||
{
|
||||
name: 'Paolo',
|
||||
mailchimpInstance: 'us16',
|
||||
listUniqueId: 'e70fd8ba4c',
|
||||
mailchimpApiKey: '24d1eb0e4f21dd7c52d47214b0d62cfd-us16'
|
||||
// CLIENT ID 682712991042
|
||||
// Client Secret 69c627f5dad15f6072ac4f86f5312a6078c94f72a0902d2f4c
|
||||
},
|
||||
{
|
||||
name: 'Paolo',
|
||||
mailchimpInstance: 'us16',
|
||||
listUniqueId: 'e70fd8ba4c',
|
||||
mailchimpApiKey: '24d1eb0e4f21dd7c52d47214b0d62cfd-us16'
|
||||
// CLIENT ID 682712991042
|
||||
// Client Secret 69c627f5dad15f6072ac4f86f5312a6078c94f72a0902d2f4c
|
||||
},
|
||||
{
|
||||
name: 'AssShen',
|
||||
mailchimpInstance: 'us4',
|
||||
listUniqueId: '991c0b8321',
|
||||
mailchimpApiKey: '07dd8b0bd078ae3a79e398656c276bbd-us4'
|
||||
// CLIENT ID 682712991042
|
||||
// Client Secret 69c627f5dad15f6072ac4f86f5312a6078c94f72a0902d2f4c
|
||||
},
|
||||
{
|
||||
name: 'AssociazioneShen',
|
||||
mailchimpInstance: '',
|
||||
listUniqueId: '',
|
||||
mailchimpApiKey: ''
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
|
||||
idwebsite = req.body.idwebsite;
|
||||
locale = req.body.locale;
|
||||
|
||||
request
|
||||
.post('https://' + newsletter[idwebsite].mailchimpInstance + '.api.mailchimp.com/3.0/lists/' + newsletter[idwebsite].listUniqueId + '/members/')
|
||||
.set('Content-Type', 'application/json;charset=utf-8')
|
||||
.set('Authorization', 'Basic ' + new Buffer('any:' + newsletter[idwebsite].mailchimpApiKey).toString('base64'))
|
||||
.send({
|
||||
'email_address': req.body.email,
|
||||
'status': server_constants.RIS_SUBSCRIBED_STR,
|
||||
'merge_fields': {
|
||||
'FNAME': req.body.firstName,
|
||||
'LNAME': req.body.lastName
|
||||
}
|
||||
})
|
||||
.end(function (err, response) {
|
||||
console.log("STAT", response.status);
|
||||
|
||||
if (response.status < 300 || (response.status === 400 && response.body.title === "Member Exists")) {
|
||||
if (response.status === 400 && response.body.title === "Member Exists")
|
||||
res.send({result: server_constants.RIS_SUBSCRIBED_ALREADYEXIST, msg: server_constants.RIS_SUBSCRIBED_MSG_ALREADYEXIST[locale]});
|
||||
else
|
||||
res.send({result: server_constants.RIS_SUBSCRIBED_OK, msg: server_constants.RIS_SUBSCRIBED_MSG[locale]});
|
||||
} else {
|
||||
res.send({result: server_constants.RIS_SUBSCRIBED_ERR, msg: server_constants.RIS_SUBSCRIBED_MSG_FAILED[locale]});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -3,13 +3,13 @@ const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
var { authenticate } = require('../middleware/authenticate');
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
// var mongoose = require('mongoose');
|
||||
|
||||
var { Project } = require('../models/project');
|
||||
const { Project } = require('../models/project');
|
||||
const { Todo } = require('./../models/todo');
|
||||
|
||||
const _ = require('lodash');
|
||||
@@ -31,11 +31,8 @@ router.post('/', authenticate, (req, res) => {
|
||||
return res.status(400).send({ code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC });
|
||||
}
|
||||
|
||||
if (String(project.userId) !== String(req.user._id)) {
|
||||
// I'm trying to write something not mine!
|
||||
tools.mylog('project.userId = ', project.userId, 'req.user._id', req.user._id);
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
const check = tools.checkUserOk(project.userId, req.user._id);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
tools.mylog('PROJECT POST :', project.descr, project._id);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ function existSubScribe(userId, access, browser) {
|
||||
// POST /users
|
||||
router.post('/', (req, res) => {
|
||||
tools.mylog("POST /users");
|
||||
var body = _.pick(req.body, ['email', 'password', 'username', 'idapp', 'keyappid', 'lang']);
|
||||
var body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang']);
|
||||
var user = new User(body);
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
||||
@@ -63,7 +63,7 @@ router.post('/', (req, res) => {
|
||||
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
||||
console.log('res.locale', res.locale);
|
||||
if (!tools.testing()) {
|
||||
sendemail.sendEmail_Registration(user.lang, user.email, user.username, user.idapp, user.linkreg);
|
||||
sendemail.sendEmail_Registration(user.lang, user.email, user, user.idapp, user.linkreg);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -114,6 +114,8 @@ router.post('/login', (req, res) => {
|
||||
return user.generateAuthToken(req).then((token) => {
|
||||
var usertosend = User();
|
||||
usertosend.username = user.username;
|
||||
usertosend.name = user.name;
|
||||
usertosend.surname = user.surname;
|
||||
usertosend.email = user.email;
|
||||
usertosend.userId = user._id.toHexString();
|
||||
usertosend.verified_email = user.verified_email;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const tools = require('./tools/general');
|
||||
|
||||
require('./config/config');
|
||||
|
||||
const Email = require('email-templates');
|
||||
|
||||
var i18n = require("i18n");
|
||||
@@ -29,7 +31,7 @@ function checkifSendEmail() {
|
||||
module.exports = {
|
||||
sendEmail_base: function (template, username, to, mylocalsconf) {
|
||||
|
||||
console.log("check EMAIL :" + checkifSendEmail());
|
||||
// console.log("check EMAIL :" + checkifSendEmail());
|
||||
|
||||
const email = new Email({
|
||||
message: {
|
||||
@@ -57,6 +59,7 @@ module.exports = {
|
||||
.then(console.log)
|
||||
.catch(console.error);
|
||||
},
|
||||
|
||||
sendEmail_Normale: function (to, subject, html) {
|
||||
|
||||
// setup e-mail data with unicode symbols
|
||||
@@ -93,11 +96,7 @@ module.exports = {
|
||||
return ""
|
||||
}
|
||||
},
|
||||
getNomeAppByIdApp: function (idapp) {
|
||||
if (idapp === 1) {
|
||||
return process.env.NOME_APP1;
|
||||
}
|
||||
},
|
||||
|
||||
getlinkReg: function (idapp, idreg) {
|
||||
strlinkreg = this.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `?idapp=${idapp}&idlink=${idreg}`;
|
||||
return strlinkreg;
|
||||
@@ -110,9 +109,11 @@ module.exports = {
|
||||
|
||||
mylocalsconf = {
|
||||
locale: lang,
|
||||
nomeapp: this.getNomeAppByIdApp(idapp),
|
||||
nomeapp: tools.getNomeAppByIdApp(idapp),
|
||||
strlinkreg: this.getlinkReg(idapp, idreg),
|
||||
user: user,
|
||||
username: user.username,
|
||||
name: user.name,
|
||||
surname: user.surname,
|
||||
forgetpwd: "",
|
||||
emailto: emailto,
|
||||
};
|
||||
@@ -120,13 +121,13 @@ module.exports = {
|
||||
this.sendEmail_base('registration/' + lang, user, emailto, mylocalsconf);
|
||||
|
||||
// Send to the Admin an Email
|
||||
this.sendEmail_Normale(process.env.EMAIL_FROM, 'Nuova Registrazione: (' + user + ")", 'Effettuata una Nuova Registrazione!<br>Username:' + user + '<br></br>Email: ' + emailto +'<br>')
|
||||
this.sendEmail_base('admin/registration/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
|
||||
},
|
||||
sendEmail_RequestNewPassword: function (lang, emailto, idapp, tokenforgot) {
|
||||
|
||||
mylocalsconf = {
|
||||
locale: lang,
|
||||
nomeapp: this.getNomeAppByIdApp(idapp),
|
||||
nomeapp: tools.getNomeAppByIdApp(idapp),
|
||||
user: user,
|
||||
strlinksetpassword: this.getlinkRequestNewPassword(idapp, user, tokenforgot),
|
||||
emailto: emailto,
|
||||
@@ -135,5 +136,55 @@ module.exports = {
|
||||
this.sendEmail_base('resetpwd/' + lang, user, emailto, mylocalsconf);
|
||||
},
|
||||
|
||||
sendEmail_Booking: function (res, lang, emailto, user, idapp, recbooking) {
|
||||
|
||||
tools.mylog('sendEmail_Booking');
|
||||
tools.mylog('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp);
|
||||
|
||||
mylocalsconf = {
|
||||
locale: lang,
|
||||
nomeapp: tools.getNomeAppByIdApp(idapp),
|
||||
name: user.name,
|
||||
surname: user.surname,
|
||||
emailto: emailto,
|
||||
participants: '',
|
||||
eventtextplain: tools.removeSpecialCharForEmail(recbooking.infoevent),
|
||||
event: recbooking.infoevent,
|
||||
};
|
||||
|
||||
if (recbooking.numpeople > 1)
|
||||
mylocalsconf.participants = recbooking.numpeople.toString() + ' ' + res.__("partecipanti");
|
||||
|
||||
this.sendEmail_base('booking/makebooking/' + lang, user, emailto, mylocalsconf);
|
||||
|
||||
// Send Email also to the Admin
|
||||
this.sendEmail_base('admin/makebooking/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
|
||||
},
|
||||
|
||||
sendEmail_CancelBooking: function (res, lang, emailto, user, idapp, recbooking) {
|
||||
|
||||
tools.mylog('sendEmail_CancelBooking');
|
||||
|
||||
mylocalsconf = {
|
||||
locale: lang,
|
||||
nomeapp: tools.getNomeAppByIdApp(idapp),
|
||||
name: user.name,
|
||||
surname: user.surname,
|
||||
emailto: emailto,
|
||||
event: recbooking.infoevent,
|
||||
participants: '',
|
||||
eventtextplain: tools.removeSpecialCharForEmail(recbooking.infoevent),
|
||||
};
|
||||
|
||||
if (recbooking.numpeople > 1)
|
||||
mylocalsconf.participants = recbooking.numpeople.toString() + ' ' + res.__("partecipanti");
|
||||
|
||||
this.sendEmail_base('booking/cancelbooking/' + lang, user, emailto, mylocalsconf);
|
||||
|
||||
// Send Email also to the Admin
|
||||
this.sendEmail_base('admin/cancelbooking/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -29,10 +29,14 @@ require('./models/project');
|
||||
require('./models/user');
|
||||
require('./models/subscribers');
|
||||
require('./models/cfgserver');
|
||||
require('./models/booking');
|
||||
const mysql_func = require('./mysql/mysql_func');
|
||||
|
||||
|
||||
const index_router = require('./router/index_router');
|
||||
const push_router = require('./router/push_router');
|
||||
const newsletter_router = require('./router/newsletter_router');
|
||||
const booking_router = require('./router/booking_router');
|
||||
const subscribe_router = require('./router/subscribe_router');
|
||||
const email_router = require('./router/email_router');
|
||||
const todos_router = require('./router/todos_router');
|
||||
@@ -55,6 +59,8 @@ var mongoose = require('mongoose');
|
||||
const cfgserver = mongoose.model('cfgserver');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
app.use(express.static('views'));
|
||||
|
||||
// app.use(express.static(path.join(__dirname, 'client')));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
@@ -83,6 +89,8 @@ app.use(i18n.init);
|
||||
app.use('/', index_router);
|
||||
app.use('/subscribe', subscribe_router);
|
||||
app.use('/push', push_router);
|
||||
app.use('/signup_news', newsletter_router);
|
||||
app.use('/booking', booking_router);
|
||||
app.use('/email', email_router);
|
||||
app.use('/todos', todos_router);
|
||||
app.use('/projects', projects_router);
|
||||
@@ -113,6 +121,15 @@ if (app.get('env') === 'development') {
|
||||
});
|
||||
}
|
||||
|
||||
// *** DB CONNECTIONS ***
|
||||
// mysql_func.mySqlConn_Shen.connect((err) => {
|
||||
// if (!err)
|
||||
// console.log('DB connection to Shen Database succeded.');
|
||||
// else
|
||||
// console.log('DB connection to Shen Database FAILED \n Error: ' + JSON.stringify(err, undefined, 2));
|
||||
// });
|
||||
|
||||
|
||||
if ((process.env.NODE_ENV === 'production') || (process.env.NODE_ENV === 'test')) {
|
||||
var httpsServer = https.createServer(credentials, app);
|
||||
console.log("httpsServer: port ", port);
|
||||
@@ -127,6 +144,22 @@ if (process.env.PROD !== 1) {
|
||||
testmsgwebpush();
|
||||
}
|
||||
|
||||
// ----------------- MAILCHIMP -----
|
||||
const querystring = require('querystring');
|
||||
const mailchimpClientId = 'xxxxxxxxxxxxxxxx';
|
||||
|
||||
app.get('/mailchimp/auth/authorize', function(req, res) {
|
||||
res.redirect('https://login.mailchimp.com/oauth2/authorize?' +
|
||||
querystring.stringify({
|
||||
'response_type': 'code',
|
||||
'client_id': mailchimpClientId,
|
||||
'redirect_uri': 'http://127.0.0.1:3000/mailchimp/auth/callback'
|
||||
}));
|
||||
});
|
||||
|
||||
// -----------------
|
||||
|
||||
|
||||
startserv();
|
||||
|
||||
|
||||
@@ -155,7 +188,9 @@ function startserv() {
|
||||
|
||||
function testmsgwebpush() {
|
||||
var { User } = require('./models/user');
|
||||
// const tools = require('./tools/general');
|
||||
|
||||
// console.log('nomeapp 1: ' , tools.getNomeAppByIdApp(1));
|
||||
// console.log('nomeapp 2: ' , tools.getNomeAppByIdApp(2));
|
||||
|
||||
User.findOne().then((user) => {
|
||||
if (user !== null) {
|
||||
@@ -168,7 +203,9 @@ function testmsgwebpush() {
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ const users = [{
|
||||
idapp: '1',
|
||||
email: 'paoloa.rena77@gmail.com',
|
||||
username: 'paoloar77B',
|
||||
name: 'Paolo',
|
||||
surname: 'Arena',
|
||||
password: mypwdcrypted,
|
||||
tokens: [{
|
||||
access: 'auth',
|
||||
@@ -50,6 +52,8 @@ const users = [{
|
||||
lang: 'it',
|
||||
idapp: '1',
|
||||
email: 'pa@com',
|
||||
name: 'Paolo2',
|
||||
surname: 'Arena2',
|
||||
password: mypwdcrypted,
|
||||
username: 'paoloar77C',
|
||||
tokens: [{
|
||||
@@ -64,7 +68,9 @@ const users = [{
|
||||
idapp: '1',
|
||||
email: 'pao.loarena77@gmail.com',
|
||||
password: mypwdcrypted,
|
||||
username: 'paoloar77A'
|
||||
username: 'paoloar77A',
|
||||
name: 'Paolo3',
|
||||
surname: 'Arena3',
|
||||
}];
|
||||
|
||||
const userjson = JSON.stringify(users[0]);
|
||||
|
||||
@@ -16,6 +16,8 @@ let jsonUser1 = {
|
||||
email: "paolo.arena77@gmail.com",
|
||||
password: "$2a$12$hTv40mdq.x35Up7HQ9faae1JgHrohcvp45vt8eMkGhQv/Zv.8.MIG",
|
||||
username: "paoloar77",
|
||||
name: 'Paolo',
|
||||
surname: 'Arena',
|
||||
idapp: "1",
|
||||
lang: "it",
|
||||
keyappid: "KKPPAA5KJK435J3KSS9F9D8S9F8SD98F9SDF"
|
||||
@@ -46,6 +48,8 @@ if (testsingolo) {
|
||||
// .set('x-auth', users[0].tokens[0].token)
|
||||
.send({
|
||||
username: users[0].username,
|
||||
name: users[0].name,
|
||||
surname: users[0].surname,
|
||||
password: mypwdchiaro,
|
||||
idapp: users[0].idapp,
|
||||
keyappid: users[0].keyappid,
|
||||
@@ -86,6 +90,8 @@ if (testsingolo) {
|
||||
expect(res.body._id).toExist();
|
||||
expect(res.body.email).toBe(users[IndexUserToCreate].email);
|
||||
expect(res.body.username).toBe(users[IndexUserToCreate].username);
|
||||
expect(res.body.name).toBe(users[IndexUserToCreate].name);
|
||||
expect(res.body.surname).toBe(users[IndexUserToCreate].surname);
|
||||
})
|
||||
.end((err) => {
|
||||
if (err) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var os = require("os");
|
||||
|
||||
require('../config/config');
|
||||
|
||||
require('../models/subscribers');
|
||||
|
||||
var Url = require('url-parse');
|
||||
@@ -70,6 +72,14 @@ module.exports = {
|
||||
, 'privacyread', 'privacywrite']
|
||||
},
|
||||
|
||||
allfieldBooking: function () {
|
||||
return ['idapp', 'userId', 'id_bookedevent', 'numpeople', 'msgbooking', 'infoevent', 'datebooked', 'booked']
|
||||
},
|
||||
|
||||
allfieldBookingChange: function () {
|
||||
return ['numpeople', 'msgbooking', 'infoevent', 'datebooked', 'booked']
|
||||
},
|
||||
|
||||
allfieldProjectWithId: function () {
|
||||
return ['_id', ...this.allfieldProject()]
|
||||
},
|
||||
@@ -247,7 +257,55 @@ module.exports = {
|
||||
// console.log('DOPO sortedList', sortedList);
|
||||
|
||||
return sortedList;
|
||||
},
|
||||
|
||||
checkUserOk(userpassed, userauth) {
|
||||
this.mylog('checkUserOk', userpassed, userauth);
|
||||
if (String(userpassed) !== String(userauth)) {
|
||||
// I'm trying to write something not mine!
|
||||
this.mylog('userId = ', userpassed.userId, 'req.user._id', userauth);
|
||||
return { exit: true, ret: res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER }) }
|
||||
} else {
|
||||
return { exit: false, ret: false }
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
convertHTMLtoText(myhtml) {
|
||||
let msg = myhtml;
|
||||
msg = msg.replace('"', '"');
|
||||
msg = msg.replace('>', '>');
|
||||
msg = msg.replace('<', '<');
|
||||
msg = msg.replace('&', '&');
|
||||
msg = msg.replace('<br>', '\n');
|
||||
|
||||
return msg
|
||||
},
|
||||
|
||||
removeSpecialCharForEmail(myhtml) {
|
||||
let msg = myhtml;
|
||||
msg = msg.replace(/"/g, '\'');
|
||||
|
||||
return msg
|
||||
},
|
||||
|
||||
getNomeAppByIdApp: function (idapp) {
|
||||
|
||||
const myapp = MYAPPS.find(item => item.idapp === idapp);
|
||||
if (myapp)
|
||||
return myapp.name;
|
||||
else
|
||||
return '';
|
||||
},
|
||||
|
||||
getAdminEmailByIdApp: function (idapp) {
|
||||
const myapp = MYAPPS.find((item) => item.idapp === idapp);
|
||||
if (myapp)
|
||||
return myapp.adminemail;
|
||||
else
|
||||
return '';
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,34 @@ module.exports = Object.freeze({
|
||||
|
||||
RIS_CODE_HTTP_INVALID_TOKEN: 403,
|
||||
|
||||
RIS_SUBSCRIBED_OK: 1,
|
||||
RIS_SUBSCRIBED_ALREADYEXIST: 2,
|
||||
RIS_SUBSCRIBED_ERR: -1,
|
||||
RIS_SUBSCRIBED_STR: 'subscribed',
|
||||
|
||||
|
||||
RIS_SUBSCRIBED_MSG: {
|
||||
enUs: 'Subscription to the Newsletter Confirmed!',
|
||||
es: 'Suscripción al boletín confirmado!',
|
||||
it: 'Sottoscrizione alla Newsletter Confermata!',
|
||||
fr: 'Inscription à la newsletter confirmée!',
|
||||
de: 'Anmeldung zum Newsletter bestätigt!'
|
||||
} ,
|
||||
RIS_SUBSCRIBED_MSG_ALREADYEXIST: {
|
||||
enUs: 'Subscription already made!',
|
||||
es: 'Suscripción ya realizada!',
|
||||
it: 'Sottoscrizione già effettuata!',
|
||||
fr: 'Abonnement déjà fait!',
|
||||
de: 'Abonnement bereits gemacht!'
|
||||
} ,
|
||||
RIS_SUBSCRIBED_MSG_FAILED: {
|
||||
enUs: 'Sign Up Failed :(',
|
||||
es: 'Suscripción al boletín fallido',
|
||||
it: 'Sottoscrizione alla Newsletter Fallita',
|
||||
fr: 'Abonnement à la newsletter en échec',
|
||||
de: 'Abonnement des fehlgeschlagenen Newsletters',
|
||||
} ,
|
||||
|
||||
|
||||
LIST_END: '10000000',
|
||||
LIST_START: null,
|
||||
|
||||
10
server/views/integrated-mailchimp.html
Normal file
10
server/views/integrated-mailchimp.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Integrate MailChimp</title>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.1.25/spectre.min.css" rel="stylesheet" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<a class="btn btn-primary" href="/mailchimp/auth/authorize">Connect with MailChimp</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user