diff --git a/emails/RISO/circuit_abilitato_al_fido_membro/it/html.pug b/emails/RISO/circuit_abilitato_al_fido_membro/it/html.pug
new file mode 100755
index 0000000..2078afb
--- /dev/null
+++ b/emails/RISO/circuit_abilitato_al_fido_membro/it/html.pug
@@ -0,0 +1,494 @@
+doctype html
+html(lang="it")
+ head
+ meta(charset="UTF-8")
+ meta(name="viewport" content="width=device-width, initial-scale=1.0")
+ style(type="text/css").
+ * {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ }
+
+ body {
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
+ background-color: #f5f5f5;
+ padding: 20px;
+ line-height: 1.6;
+ }
+
+ .header-logo {
+ width: 120px;
+ height: auto;
+ margin-bottom: 16px;
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+ }
+
+ .email-container {
+ max-width: 600px;
+ margin: 0 auto;
+ background: white;
+ border-radius: 12px;
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
+ overflow: hidden;
+ }
+
+ .email-header {
+ background: linear-gradient(135deg, #7cb342 0%, #558b2f 100%);
+ color: white;
+ padding: 40px 24px;
+ text-align: center;
+ }
+
+ .email-header h1 {
+ margin: 0 0 8px 0;
+ font-size: 26px;
+ font-weight: 600;
+ line-height: 1.3;
+ }
+
+ .email-header .subtitle {
+ margin: 8px 0 0 0;
+ font-size: 17px;
+ opacity: 0.95;
+ font-style: italic;
+ }
+
+ .email-body {
+ padding: 32px 24px;
+ }
+
+ .intro-text {
+ font-size: 16px;
+ color: #333;
+ margin-bottom: 20px;
+ text-align: center;
+ line-height: 1.7;
+ }
+
+ .congrats-card {
+ background: linear-gradient(135deg, #e8f5e9 0%, #f1f8f4 100%);
+ border: 2px solid #7cb342;
+ border-radius: 12px;
+ padding: 24px;
+ margin: 20px 0;
+ text-align: center;
+ }
+
+ .congrats-card .congrats-icon {
+ font-size: 48px;
+ margin-bottom: 12px;
+ }
+
+ .congrats-card h3 {
+ font-size: 22px;
+ color: #558b2f;
+ margin-bottom: 12px;
+ font-weight: 700;
+ }
+
+ .congrats-card .territory-name {
+ font-size: 20px;
+ color: #7cb342;
+ font-weight: 600;
+ margin-top: 8px;
+ }
+
+ .info-section {
+ background: #ffffff;
+ border-radius: 8px;
+ padding: 20px;
+ margin: 24px 0;
+ }
+
+ .info-section h3 {
+ font-size: 18px;
+ color: #1a1a1a;
+ margin-bottom: 16px;
+ font-weight: 600;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ }
+
+ .info-section p {
+ font-size: 15px;
+ color: #555;
+ line-height: 1.7;
+ margin-bottom: 12px;
+ }
+
+ .info-section ul {
+ margin: 12px 0;
+ padding-left: 24px;
+ }
+
+ .info-section li {
+ font-size: 15px;
+ color: #555;
+ line-height: 1.7;
+ margin-bottom: 8px;
+ }
+
+ .highlight-box {
+ background: linear-gradient(135deg, #fff8dc 0%, #fef9f3 100%);
+ border-left: 4px solid #f0ad4e;
+ border-radius: 8px;
+ padding: 20px;
+ margin: 20px 0;
+ }
+
+ .highlight-box h4 {
+ font-size: 17px;
+ color: #f0ad4e;
+ margin-bottom: 12px;
+ font-weight: 600;
+ }
+
+ .highlight-box p {
+ font-size: 15px;
+ color: #555;
+ line-height: 1.7;
+ margin-bottom: 8px;
+ }
+
+ .example-box {
+ background: #e3f2fd;
+ border-radius: 8px;
+ padding: 20px;
+ margin: 20px 0;
+ }
+
+ .example-box h4 {
+ font-size: 16px;
+ color: #1976d2;
+ margin-bottom: 12px;
+ font-weight: 600;
+ }
+
+ .example-box .transaction {
+ background: white;
+ border-radius: 6px;
+ padding: 12px;
+ margin: 8px 0;
+ font-size: 14px;
+ }
+
+ .example-box .benefit {
+ background: #c8e6c9;
+ border-radius: 6px;
+ padding: 12px;
+ margin-top: 12px;
+ font-size: 14px;
+ color: #2e7d32;
+ }
+
+ .steps-box {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 20px;
+ margin: 20px 0;
+ }
+
+ .steps-box h4 {
+ font-size: 17px;
+ color: #1a1a1a;
+ margin-bottom: 16px;
+ font-weight: 600;
+ text-align: center;
+ }
+
+ .step-item {
+ display: flex;
+ align-items: flex-start;
+ margin-bottom: 16px;
+ padding: 12px;
+ background: white;
+ border-radius: 6px;
+ }
+
+ .step-number {
+ font-size: 24px;
+ font-weight: 700;
+ color: #7cb342;
+ min-width: 40px;
+ margin-right: 12px;
+ }
+
+ .step-content h5 {
+ font-size: 16px;
+ color: #1a1a1a;
+ margin-bottom: 6px;
+ font-weight: 600;
+ }
+
+ .step-content p {
+ font-size: 14px;
+ color: #555;
+ line-height: 1.6;
+ margin: 0;
+ }
+
+ .cta-section {
+ text-align: center;
+ margin: 32px 0;
+ padding: 24px 0;
+ border-top: 2px solid #e0e0e0;
+ border-bottom: 2px solid #e0e0e0;
+ }
+
+ .cta-title {
+ font-size: 18px;
+ font-weight: 600;
+ color: #1a1a1a;
+ margin-bottom: 20px;
+ }
+
+ .cta-button {
+ display: inline-block;
+ padding: 18px 56px;
+ font-size: 20px;
+ font-weight: 700;
+ color: white;
+ background: linear-gradient(135deg, #7cb342 0%, #558b2f 100%);
+ border-radius: 50px;
+ text-decoration: none;
+ box-shadow: 0 6px 20px rgba(124, 179, 66, 0.4);
+ transition: all 0.3s ease;
+ }
+
+ .button-icon {
+ font-size: 20px;
+ margin-right: 10px;
+ vertical-align: middle;
+ }
+
+ .community-box {
+ background: linear-gradient(135deg, #e8f5e9 0%, #f1f8f4 100%);
+ border-radius: 8px;
+ padding: 20px;
+ margin: 20px 0;
+ text-align: center;
+ }
+
+ .community-box h4 {
+ font-size: 17px;
+ color: #558b2f;
+ margin-bottom: 12px;
+ font-weight: 600;
+ }
+
+ .community-box p {
+ font-size: 15px;
+ color: #555;
+ line-height: 1.7;
+ margin-bottom: 12px;
+ }
+
+ .community-box a {
+ color: #2196f3;
+ text-decoration: none;
+ font-weight: 600;
+ }
+
+ .email-footer {
+ padding: 20px;
+ text-align: center;
+ background: #f8f9fa;
+ color: #777;
+ font-size: 13px;
+ }
+
+ .email-footer p {
+ margin: 4px 0;
+ }
+
+ .divider {
+ height: 1px;
+ background: linear-gradient(to right, transparent, #e0e0e0, transparent);
+ margin: 20px 0;
+ }
+
+ @media only screen and (max-width: 600px) {
+ body {
+ padding: 10px;
+ }
+
+ .email-header {
+ padding: 24px 16px;
+ }
+
+ .email-header h1 {
+ font-size: 22px;
+ }
+
+ .email-body {
+ padding: 20px 16px;
+ }
+
+ .congrats-card .congrats-icon {
+ font-size: 40px;
+ }
+
+ .congrats-card h3 {
+ font-size: 20px;
+ }
+
+ .cta-button {
+ padding: 16px 40px;
+ font-size: 18px;
+ width: 100%;
+ max-width: 300px;
+ }
+
+ .step-item {
+ flex-direction: column;
+ }
+
+ .step-number {
+ margin-bottom: 8px;
+ }
+ }
+
+ body
+ .email-container
+ //- Header
+ .email-header
+ img.header-logo(src=baseurl+'/images/logo.png' alt=nomeapp)
+ h1 🎉 Benvenuto nel #{nomeTerritorio}!
+ p.subtitle Sei stato abilitato con successo
+
+ //- Body
+ .email-body
+ //- Intro
+ .intro-text
+ | Ciao #{usernameMembro},
+ | complimenti! Sei stato abilitato al Circuito RIS del tuo territorio da #{usernameInvitante}.
+
+ linkProfiloAdmin
+
+ if linkProfiloAdmin
+ .divider(style="margin: 16px 0;")
+ p(style="text-align: center; margin: 16px 0;")
+ a.profile-button(href=linkProfiloAdmin target="_blank" style="display: inline-block; padding: 10px 24px; font-size: 15px; font-weight: 600; color: #7cb342; background: white; border: 2px solid #7cb342; border-radius: 20px; text-decoration: none; transition: all 0.3s ease;")
+ span(style="margin-right: 6px;") 👤
+ | Profilo #{usernameInvitante}
+
+ //- Congratulazioni
+ .congrats-card
+ .congrats-icon ✅
+ h3 Abilitazione Completata
+ p(style="font-size: 15px; color: #555; margin-top: 8px;")
+ | Ora puoi utilizzare i RIS per i tuoi scambi nella comunità
+ .territory-name 📍 #{nomeTerritorio}
+
+ //- Info comunità
+ .community-box
+ h4 💬 Unisciti alla Comunità Territoriale
+ p
+ | Entra nel gruppo Telegram di #{nomeTerritorio} per interagire con i partecipanti, rimanere aggiornato su eventi, mercatini e opportunità di scambio nella tua zona, e per poter inserire, anche tu, annunci di offro/cerco.
+
+ if linkTelegramTerritorio
+ a.telegram-button(href=linkTelegramTerritorio target="_blank" style="display: inline-block; margin-top: 16px; padding: 14px 32px; font-size: 17px; font-weight: 600; color: white; background: linear-gradient(135deg, #0088cc 0%, #006699 100%); border-radius: 25px; text-decoration: none; box-shadow: 0 4px 12px rgba(0, 136, 204, 0.3); transition: all 0.3s ease;")
+ span(style="font-size: 20px; margin-right: 8px; vertical-align: middle;") ✈️
+ | Unisciti al gruppo Telegram
+
+ //- Cos'è RIS
+ .info-section
+ h3
+ span 💰
+ | Cosa sono i RIS?
+ p
+ | RIS (Rete Italiana Scambio) è un sistema di credito comunitario basato sulla fiducia reciproca. Non sono soldi tradizionali, ma un'unità di misura che rappresenta il valore degli scambi all'interno della comunità RISO.
+ p
+ | Parità con l'Euro: 1 RIS = 1 Euro (solo come riferimento di valore, non come convertibilità)
+
+ //- Come funziona la fiducia
+ .highlight-box
+ h4 🤝 Come Funziona la "Fiducia Concessa"
+ p
+ | Parti da 0 RIS - Non devi avere un "saldo positivo" per iniziare a scambiare!
+ p
+ | Quando ricevi un bene o servizio pagando in RIS → il tuo saldo diventa positivo
+ p
+ | Quando offri un bene o servizio ricevendo RIS → il tuo saldo diventa negativo
+ p(style="margin-top: 12px; padding-top: 12px; border-top: 1px solid #f0ad4e;")
+ | 💡 Il saldo negativo non è un debito! È la fiducia che la comunità ti concede. Significa che hai ricevuto prima di aver dato, e la comunità si fida che restituirai nel tempo.
+
+ //- Esempio pratico
+ .example-box
+ h4 📖 Esempio Pratico
+ .transaction
+ | Situazione: Sei un grafico e vuoi comprare 100€ di verdure da un produttore locale
+ .transaction
+ | Transazione mista:
+ |
• Paghi 80€ in Euro
+ |
• Paghi 20 RIS (20% in RIS)
+ |
🔻 Il tuo saldo RIS passa da 0 a -20 RIS
+ .benefit
+ | ✓ Beneficio: Hai ridotto del 20% l'uso degli Euro, sostenendo il produttore locale e rafforzando la comunità! Puoi iniziare con percentuali basse (5-10%) e aumentare man mano che acquisisci fiducia.
+
+ //- Come riequilibrare
+ .info-section
+ h3
+ span ⚖️
+ | Come Riequilibrare il Saldo
+ p
+ | Per riportare il tuo saldo verso lo zero (o in positivo), puoi:
+ ul
+ li Offrire beni o servizi ricevendo RIS in cambio
+ li Vendere prodotti accettando pagamenti parziali o totali in RIS
+ li Mettere annunci sulla piattaforma specificando che accetti RIS
+ li Partecipare ai mercatini locali della comunità RISO
+
+ //- Primi passi
+ .steps-box
+ h4 🚀 I Tuoi Primi Passi
+ .step-item
+ .step-number 1
+ .step-content
+ h5 Esplora la Piattaforma
+ p Familiarizza con gli annunci, i membri e le funzionalità del Circuito RIS
+ .step-item
+ .step-number 2
+ .step-content
+ h5 Crea il Tuo Primo Annuncio
+ p Pubblica cosa offri o cosa cerchi, specificando se accetti pagamenti in RIS
+ .step-item
+ .step-number 3
+ .step-content
+ h5 Inizia con Piccole Transazioni
+ p Comincia con percentuali basse di RIS (5-10%) per prendere confidenza e vedi cosa succede. Più siamo aperti noi e più l'Universo ci aiuta e sostiene e ci dona quello di cui abbiamo bisogno.
+ .step-item
+ .step-number 4
+ .step-content
+ h5 Partecipa alla Comunità
+ p Unisciti agli incontri locali e ai mercatini per conoscere altri membri. Se non ci sono membri che propongono incontri, puoi proporti anche tu!
+
+ //- CTA
+ .cta-section
+ .cta-title Inizia Subito a Usare i RIS!
+ a.cta-button(href=strlinksito target="_blank")
+ span.button-icon 🌾
+ | Vai alla Piattaforma
+
+ //- Supporto
+ .info-section
+ h3
+ span ❓
+ | Hai Domande?
+ p
+ | Se hai dubbi sul funzionamento dei RIS o sulla piattaforma, non esitare a:
+ ul
+ li Contattare il facilitatore del tuo territorio
+ li Chiedere nel gruppo Telegram locale
+ li Partecipare agli incontri di comunità
+
+ //- Footer
+ .email-footer
+ .divider
+ p Benvenuto nella Rete Italiana Scambio orizzontale - #{nomeTerritorio}
+ p(style="margin-top: 12px; font-size: 12px;")
+ | #{new Date().getFullYear()} #{nomeapp}
\ No newline at end of file
diff --git a/emails/RISO/circuit_abilitato_al_fido_membro/it/subject.pug b/emails/RISO/circuit_abilitato_al_fido_membro/it/subject.pug
new file mode 100755
index 0000000..05304aa
--- /dev/null
+++ b/emails/RISO/circuit_abilitato_al_fido_membro/it/subject.pug
@@ -0,0 +1 @@
+=`Richiesta ingresso di ${usernameMembro} - ${nomeMembro} ${cognomeMembro} su ${nomeTerritorio} in ${nomeapp}`
diff --git a/src/models/account.js b/src/models/account.js
index b949e64..6a1d8bd 100755
--- a/src/models/account.js
+++ b/src/models/account.js
@@ -56,6 +56,9 @@ const AccountSchema = new Schema({
fidoConcesso: {
type: Number,
},
+ username_admin_abilitante: {
+ type: String,
+ },
qta_maxConcessa: {
type: Number,
},
@@ -318,6 +321,7 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (
saldo: 0,
saldo_pend: 0,
fidoConcesso: 0,
+ username_admin_abilitante: '',
qta_maxConcessa: 0,
totTransato: 0,
numtransactions: 0,
@@ -643,9 +647,10 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, fidoConcesso,
}
};
-AccountSchema.statics.updateFido = async function (idapp, username, groupname, circuitId, fido) {
+AccountSchema.statics.updateFido = async function (idapp, username, groupname, circuitId, fido, username_action) {
let paramstoupdate = {
fidoConcesso: fido,
+ username_admin_abilitante: username_action,
};
let risult = null;
if (groupname) risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
diff --git a/src/models/circuit.js b/src/models/circuit.js
index 176b1ea..845ee25 100755
--- a/src/models/circuit.js
+++ b/src/models/circuit.js
@@ -174,6 +174,7 @@ const CircuitSchema = new Schema({
{
username: { type: String },
date: { type: Date },
+ enable_to_receive_email: { type: Boolean },
},
],
photos: [
@@ -1331,7 +1332,7 @@ CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, va
}
};
-CircuitSchema.statics.setFido = async function (idapp, username, circuitName, groupname) {
+CircuitSchema.statics.setFido = async function (idapp, username, circuitName, groupname, username_action) {
try {
mycircuit = await Circuit.findOne({ idapp, name: circuitName }).lean();
if (mycircuit) {
@@ -1384,9 +1385,9 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
variato = await Account.updateQtaMax(idapp, username, groupname, circuitId, qtamax);
}
- const ris = await Account.updateFido(idapp, username, groupname, circuitId, fido);
+ const ris = await Account.updateFido(idapp, username, groupname, circuitId, fido, username_action);
if (ris) {
- return { qta_maxConcessa: qtamax, fidoConcesso: fido, changed: variato || (ris && ris.modifiedCount > 0) };
+ return { qta_maxConcessa: qtamax, fidoConcesso: fido, username_admin_abilitante: username_action, changed: variato || (ris && ris.modifiedCount > 0) };
}
}
}
@@ -1882,6 +1883,15 @@ CircuitSchema.statics.getCircuitoItalia = async function (idapp) {
return circuit;
};
+CircuitSchema.statics.isEnableToReceiveEmailByExtraRec = async function (idapp, recnotif) {
+ let ricevo = true;
+ if (recnotif.tag === 'setfido') {
+ // Controllo se l'utente ha scelto di ricevere l'email
+ }
+
+ return ricevo;
+};
+
const Circuit = mongoose.model('Circuit', CircuitSchema);
Circuit.createIndexes()
diff --git a/src/models/sendnotif.js b/src/models/sendnotif.js
index 8dc274d..94dde22 100755
--- a/src/models/sendnotif.js
+++ b/src/models/sendnotif.js
@@ -505,6 +505,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
recnotif.paramsObj.circuitnameDest,
username_action
);
+ tag = 'setfido_admin_group';
} else {
newdescr = i18n.__(
'FIDO_IMPOSTATO_ADMINS_CIRCUIT',
@@ -513,6 +514,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
recnotif.paramsObj.circuitnameDest,
username_action
);
+ tag = 'setfido_admin';
}
recnotif.openUrl = '/my/' + sender;
@@ -520,11 +522,12 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
newdescr = i18n.__(
'FIDO_IMPOSTATO',
-recnotif.paramsObj.extrarec.fidoConcesso,
- username_action,
- recnotif.paramsObj.circuitnameDest
+ recnotif.paramsObj.extrarec.username_admin_abilitante,
+ recnotif.paramsObj.circuitnameDest,
);
+ tag = 'setfido';
}
- tag = 'setfido';
+
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
if (recnotif.paramsObj.isAdmin) {
if (recnotif.extrarec.groupname) {
@@ -971,7 +974,7 @@ sendNotifSchema.statics.findAllNotifCoinsAllIdAndIdApp = function (idapp) {
});
};
-sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res, user) {
+sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res, user, paramsObj) {
const SendNotif = this;
let idapp = req.body.idapp;
@@ -1003,7 +1006,8 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
res,
idapp,
user ? user : req.user,
- myrecread
+ myrecread,
+ paramsObj
);
else return false;
}
@@ -1018,7 +1022,8 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
res,
idapp,
user ? user : req.user,
- myrecout
+ myrecout,
+ paramsObj
);
}
@@ -1312,7 +1317,7 @@ sendNotifSchema.statics.createNewNotifToSingleUser = async function (req, res, p
myrecnotif = this.getExtraParam(myrecnotif, paramsObj);
- return await SendNotif.sendToSingleUserDest(myrecnotif, req, res, onlysave);
+ return await SendNotif.sendToSingleUserDest(myrecnotif, req, res, onlysave, paramsObj);
} catch (e) {
console.error('createNewNotification', e);
return null;
@@ -1547,7 +1552,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
}
};
-sendNotifSchema.statics.sendToSingleUserDest = async function (myrecnotif, req, res, onlysave) {
+sendNotifSchema.statics.sendToSingleUserDest = async function (myrecnotif, req, res, onlysave, paramsObj) {
const SendNotif = this;
try {
@@ -1559,9 +1564,9 @@ sendNotifSchema.statics.sendToSingleUserDest = async function (myrecnotif, req,
: myrecnotif.dest;
if (onlysave) {
- return await SendNotif.saveNotif(myrecnotif, req);
+ return await SendNotif.saveNotif(myrecnotif, req, paramsObj);
} else {
- return await SendNotif.saveAndSendNotif(myrecnotif, req, res, null);
+ return await SendNotif.saveAndSendNotif(myrecnotif, req, res, null, paramsObj);
}
} catch (e) {
console.error('sendToSingleUserDest', e);
diff --git a/src/models/user.js b/src/models/user.js
index da6646d..b1704e0 100755
--- a/src/models/user.js
+++ b/src/models/user.js
@@ -2547,8 +2547,7 @@ UserSchema.statics.getCircuitByTokenAndUsername = async function (idapp, usernam
'profile.mycircuits.token': token,
});
- // Il circuito sarà in: circuit?.profile?.mycircuits?.[0]
- const foundCircuit = user?.profile?.mycircuits?.[0];
+ const foundCircuit = user?.profile?.mycircuits?.find((c) => c.token === token);
if (foundCircuit) {
return { circuitname: foundCircuit.circuitname, user };
}
@@ -2557,6 +2556,7 @@ UserSchema.statics.getCircuitByTokenAndUsername = async function (idapp, usernam
}
return { circuitname: '', user: null };
};
+
UserSchema.statics.removeAllUsersFromMyGroups = async function (idapp, groupnameDest) {
return await User.updateMany({ idapp }, { $pull: { 'profile.mygroups': { groupname: { $in: [groupnameDest] } } } });
};
@@ -3458,11 +3458,12 @@ UserSchema.statics.setCircuitCmd = async function (
}
}
} else if (cmd === shared_consts.CIRCUITCMD.SETFIDO) {
- ris = await Circuit.setFido(idapp, usernameOrig, circuitname, groupname);
+ ris = await Circuit.setFido(idapp, usernameOrig, circuitname, groupname, username_action);
if (ris && ris.fidoConcesso && ris.changed) {
if (extrarec) {
extrarec.fidoConcesso = ris.fidoConcesso;
extrarec.qta_maxConcessa = ris.qta_maxConcessa;
+ extrarec.username_admin_abilitante = ris.username_admin_abilitante;
}
// Elimina la richiesta:
@@ -3991,6 +3992,15 @@ UserSchema.statics.getInfoAskFriendByUsername = async function (idapp, username)
.then((rec) => (!!rec ? rec : null));
};
+UserSchema.statics.isFidoConcesso = async function (idapp, username, nomeCircuito) {
+ try {
+ const myfido = await Circuit.getFido(idapp, username, nomeCircuito, '');
+ return !!myfido && myfido > 0 ? true : false;
+ } catch (e) {
+ return false;
+ }
+};
+
UserSchema.statics.getAskedFriendsByUsername = async function (idapp, username) {
const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username);
@@ -6946,6 +6956,16 @@ UserSchema.statics.createNewSubRecord = async function (idapp, req) {
// Nel tuo User schema, aggiungi questo metodo statico:
+UserSchema.statics.isEnableToReceiveEmailByUsernameECmd = async function (idapp, username, cmd) {
+ let ricevo = true;
+ if (cmd === shared_consts.CIRCUITCMD.SETFIDO) {
+ // Controllo se l'utente ha scelto di ricevere l'email
+
+ }
+
+ return ricevo;
+};
+
UserSchema.statics.getTokenByUsernameAndCircuitName = async function (idapp, username, circuitname) {
const User = this;
diff --git a/src/router/index_router.js b/src/router/index_router.js
index 9d16922..724d401 100755
--- a/src/router/index_router.js
+++ b/src/router/index_router.js
@@ -206,7 +206,8 @@ router.post('/abcirc', async (req, res) => {
const username = body.username;
const groupname = body.groupname;
const username_action = body.username_action;
- const cmd = body.cmd;
+ const cmd = parseInt(body.cmd);
+
try {
// Cerco il token se è ancora da ammettere
@@ -215,21 +216,24 @@ router.post('/abcirc', async (req, res) => {
.then(async (ris) => {
const { circuitname, user } = ris;
if (!user) {
- return res.status(404).send();
+ return res.send({
+ code: server_constants.RIS_CODE_ERRORE,
+ msg: 'La richiesta di Abilitazione non è più presente su questo circuito !',
+ });
} else {
const lang = user.lang;
// console.log('user', user);
let nomeCircuito = circuitname;
- let giaabilitato = false;
+ let giaabilitato = await User.isFidoConcesso(idapp, username, nomeCircuito);
let ret = null;
// user.verified_by_aportador = false;
if (giaabilitato) {
- res.send({
+ return res.send({
code: server_constants.RIS_CODE_GIA_AMMESSO,
- msg: 'Il membro ' + user.username + ' è stato già Abilitato!',
+ msg: 'Il membro ' + user.username + ' è già stato abilitato al circuito ' + nomeCircuito + '!',
circuitName: nomeCircuito,
});
} else {
@@ -244,11 +248,6 @@ router.post('/abcirc', async (req, res) => {
});
}
- return res.send({
- code: server_constants.RIS_CODE_GIA_AMMESSO,
- msg: 'L\'utente è già stato abilitato al circuito ' + nomeCircuito + '!',
- circuitName: nomeCircuito,
- });
}
})
.catch((e) => {
diff --git a/src/router/push_router.js b/src/router/push_router.js
index 274f9d8..74113b3 100755
--- a/src/router/push_router.js
+++ b/src/router/push_router.js
@@ -134,7 +134,7 @@ router.post('/send', authenticate, async (req, res) => {
params.usernameDest = req.user.username;
}
- const ris = await globalTables.SendMsgToParam(idapp, params);
+ const ris = await globalTables.SendMsgToParam(idapp, params, null);
return res.send({
code: server_constants.RIS_CODE_OK,
diff --git a/src/router/sendmsg_router.js b/src/router/sendmsg_router.js
index a657c24..0ca8396 100755
--- a/src/router/sendmsg_router.js
+++ b/src/router/sendmsg_router.js
@@ -64,7 +64,7 @@ router.post('/', authenticate, (req, res) => {
myrecsend.msg = recmsg.message;
let myid = recmsg._id;
// ##Todo !! DA SISTEMARE !!!
- return await SendNotif.saveAndSendNotif(myrecsend, req, res).then((out) => {
+ return await SendNotif.saveAndSendNotif(myrecsend, req, res, null).then((out) => {
if (out)
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: myid });
else
diff --git a/src/router/sendnotif_router.js b/src/router/sendnotif_router.js
index 1819893..1c7a58d 100755
--- a/src/router/sendnotif_router.js
+++ b/src/router/sendnotif_router.js
@@ -21,7 +21,7 @@ router.post('/', authenticate, async (req, res) => {
tools.mylog('crea SendNotif');
let myrecnotif = new SendNotif(body);
- const recout = await SendNotif.saveAndSendNotif(myrecnotif, req, res);
+ const recout = await SendNotif.saveAndSendNotif(myrecnotif, req, res, null);
if (recout) {
return res.send({ code: server_constants.RIS_CODE_OK, notif: '', record: recout });
} else {
diff --git a/src/sendemail.js b/src/sendemail.js
index 24efd3a..73107b6 100755
--- a/src/sendemail.js
+++ b/src/sendemail.js
@@ -507,14 +507,15 @@ module.exports = {
},
getLinkAbilitaCircuito: function (idapp, user, data) {
if (data.token_circuito_da_ammettere) {
- const strlink = tools.getHostByIdApp(idapp) + `/abcirc/${data.cmd}/${data.token_circuito_da_ammettere}/${user.username}`;
+ const strlink = tools.getHostByIdApp(idapp) + `/abcirc/${data.cmd}/${data.token_circuito_da_ammettere}/${user.username}/${data.myusername}`;
return strlink;
}
return '';
},
getPathEmail(idapp, email_template) {
- const RISO_TEMPLATES = ['reg_notifica_all_invitante', 'reg_email_benvenuto_ammesso', 'reg_chiedi_ammettere_all_invitante', 'circuit_chiedi_facilitatori_di_entrare'];
+ const RISO_TEMPLATES = ['reg_notifica_all_invitante', 'reg_email_benvenuto_ammesso', 'reg_chiedi_ammettere_all_invitante',
+ 'circuit_chiedi_facilitatori_di_entrare', 'circuit_abilitato_al_fido_membro'];
if (idapp === '13') {
if (RISO_TEMPLATES.includes(email_template)) {
@@ -674,11 +675,40 @@ module.exports = {
console.error('Err sendEmail_Utente_Ammesso', e);
}
},
+ sendEmail_Utente_Abilitato_Circuito_FidoConcesso: async function (lang, emailto, user, idapp, dati) {
+ try {
+ let mylocalsconf = {
+ idapp,
+ dataemail: await this.getdataemail(idapp),
+ baseurl: tools.getHostByIdApp(idapp),
+ locale: lang,
+ nomeapp: tools.getNomeAppByIdApp(idapp),
+ strlinksito: tools.getHostByIdApp(idapp),
+ emailto: emailto,
+ usernameInvitante: dati.usernameInvitante,
+ linkProfiloAdmin: tools.getLinkUserProfile(idapp, dati.usernameInvitante),
+ user,
+ usernameMembro: user.username,
+ nomeTerritorio: dati.nomeTerritorio,
+ linkTelegramTerritorio: dati.link_group,
+ };
+
+ const quale_email_inviare = this.getPathEmail(idapp, 'circuit_abilitato_al_fido_membro') + '/' + lang;
+
+ const ris = await this.sendEmail_base(quale_email_inviare, emailto, mylocalsconf, '');
+
+ await telegrambot.notifyToTelegram(telegrambot.phase.AMMETTI_UTENTE, mylocalsconf);
+
+ return ris;
+ } catch (e) {
+ console.error('Err sendEmail_Utente_Ammesso', e);
+ }
+ },
sendEmail_Richiesta_Al_Facilitatore_Di_FarEntrare_AlCircuito: async function (lang, emailto, user, userInvitante, idapp, dati) {
try {
// dati.circuitId
// dati.groupname
- dati.cmd = shared_consts.CallFunz.RICHIESTA_FIDO;
+ dati.cmd = shared_consts.CIRCUITCMD.SETFIDO;
const linkAbilitazione = this.getLinkAbilitaCircuito(idapp, user, dati);
diff --git a/src/telegram/telegrambot.js b/src/telegram/telegrambot.js
index 0189e53..debc703 100644
--- a/src/telegram/telegrambot.js
+++ b/src/telegram/telegrambot.js
@@ -1047,6 +1047,7 @@ const MyTelegramBot = {
const data = {
token_circuito_da_ammettere: token,
nomeTerritorio: mycircuit.name,
+ myusername: userDest,
};
// if (usersmanagers) {
// for (const recadminCirc of usersmanagers) {
diff --git a/src/tools/general.js b/src/tools/general.js
index 95d0635..2e7e08a 100755
--- a/src/tools/general.js
+++ b/src/tools/general.js
@@ -1217,6 +1217,7 @@ module.exports = {
if (mycircuit && extrarec) {
extrarec.fido_scoperto_default = mycircuit.fido_scoperto_default;
extrarec.fido_scoperto_default_grp = mycircuit.fido_scoperto_default_grp;
+ extrarec.link_group = mycircuit.link_group;
}
if (cmd) {
@@ -1489,6 +1490,7 @@ module.exports = {
) {
const { Circuit } = require('../models/circuit');
const { SendNotif } = require('../models/sendnotif');
+ var { User } = require('../models/user');
const circuit = await Circuit.findOne(
{ idapp, name: circuitname },
@@ -1626,6 +1628,8 @@ module.exports = {
if (singleadmin.username) {
if (usernameOrig === singleadmin.username) giainviato = true;
+ extrarec.send_email = !!singleadmin.enable_to_receive_email ? singleadmin.enable_to_receive_email : true;
+
await this.sendNotifCircuitByUsername(
cmd,
idapp,
@@ -1649,6 +1653,8 @@ module.exports = {
}
if (!giainviato && cmd !== shared_consts.CIRCUITCMD.REQ) {
+ extrarec.send_email = await User.isEnableToReceiveEmailByUsernameECmd(idapp, usernameOrig, cmd);
+
// SEND TO THE USER DEST THE NOTIFICATION
ris = await this.sendNotifCircuitByUsername(
cmd,
diff --git a/src/tools/globalTables.js b/src/tools/globalTables.js
index 3b62673..c181085 100755
--- a/src/tools/globalTables.js
+++ b/src/tools/globalTables.js
@@ -201,7 +201,7 @@ module.exports = {
return process.env.ENABLE_PUSHNOTIFICATION === '1';
},
- async sendNotifCmd(typenotif, idnotif, res, idapp, user, recnotif, cmd) {
+ async sendNotifCmd(typenotif, idnotif, res, idapp, user, recnotif, paramsObj) {
// Controlla nelle impostazioni che tipo di Notifica visualizzare
const sendemail = require('../sendemail');
@@ -250,8 +250,12 @@ module.exports = {
invia = true;
}
+ if (recnotif.extrarec.send_email) {
+ params.typesend = params.typesend + shared_consts.TypeSend.EMAIL;
+ }
+
if (invia) {
- ris = await this.SendMsgToParam(idapp, params);
+ ris = await this.SendMsgToParam(idapp, params, recnotif, paramsObj);
}
// Send Msg by EMAIL
@@ -270,11 +274,12 @@ module.exports = {
}
},
- SendMsgToParam: async function (idapp, params) {
+ SendMsgToParam: async function (idapp, params, recnotif, paramsObj) {
try {
// console.log('SendMsgToParam', params.typesend, params.typemsg);
const { User } = require('../models/user');
+ const sendemail = require('../sendemail');
let textsent = '';
@@ -432,6 +437,21 @@ module.exports = {
} catch (e) { }
}
}
+ if (tools.isBitActive(params.typesend, shared_consts.TypeSend.EMAIL)) {
+ // Invia una Email
+ if (params.tag === 'setfido') {
+ const usertosend = await User.getUserByUsername(params.idapp, params.usernameDest);
+ if (paramsObj) {
+ }
+
+ const dati = {
+ usernameInvitante: paramsObj.extrarec.username_admin_abilitante,
+ nomeTerritorio: paramsObj.circuitnameDest,
+ link_group: paramsObj.extrarec.link_group,
+ };
+ await sendemail.sendEmail_Utente_Abilitato_Circuito_FidoConcesso(usertosend.lang, usertosend.email, usertosend, params.idapp, dati);
+ }
+ }
}
numrec++;
@@ -470,7 +490,7 @@ module.exports = {
params.sendreally = true;
params.typesend = shared_consts.TypeSend.PUSH_NOTIFICATION;
- return await this.SendMsgToParam(idapp, params);
+ return await this.SendMsgToParam(idapp, params, null);
},
SearchString: async function (idapp, searchString) {
diff --git a/src/tools/shared_nodejs.js b/src/tools/shared_nodejs.js
index 251545d..5a9c3e9 100755
--- a/src/tools/shared_nodejs.js
+++ b/src/tools/shared_nodejs.js
@@ -1,6 +1,6 @@
module.exports = {
USER_ADMIN_CIRCUITS: ['surya1977', 'ElenaEspx'],
- ADMIN_IDTELEGRAM_TEST_USERNAME: ['surya1977', 'SuryaArena', 'surya4'],
+ ADMIN_IDTELEGRAM_TEST_USERNAME: ['surya1977', 'SuryaArena', 'surya4', 'test1234'],
ADMIN_USER_SERVER: 'surya1977',
Accepted: {
CHECK_READ_GUIDELINES: 1,
@@ -604,6 +604,7 @@ module.exports = {
TypeSend: {
PUSH_NOTIFICATION: 1,
TELEGRAM: 2,
+ EMAIL: 4,
},
UsersNotif: {
NEW_ADV_CITY: 1,