diff --git a/emails/admin/iscrizione_arcadei/it/html.pug b/emails/admin/iscrizione_arcadei/it/html.pug new file mode 100755 index 0000000..d8a1e47 --- /dev/null +++ b/emails/admin/iscrizione_arcadei/it/html.pug @@ -0,0 +1,71 @@ +p #{username} (#{name} #{surname}) si è appena Iscritto ad Arcadei Foundation su #{nomeapp} +p Con i seguenti dati di accesso: +span Nome:  + strong #{iscritto.name}
+span Cognome:  + strong #{iscritto.surname}
+span Email:  + strong #{iscritto.email}
+span Email Secondaria:  + strong #{iscritto.email2}
+span Indirizzo di Residenza:  + strong #{iscritto.residency_address}
+span Città di Residenza:  + strong #{iscritto.residency_city}
+span Provincia:  + strong #{iscritto.residency_province}
+span CAP:  + strong #{iscritto.residency_zipcode}
+span Nazione:  + strong #{iscritto.residency_country}
+span Data di Nascita:  + strong #{data_nascita}
+span Città di Nascita:  + strong #{iscritto.born_city}
+span Provincia di Nascita:  + strong #{iscritto.born_province}
+span Paese di Nascita:  + strong #{iscritto.born_country}
+span Telefono:  + strong #{iscritto.cell_phone}
+span Telefono2:  + strong #{iscritto.cell_phone2}
+span Tipo di Documento :  + strong #{iscritto.doctype}
+span Numero Documento :  + strong #{iscritto.documentnumber}
+span Metodo di Pagamento :  + strong #{iscritto.metodo_pagamento}
+span Quota scelta da versare :  + strong #{iscritto.quota_versata}
+span Scrivi altre eventuali informazioni o comunicazioni:  + strong #{iscritto.altre_comunicazioni}
+span Categorie d'Interesse :  + strong #{iscritto.categorie_interesse}
+p
Saluti + +style(type="text/css"). + html, body { + padding: 0; + margin: 0; + } + p { + font-size: 1rem; + } + + .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/iscrizione_arcadei/it/subject.pug b/emails/admin/iscrizione_arcadei/it/subject.pug new file mode 100755 index 0000000..13b99bf --- /dev/null +++ b/emails/admin/iscrizione_arcadei/it/subject.pug @@ -0,0 +1 @@ +=`Nuova Iscrizione Arcadei di ${name} ${surname} (${emailto}) su ${nomeapp}` diff --git a/src/server/models/iscrittiArcadei.js b/src/server/models/iscrittiArcadei.js new file mode 100755 index 0000000..5d37dc5 --- /dev/null +++ b/src/server/models/iscrittiArcadei.js @@ -0,0 +1,198 @@ +const mongoose = require('mongoose').set('debug', false); +const Schema = mongoose.Schema; + +const tools = require('../tools/general'); + +mongoose.Promise = global.Promise; +mongoose.level = 'F'; + +// Resolving error Unknown modifier: $pushAll +mongoose.plugin(schema => { + schema.options.usePushEach = true; +}); + +const IscrittiArcadeiSchema = new Schema({ + idapp: { + type: String, + }, + userId: { + type: String, + }, + numTesseraInterna: { + type: Number, + default: 0, + }, + name: { + type: String, + trim: true, + }, + surname: { + type: String, + trim: true, + }, + email: { + type: String, + trim: true, + }, + email2: { + type: String, + trim: true, + }, + residency_address: { + type: String, + }, + residency_city: { + type: String, + trim: true, + }, + residency_province: { + type: String, + trim: true, + }, + residency_country: { + type: String, + trim: true, + }, + residency_zipcode: { + type: String, + trim: true, + }, + dateofbirth: { + type: Date, + }, + born_city: { + type: String, + trim: true, + }, + born_province: { + type: String, + trim: true, + }, + born_country: { + type: String, + trim: true, + }, + cell_phone: { + type: String, + }, + cell_phone2: { + type: String, + }, + newsletter_on: { + type: Boolean, + }, + terms: { + type: Boolean, + }, + metodo_pagamento: { + type: Number, + }, + doctype: { + type: String, + }, + documentnumber: { + type: String, + }, + ha_pagato: { + type: Boolean, + }, + iscrizione_compilata: { + type: Boolean, + }, + dateofreg: { + type: Date, + }, + dateofapproved: { + type: Date, + }, + codiceArcadei: { + type: String, + }, + annoTesseramento: { + type: Number, + }, + motivazioni: { + type: String, + }, + categorie_interesse: [ + { + type: Number, + }], + altre_comunicazioni: { + type: String, + }, + come_ci_hai_conosciuto: { + type: String, + }, + note: { + type: String, + }, + quota_versata: { + type: Number, + }, + +}); + +IscrittiArcadeiSchema.pre('save', async function(next) { + if (this.isNew) { + const myrec = await IscrittiArcadei.findOne().limit(1).sort({numTesseraInterna: -1}); + if (!!myrec) { + this.numTesseraInterna = myrec._doc.numTesseraInterna + 1; + } else { + this.numTesseraInterna = 0; + } + } + + next(); +}); + +var IscrittiArcadei = module.exports = mongoose.model('IscrittiArcadei', IscrittiArcadeiSchema); + +module.exports.getFieldsForSearch = function() { + return [ + {field: 'name', type: tools.FieldType.string}, + {field: 'surname', type: tools.FieldType.string}, + {field: 'email', type: tools.FieldType.string}]; +}; + +module.exports.executeQueryTable = function(idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); + return tools.executeQueryTable(this, idapp, params); +}; + +module.exports.getLastRec = async function(idapp) { + const lastrec = await IscrittiArcadei.find({idapp}).sort({dateofreg: -1}).limit(1); + if (!!lastrec) { + return lastrec[0]; + } else { + return null; + } +}; + +module.exports.getNameSurnameByEmail = async function(idapp, email) { + return await IscrittiArcadei.findOne({ + idapp, email, + }, {name: 1, surname: 1}).then((rec) => { + return (!!rec) ? `${rec.name} ${rec.surname}` : ''; + }).catch((e) => { + console.error('getNameSurnameByUsername', e); + }); +}; + +module.exports.findByEmail = function(idapp, email) { + + return IscrittiArcadei.findOne({ + 'idapp': idapp, + 'email': email, + $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + }); +}; + +module.exports.findAllIdApp = async function(idapp) { + + const myfind = {idapp}; + + return await IscrittiArcadei.find(myfind, (err, arrrec) => { + return arrrec; + }); +}; diff --git a/src/server/models/myelem.js b/src/server/models/myelem.js index 99eedb6..13677fe 100755 --- a/src/server/models/myelem.js +++ b/src/server/models/myelem.js @@ -17,7 +17,7 @@ const MyElemSchema = new Schema({ type: String, }, type: { - type: String, + type: Number, }, title: { type: String, @@ -25,6 +25,24 @@ const MyElemSchema = new Schema({ container: { type: String, }, + container2: { + type: String, + }, + container3: { + type: String, + }, + number: { + type: String, + }, + imgback: { + type: String, + }, + ratio: { + type: String, + }, + containerHtml: { + type: String, + }, size: { type: String, }, @@ -35,6 +53,18 @@ const MyElemSchema = new Schema({ height: { type: Number, }, + heightimg: { + type: Number, + }, + widthimg: { + type: Number, + }, + width: { + type: Number, + }, + link: { + type: String, + }, onlyif_logged: { type: Boolean, }, @@ -47,6 +77,25 @@ const MyElemSchema = new Schema({ class: { type: String, }, + styleadd: { + type: String, + }, + list: [ + { + imagefile: { + type: String + }, + order: { + type: Number + }, + alt: { + type: String + }, + description: { + type: String + } + } + ], }); MyElemSchema.statics.getFieldsForSearch = function () { @@ -64,9 +113,7 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) { const myfind = { idapp }; - return await MyElem.find(myfind, (err, arrrec) => { - return arrrec - }); + return await MyElem.find(myfind).sort({ order: 1 }); }; const MyElem = mongoose.model('MyElem', MyElemSchema); diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 10ed48c..14da898 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -39,6 +39,7 @@ const {MyEvent} = require('../models/myevent'); const {Contribtype} = require('../models/contribtype'); const {PaymentType} = require('../models/paymenttype'); const {Discipline} = require('../models/discipline'); +const {MyElem} = require('../models/myelem'); const {Skill} = require('../models/skill'); const {Good} = require('../models/good'); const {StatusSkill} = require('../models/statusSkill'); diff --git a/src/server/router/iscrittiArcadei_router.js b/src/server/router/iscrittiArcadei_router.js new file mode 100755 index 0000000..b746d66 --- /dev/null +++ b/src/server/router/iscrittiArcadei_router.js @@ -0,0 +1,82 @@ +const express = require('express'); +const router = express.Router(); + +const IscrittiArcadei = require('../models/iscrittiArcadei'); +const { ObjectID } = require('mongodb'); + +const sendemail = require('../sendemail'); + +const { Settings } = require('../models/settings'); + +const tools = require('../tools/general'); +const shared_consts = require('../tools/shared_nodejs'); + +const server_constants = require('../tools/server_constants'); + +const telegrambot = require('../telegram/telegrambot'); + +const _ = require('lodash'); + +const { authenticate } = require('../middleware/authenticate'); + +const mongoose = require('mongoose').set('debug', false) + + +// POST /iscritti_arcadei +router.post('/', async (req, res) => { + tools.mylog("POST /iscritti_arcadei"); + const body = req.body; + body.email = body.email.toLowerCase(); + + const iscritti = new IscrittiArcadei(body); + iscritti.ipaddr = tools.getiPAddressUser(req); + iscritti.lang = req.locale; + + // tools.mylog("LANG PASSATO = " + iscritti.lang, "IDAPP", iscritti.idapp); + + if (!tools.isAlphaNumeric(body.name)) { + await tools.snooze(5000); + res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_NOT_VALID, msg: '' }); + return 1; + } + + if (tools.blockwords(body.username) || tools.blockwords(body.email) || tools.blockwords(body.name) || tools.blockwords(body.surname)) { + // tools.writeIPToBan(iscritti.ipaddr + ': [' + iscritti.username + '] ' + iscritti.name + ' ' + iscritti.surname); + await tools.snooze(5000); + return res.status(404).send(); + } + + iscritti.dateofreg = new Date(); + + // Controlla se anche l'ultimo record era dallo stesso IP: + const lastrec = await IscrittiArcadei.getLastRec(body.idapp); + if (!!lastrec) { + if (process.env.LOCALE !== "1") { + if (lastrec.ipaddr === iscritti.ipaddr) { + // Se l'ha fatto troppo ravvicinato + if (lastrec.date_reg) { + let ris = tools.isdiffSecDateLess(lastrec.date_reg, 120); + if (ris) { + tools.writeIPToBan(iscritti.ipaddr + ': ' + tools.getNomeCognomeEUserNameByUser(iscritti)); + await tools.snooze(10000); + res.status(400).send({ code: server_constants.RIS_CODE_BANIP, msg: '' }); + return 1; + } + } + } + } + } + + return iscritti.save() + .then(async () => { + await sendemail.sendEmail_IscrizioneArcadei(iscritti.lang, iscritti.email, iscritti, iscritti.idapp); + // } + return res.status(200).send(); + }).catch((e) => { + console.error(e.message); + res.status(400).send(e); + }) +}); + + +module.exports = router; diff --git a/src/server/sendemail.js b/src/server/sendemail.js index 4f3b0e8..cea3e60 100755 --- a/src/server/sendemail.js +++ b/src/server/sendemail.js @@ -238,7 +238,7 @@ module.exports = { // Send to the Admin an Email this.sendEmail_base('admin/iscrizione_conacreis/' + tools.LANGADMIN, tools.getAdminEmailByIdApp(idapp), mylocalsconf, ''); - await telegrambot.notifyIscrizioneToTelegram(telegrambot.phase.ISCRIZIONE_CONACREIS, mylocalsconf); + await telegrambot.notifyIscrizioneToTelegram(telegrambot.phase.ISCRIZIONE_CONACREIS, mylocalsconf, 'MSG_ISCRITTO_CONACREIS'); tools.sendNotifToAdmin('Iscrizione Conacreis : ' + mylocalsconf.name + ' ' + mylocalsconf.surname + ' (' + mylocalsconf.username + ')'); @@ -247,6 +247,38 @@ module.exports = { } }, + sendEmail_IscrizioneArcadei: async function (lang, emailto, iscritto, idapp) { + + // console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp)); + + let mylocalsconf = { + idapp, + dataemail: await this.getdataemail(idapp), + locale: lang, + nomeapp: tools.getNomeAppByIdApp(idapp), + strlinksito: tools.getHostByIdApp(idapp), + emailto: emailto, + iscritto, + metodo_pagamento: tools.getPaymentTypesById(iscritto.metodo_pagamento), + data_nascita: tools.getstrDate_DD_MM_YYYY(iscritto.dateofbirth) + }; + + mylocalsconf = this.setParamsForTemplate(iscritto, mylocalsconf); + + this.sendEmail_base('iscrizione_arcadei/' + lang, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp)); + + // Send to the Admin an Email + this.sendEmail_base('admin/iscrizione_arcadei/' + tools.LANGADMIN, tools.getAdminEmailByIdApp(idapp), mylocalsconf, ''); + + await telegrambot.notifyIscrizioneToTelegram(telegrambot.phase.ISCRIZIONE_ARCADEI, mylocalsconf, 'MSG_ISCRITTO_ARCADEI'); + + tools.sendNotifToAdmin('Iscrizione Arcadei : ' + mylocalsconf.name + ' ' + mylocalsconf.surname + ' (' + mylocalsconf.username + ')'); + + if (tools.isManagAndAdminDifferent(idapp)) { + this.sendEmail_base('admin/iscrizione_arcadei/' + tools.LANGADMIN, tools.getManagerEmailByIdApp(idapp), mylocalsconf, ''); + } + }, + sendEmail_RequestNewPassword: async function (lang, user, emailto, idapp, tokenforgot) { let mylocalsconf = { diff --git a/src/server/server.js b/src/server/server.js index 8110430..8ec88a6 100755 --- a/src/server/server.js +++ b/src/server/server.js @@ -124,6 +124,7 @@ myLoad().then(ris => { const mygroups_router = require('./router/mygroups_router'); const circuits_router = require('./router/circuits_router'); const iscrittiConacreis_router = require('./router/iscrittiConacreis_router'); + const iscrittiArcadei_router = require('./router/iscrittiArcadei_router'); const site_router = require('./router/site_router'); const admin_router = require('./router/admin_router'); const products_router = require('./router/products_router'); @@ -184,6 +185,7 @@ myLoad().then(ris => { app.use('/mygroup', mygroups_router); app.use('/circuit', circuits_router); app.use('/iscritti_conacreis', iscrittiConacreis_router); + app.use('/iscritti_arcadei', iscrittiArcadei_router); app.use('/report', report_router); app.use('/site', site_router); app.use('/admin', admin_router); diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 4381b0a..ff1e1a6 100755 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -505,6 +505,7 @@ const txt = { '🚫 Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s.
Contattalo per farti abilitare !', MSG_APORTADOR_NOT_CONFIRMED: emo.EXCLAMATION_MARK + '🚫 %s Non è stato Abilitato !', MSG_ISCRITTO_CONACREIS: emo.FIRE + '[%] Si è appena Iscritto al Conacreis "%s"', + MSG_ISCRITTO_ARCADEI: emo.FIRE + '[%] Si è appena Iscritto ad Arcadei "%s"', MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !', MSG_MSG_TOSENT: emoji.get('envelope') + ' Messaggi da Inviare', MSG_MSG_INCORSO: emoji.get('envelope') + ' messaggi in corso... Inviati attualmente', @@ -696,6 +697,7 @@ const MyTelegramBot = { phase: { REGISTRATION: 1, ISCRIZIONE_CONACREIS: 2, + ISCRIZIONE_ARCADEI: 4, }, getAppTelegram: function() { @@ -805,13 +807,13 @@ const MyTelegramBot = { }, - notifyIscrizioneToTelegram: async function(phase, mylocalsconf) { + notifyIscrizioneToTelegram: async function(phase, mylocalsconf, msg) { let langdest = mylocalsconf.iscritto.lang; let NameFrom = `${mylocalsconf.iscritto.name} ${mylocalsconf.iscritto.surname}`; let nomeapp = tools.getHostByIdApp(mylocalsconf.idapp); - let text = printf(getstr(langdest, 'MSG_ISCRITTO_CONACREIS'), nomeapp, NameFrom); + let text = printf(getstr(langdest, msg), nomeapp, NameFrom); let addtext = ''; diff --git a/src/server/tools/general.js b/src/server/tools/general.js index bf9f0ed..1471e6c 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -1211,7 +1211,7 @@ module.exports = { } catch (e) { console.error('sendNotificationByCircuit: ', e); - return {ris: null, inviato: false} ; + return {ris: null, inviato: false}; } }, @@ -1317,20 +1317,24 @@ module.exports = { }, ConvertHTMLToPlainText(strHTML) { - return strHTML.replace(/<[^>]+>/g, ''); + if (strHTML) + return strHTML.replace(/<[^>]+>/g, ''); + return ''; }, convertHTMLtoText(myhtml) { let msg = myhtml; - msg = msg.replace('"', '"'); - msg = msg.replace(//g, ''); - msg = msg.replace(/<\/strong>/g, ''); - msg = msg.replace(//g, ''); - msg = msg.replace(/<\/em>/g, ''); - msg = msg.replace('>', '>'); - msg = msg.replace('<', '<'); - msg = msg.replace('&', '&'); - msg = msg.replace('
', '\n'); + if (msg) { + msg = msg.replace('"', '"'); + msg = msg.replace(//g, ''); + msg = msg.replace(/<\/strong>/g, ''); + msg = msg.replace(//g, ''); + msg = msg.replace(/<\/em>/g, ''); + msg = msg.replace('>', '>'); + msg = msg.replace('<', '<'); + msg = msg.replace('&', '&'); + msg = msg.replace('
', '\n'); + } return msg; }, diff --git a/src/server/tools/globalTables.js b/src/server/tools/globalTables.js index 5b29066..a928886 100755 --- a/src/server/tools/globalTables.js +++ b/src/server/tools/globalTables.js @@ -63,6 +63,7 @@ const Department = require('../models/department'); const ShareWithUs = require('../models/sharewithus'); const Site = require('../models/site'); const IscrittiConacreis = require('../models/iscrittiConacreis'); +const IscrittiArcadei = require('../models/iscrittiArcadei'); const Group = require('../models/group'); const {Todo} = require('../models/todo'); const Hours = require('../models/hours'); @@ -105,6 +106,8 @@ module.exports = { mytable = Site; else if (tablename === 'iscritticonacreis') mytable = IscrittiConacreis; + else if (tablename === 'iscrittiarcadei') + mytable = IscrittiArcadei; else if (tablename === 'groups') mytable = Group; else if (tablename === 'todos')