diff --git a/emails/admin/cancelbooking/it/html.pug b/emails/admin/cancelbooking/it/html.pug
new file mode 100644
index 0000000..69e4889
--- /dev/null
+++ b/emails/admin/cancelbooking/it/html.pug
@@ -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;
+
+ }
diff --git a/emails/admin/cancelbooking/it/subject.pug b/emails/admin/cancelbooking/it/subject.pug
new file mode 100644
index 0000000..054a131
--- /dev/null
+++ b/emails/admin/cancelbooking/it/subject.pug
@@ -0,0 +1 @@
+=`${name} ${surname} ha cancellato la prenotazione all'evento ${eventtextplain}`
diff --git a/emails/admin/makebookingadmin/it/html.pug b/emails/admin/makebookingadmin/it/html.pug
new file mode 100644
index 0000000..8c52df2
--- /dev/null
+++ b/emails/admin/makebookingadmin/it/html.pug
@@ -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;
+
+ }
diff --git a/emails/admin/makebookingadmin/it/subject.pug b/emails/admin/makebookingadmin/it/subject.pug
new file mode 100644
index 0000000..e369492
--- /dev/null
+++ b/emails/admin/makebookingadmin/it/subject.pug
@@ -0,0 +1 @@
+=`${name} ${surname} si è prenotato per l'evento ${eventtextplain}`
diff --git a/emails/admin/registration/enUs/html.pug b/emails/admin/registration/enUs/html.pug
new file mode 100644
index 0000000..2fde1d0
--- /dev/null
+++ b/emails/admin/registration/enUs/html.pug
@@ -0,0 +1,30 @@
+p #{name} #{surname} has just registered on #{nomeapp}
+p With the following access datao:
+span Username:
+ strong #{username}
+span Email:
+ strong #{emailto}
+p
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;
+
+ }
diff --git a/emails/admin/registration/enUs/subject.pug b/emails/admin/registration/enUs/subject.pug
new file mode 100644
index 0000000..4b74e79
--- /dev/null
+++ b/emails/admin/registration/enUs/subject.pug
@@ -0,0 +1 @@
+=`New Registration of ${name} ${surname} (${username}) in ${nomeapp}`
diff --git a/emails/admin/registration/esEs/html.pug b/emails/admin/registration/esEs/html.pug
new file mode 100644
index 0000000..bf484f0
--- /dev/null
+++ b/emails/admin/registration/esEs/html.pug
@@ -0,0 +1,30 @@
+p #{name} #{surname} acaba de registrarse en #{nomeapp}
+p Con los siguientes datos de acceso:
+span Username:
+ strong #{username}
+span Email:
+ strong #{emailto}
+p
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;
+
+ }
diff --git a/emails/admin/registration/esEs/subject.pug b/emails/admin/registration/esEs/subject.pug
new file mode 100644
index 0000000..562f56d
--- /dev/null
+++ b/emails/admin/registration/esEs/subject.pug
@@ -0,0 +1 @@
+=`Nuevo registro de ${name} ${surname} (${username}) en ${nomeapp}`
diff --git a/emails/admin/registration/it/html.pug b/emails/admin/registration/it/html.pug
new file mode 100644
index 0000000..be3782a
--- /dev/null
+++ b/emails/admin/registration/it/html.pug
@@ -0,0 +1,30 @@
+p #{name} #{surname} si è appena Registrato su #{nomeapp}
+p Con i seguenti dati di accesso:
+span Username:
+ strong #{username}
+span Email:
+ strong #{emailto}
+p
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;
+
+ }
diff --git a/emails/admin/registration/it/subject.pug b/emails/admin/registration/it/subject.pug
new file mode 100644
index 0000000..cadeec5
--- /dev/null
+++ b/emails/admin/registration/it/subject.pug
@@ -0,0 +1 @@
+=`Nuova Registrazione di ${name} ${surname} (${username}) su ${nomeapp}`
diff --git a/emails/booking/cancelbooking/it/html.pug b/emails/booking/cancelbooking/it/html.pug
new file mode 100644
index 0000000..c577b12
--- /dev/null
+++ b/emails/booking/cancelbooking/it/html.pug
@@ -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;
+
+ }
diff --git a/emails/booking/cancelbooking/it/subject.pug b/emails/booking/cancelbooking/it/subject.pug
new file mode 100644
index 0000000..3170602
--- /dev/null
+++ b/emails/booking/cancelbooking/it/subject.pug
@@ -0,0 +1 @@
+=`Cancellazione prenotazione di ${eventtextplain}`
diff --git a/emails/booking/makebooking/it/html.pug b/emails/booking/makebooking/it/html.pug
new file mode 100644
index 0000000..a7fd2ce
--- /dev/null
+++ b/emails/booking/makebooking/it/html.pug
@@ -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;
+
+ }
diff --git a/emails/booking/makebooking/it/subject.pug b/emails/booking/makebooking/it/subject.pug
new file mode 100644
index 0000000..cc21bd1
--- /dev/null
+++ b/emails/booking/makebooking/it/subject.pug
@@ -0,0 +1 @@
+=`Prenotazione per l'evento ${eventtextplain}`
diff --git a/emails/registration/enUs/html.pug b/emails/registration/enUs/html.pug
index b92f093..7f17977 100644
--- a/emails/registration/enUs/html.pug
+++ b/emails/registration/enUs/html.pug
@@ -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}
+ strong #{username}
span Forgot your Password? :
strong Find it here
span Email:
diff --git a/emails/registration/esEs/html.pug b/emails/registration/esEs/html.pug
index 520e370..2ef9213 100644
--- a/emails/registration/esEs/html.pug
+++ b/emails/registration/esEs/html.pug
@@ -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}
+ strong #{username}
span ¿Olvidaste tu contraseña? :
strong Encuéntrelo aquí
span Email:
diff --git a/emails/registration/it/html.pug b/emails/registration/it/html.pug
index e394b6a..d7b1cbe 100644
--- a/emails/registration/it/html.pug
+++ b/emails/registration/it/html.pug
@@ -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}
+ strong #{username}
span hai dimenticato la Password? :
strong Trovala qui
span Email:
strong #{emailto}
p Per confermare la registrazione clicca sul bottone:
div.divbtn
- button.btn.btn-lg Verify Registration
+ button.btn.btn-lg Verifica Registrazione
p Potrai cosi' accedere al sito digitando i tuoi dati di accesso.
diff --git a/package.json b/package.json
index cdc3f9b..1cea874 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/server/config/config.js b/server/config/config.js
index ec3a42c..c8f90a6 100644
--- a/server/config/config.js
+++ b/server/config/config.js
@@ -7,12 +7,34 @@ 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';
+process.env.KEY_APP_ID = 'KKPPAA5KJK435J3KSS9F9D8S9F8SD98F9SDF';
console.log("FILE : " + file);
-require('dotenv').config({path: file});
+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: ''
+ }
+];
diff --git a/server/db/mongoose.js b/server/db/mongoose.js
index 241d404..ab17cff 100644
--- a/server/db/mongoose.js
+++ b/server/db/mongoose.js
@@ -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));
diff --git a/server/locales/en.json b/server/locales/en.json
index 712bf57..af0c29f 100644
--- a/server/locales/en.json
+++ b/server/locales/en.json
@@ -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"
+}
\ No newline at end of file
diff --git a/server/locales/es.json b/server/locales/es.json
index 965e4d1..6c555c1 100644
--- a/server/locales/es.json
+++ b/server/locales/es.json
@@ -1,4 +1,8 @@
{
- "Email Verificata!": "Email Verificada!",
- "L'Email è già stata Verificata": "El email ya ha sido verificado"
+ "L'Email è già stata Verificata": "El email ya ha sido verificado",
+ "Email Verificata!": "Email Verificada!",
+ "a": "a",
+ "Nuova Registrazione": "Nuevo Registro",
+ "Effettuata una Nuova Registrazione": "Se ha realizado un nuevo registro"
+ "partecipanti": "participantes"
}
diff --git a/server/locales/it.json b/server/locales/it.json
index 98aabae..c9d2b83 100644
--- a/server/locales/it.json
+++ b/server/locales/it.json
@@ -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"
}
diff --git a/server/models/booking.js b/server/models/booking.js
new file mode 100644
index 0000000..9b30c93
--- /dev/null
+++ b/server/models/booking.js
@@ -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 };
diff --git a/server/models/user.js b/server/models/user.js
index b416836..bfc99ba 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -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) {
diff --git a/server/mysql/mysql_func.js b/server/mysql/mysql_func.js
new file mode 100644
index 0000000..fe1c7bd
--- /dev/null
+++ b/server/mysql/mysql_func.js
@@ -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);
+// });
+// }
diff --git a/server/router/booking_router.js b/server/router/booking_router.js
new file mode 100644
index 0000000..5cdc0eb
--- /dev/null
+++ b/server/router/booking_router.js
@@ -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;
diff --git a/server/router/newsletter_router.js b/server/router/newsletter_router.js
new file mode 100644
index 0000000..4de22a5
--- /dev/null
+++ b/server/router/newsletter_router.js
@@ -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;
diff --git a/server/router/projects_router.js b/server/router/projects_router.js
index c575f3e..0852115 100644
--- a/server/router/projects_router.js
+++ b/server/router/projects_router.js
@@ -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);
diff --git a/server/router/users_router.js b/server/router/users_router.js
index 566555d..f32c490 100644
--- a/server/router/users_router.js
+++ b/server/router/users_router.js
@@ -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;
diff --git a/server/sendemail.js b/server/sendemail.js
index 051ec59..5c43bd7 100644
--- a/server/sendemail.js
+++ b/server/sendemail.js
@@ -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
@@ -89,15 +92,11 @@ module.exports = {
if (idapp === 1) {
let siteport = (process.env.PORT_APP1 !== "0") ? (':' + process.env.PORT_APP1) : "";
return process.env.URLBASE_APP1 + siteport;
- }else{
+ } else {
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!
Username:' + user + '
Email: ' + emailto +'
')
+ 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);
+ },
+
+
};
diff --git a/server/server.js b/server/server.js
index faacd25..3e7f6ca 100644
--- a/server/server.js
+++ b/server/server.js
@@ -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() {
}
})
}
- })
+ });
+
+
}
diff --git a/server/tests/seed/seed.js b/server/tests/seed/seed.js
index 54ea4a4..776157d 100644
--- a/server/tests/seed/seed.js
+++ b/server/tests/seed/seed.js
@@ -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]);
diff --git a/server/tests/server.test.js b/server/tests/server.test.js
index 15c5b01..d67daf2 100644
--- a/server/tests/server.test.js
+++ b/server/tests/server.test.js
@@ -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) {
diff --git a/server/tools/general.js b/server/tools/general.js
index 9b8ca7c..46947d0 100644
--- a/server/tools/general.js
+++ b/server/tools/general.js
@@ -1,5 +1,7 @@
var os = require("os");
+require('../config/config');
+
require('../models/subscribers');
var Url = require('url-parse');
@@ -67,7 +69,15 @@ module.exports = {
allfieldProject: function () {
return ['userId', 'pos', 'typeproj', 'id_main_project', 'id_parent', 'descr', 'longdescr', 'hoursplanned', 'hoursleft', 'themecolor', 'themebgcolor', 'hoursworked', 'priority', 'statusproj', 'created_at', 'modify_at',
'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'progressCalc', 'modified', 'live_url', 'test_url', 'begin_development', 'begin_test', 'totalphases', 'actualphase', 'hoursweeky_plannedtowork', 'endwork_estimate'
- , 'privacyread', 'privacywrite']
+ , 'privacyread', 'privacywrite']
+ },
+
+ allfieldBooking: function () {
+ return ['idapp', 'userId', 'id_bookedevent', 'numpeople', 'msgbooking', 'infoevent', 'datebooked', 'booked']
+ },
+
+ allfieldBookingChange: function () {
+ return ['numpeople', 'msgbooking', 'infoevent', 'datebooked', 'booked']
},
allfieldProjectWithId: function () {
@@ -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('
', '\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 '';
+ },
+
};
diff --git a/server/tools/server_constants.js b/server/tools/server_constants.js
index 01e483d..4d055bf 100644
--- a/server/tools/server_constants.js
+++ b/server/tools/server_constants.js
@@ -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,
diff --git a/server/views/integrated-mailchimp.html b/server/views/integrated-mailchimp.html
new file mode 100644
index 0000000..22e11b7
--- /dev/null
+++ b/server/views/integrated-mailchimp.html
@@ -0,0 +1,10 @@
+
+
+