Aggiunte opzioni per il Gestore: richiede che l'invitante confermi la Reg, Notifica sul BOT , Notifica all'Admin la Reg.

This commit is contained in:
paoloar77
2022-02-27 16:56:02 +01:00
parent 2749506de7
commit 8d98726f1f
9 changed files with 175 additions and 85 deletions

View File

@@ -71,9 +71,6 @@ const SiteSchema = new Schema({
pathreg_add: { pathreg_add: {
type: String, type: String,
}, },
ask_to_verify_reg: {
type: Boolean,
},
who: { who: {
type: String type: String
}, },
@@ -92,6 +89,12 @@ const SiteSchema = new Schema({
next_payment: { next_payment: {
type: Date type: Date
}, },
confsite: {
options: { // ConfSite
type: Number,
default: 0,
},
}
}); });
var Site = module.exports = mongoose.model('Site', SiteSchema); var Site = module.exports = mongoose.model('Site', SiteSchema);
@@ -100,14 +103,27 @@ module.exports.getFieldsForSearch = function () {
return [] return []
}; };
module.exports.executeQueryTable = async function (idapp, params) { module.exports.executeQueryTable = async function (idapp, params, userreq) {
params.fieldsearch = this.getFieldsForSearch(); params.fieldsearch = this.getFieldsForSearch();
// return tools.executeQueryTable(this, null, params); // return tools.executeQueryTable(this, null, params);
const { User } = require('../models/user');
// Solo l'Admin puó leggerlo
const extrapar = params.extrapar;
if (extrapar) {
return await Site.findOne({idapp: extrapar}, {name: 1, manageremail: 1, confsite: 1}).lean();
}
if (User.isAdmin(userreq.perm)) {
const myarr = await Site.find({}); const myarr = await Site.find({});
return ({ count: myarr.length, rows: myarr }) return ({ count: myarr.length, rows: myarr })
}
}; };
@@ -115,6 +131,6 @@ module.exports.findAllIdApp = async function (idapp) {
const myfind = { active: true }; const myfind = { active: true };
return Site.find(myfind); return Site.find(myfind).lean();
}; };

View File

@@ -71,23 +71,12 @@ const {MailingList} = require('../models/mailinglist');
const {Settings} = require('../models/settings'); const {Settings} = require('../models/settings');
const {SendMsg} = require('../models/sendmsg'); const {SendMsg} = require('../models/sendmsg');
const {Permission} = require('../models/permission'); const {Permission} = require('../models/permission');
const {MsgTemplate} = require('../models/msg_template');
const Product = require('../models/product');
const Producer = require('../models/producer'); const Producer = require('../models/producer');
const Cart = require('../models/cart'); const Cart = require('../models/cart');
const OrdersCart = require('../models/orderscart'); const OrdersCart = require('../models/orderscart');
const Storehouse = require('../models/storehouse'); const Storehouse = require('../models/storehouse');
const Department = require('../models/department'); const Department = require('../models/department');
const ShareWithUs = require('../models/sharewithus');
const Site = require('../models/site');
const IscrittiConacreis = require('../models/iscrittiConacreis');
const Group = require('../models/group'); const Group = require('../models/group');
const {Todo} = require('../models/todo');
const Hours = require('../models/hours');
const Order = require('../models/order');
const Cash = require('../models/cash');
const CashCategory = require('../models/cashCategory');
const CashSubCategory = require('../models/cashSubCategory');
const tools = require('../tools/general'); const tools = require('../tools/general');
@@ -424,6 +413,7 @@ router.post('/setsubrec', authenticate, (req, res) => {
router.post('/gettable', authenticate, (req, res) => { router.post('/gettable', authenticate, (req, res) => {
const params = req.body; const params = req.body;
let idapp = req.user.idapp
const mytable = globalTables.getTableByTableName(params.table); const mytable = globalTables.getTableByTableName(params.table);
// console.log('mytable', mytable); // console.log('mytable', mytable);
if (!mytable) { if (!mytable) {
@@ -433,7 +423,7 @@ router.post('/gettable', authenticate, (req, res) => {
try { try {
return mytable.executeQueryTable(req.user.idapp, params).then(ris => { return mytable.executeQueryTable(idapp, params, req.user).then(ris => {
return res.send(ris); return res.send(ris);
}).catch((e) => { }).catch((e) => {
@@ -449,6 +439,7 @@ router.post('/gettable', authenticate, (req, res) => {
router.post('/pickup', authenticate, (req, res) => { router.post('/pickup', authenticate, (req, res) => {
const params = req.body; const params = req.body;
let idapp = req.user.idapp
let mytable = globalTables.getTableByTableName(params.table); let mytable = globalTables.getTableByTableName(params.table);
// console.log('mytable', mytable); // console.log('mytable', mytable);
if (!mytable) { if (!mytable) {
@@ -456,7 +447,7 @@ router.post('/pickup', authenticate, (req, res) => {
return res.status(400).send({}); return res.status(400).send({});
} }
return mytable.executeQueryPickup(req.user.idapp, params).then(ris => { return mytable.executeQueryPickup(idapp, params).then(ris => {
return res.send(ris); return res.send(ris);
}).catch((e) => { }).catch((e) => {
@@ -482,7 +473,7 @@ router.post('/getpage', async (req, res) => {
router.patch('/setlang', authenticate, async (req, res) => { router.patch('/setlang', authenticate, async (req, res) => {
const username = req.body.data.username; const username = req.body.data.username;
const idapp = req.body.idapp; const idapp = req.user.idapp;
const mydata = req.body.data; const mydata = req.body.data;
const lang = mydata.lang; const lang = mydata.lang;
@@ -509,7 +500,7 @@ router.patch('/setlang', authenticate, async (req, res) => {
router.patch('/chval', authenticate, async (req, res) => { router.patch('/chval', authenticate, async (req, res) => {
// const idapp = req.body.idapp; // const idapp = req.body.idapp;
const id = req.body.data.id; const id = req.body.data.id;
const idapp = req.body.idapp; const idapp = req.user.idapp;
const mydata = req.body.data; const mydata = req.body.data;
const mytable = globalTables.getTableByTableName(mydata.table); const mytable = globalTables.getTableByTableName(mydata.table);
@@ -576,9 +567,8 @@ router.patch('/chval', authenticate, async (req, res) => {
}); });
} }
if (mydata.table === shared_consts.TAB_MYBOTS) { tools.refreshAllTablesInMem(idapp, mydata.table);
telegrambot.reloadMenuBot(idapp);
}
if (mydata.table === shared_consts.TAB_SETTINGS) { if (mydata.table === shared_consts.TAB_SETTINGS) {
if (shared_consts.KEY_TO_CRYPTED.includes(fieldsvalue.key)) { if (shared_consts.KEY_TO_CRYPTED.includes(fieldsvalue.key)) {
fieldsvalue.crypted = true; fieldsvalue.crypted = true;
@@ -702,7 +692,7 @@ router.patch('/askfunz', authenticate, async (req, res) => {
const id = req.body.data.id; const id = req.body.data.id;
// const ind_order = req.body.data.ind_order; // const ind_order = req.body.data.ind_order;
// const username = req.body.data.username; // const username = req.body.data.username;
const idapp = req.body.idapp; const idapp = req.user.idapp;
const mydata = req.body.data; const mydata = req.body.data;
let entra = false; let entra = false;
@@ -751,7 +741,7 @@ router.patch('/callfunz', authenticate, async (req, res) => {
const id = req.body.data.id; const id = req.body.data.id;
// const ind_order = req.body.data.ind_order; // const ind_order = req.body.data.ind_order;
const username = req.body.data.username; const username = req.body.data.username;
const idapp = req.body.idapp; const idapp = req.user.idapp;
const mydata = req.body.data; const mydata = req.body.data;
// const telegrambot = require('../telegram/telegrambot'); // const telegrambot = require('../telegram/telegrambot');
@@ -1217,7 +1207,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp); // msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId,
req.user.username, req.user.idapp); req.user.username, idapp);
let usersList = null; let usersList = null;
@@ -1227,7 +1217,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
User.isManager(req.user.perm)) { User.isManager(req.user.perm)) {
// Send UsersList // Send UsersList
usersList = User.getUsersList(req.user.idapp); usersList = User.getUsersList(idapp);
// usersList = null; // usersList = null;
} }
} }
@@ -1314,7 +1304,7 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
function uploadFile(req, res, version) { function uploadFile(req, res, version) {
// console.log('/upload dir:' + dir); // console.log('/upload dir:' + dir);
const dir = tools.invertescapeslash(req.params.dir); const dir = tools.invertescapeslash(req.params.dir);
const idapp = req.user.idapp; const idapp = req.body.idapp;
const form = new formidable.IncomingForm(); const form = new formidable.IncomingForm();
@@ -1402,7 +1392,8 @@ function uploadFile(req, res, version) {
}); });
} }
console.log(err); if (err)
console.error('Error Upload: ', err);
}); });
} catch (e) { } catch (e) {
console.error('newname', e); console.error('newname', e);

View File

@@ -379,6 +379,7 @@ router.post('/login', (req, res) => {
body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) +
']'; ']';
tools.mylogshow(msg); tools.mylogshow(msg);
tools.writeErrorLog(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg); // telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).send({code: server_constants.RIS_CODE_LOGIN_ERR}); res.status(404).send({code: server_constants.RIS_CODE_LOGIN_ERR});
} }

View File

@@ -23,6 +23,8 @@ const { Newstosent } = require('./models/newstosent');
const server_constants = require('./tools/server_constants'); const server_constants = require('./tools/server_constants');
const { User } = require('./models/user');
const transport_preview = nodemailer.createTransport({ const transport_preview = nodemailer.createTransport({
jsonTransport: true jsonTransport: true
}); });
@@ -203,9 +205,12 @@ module.exports = {
await telegrambot.notifyToTelegram(telegrambot.phase.REGISTRATION, mylocalsconf); await telegrambot.notifyToTelegram(telegrambot.phase.REGISTRATION, mylocalsconf);
if (tools.getConfSiteOptionEnabledByIdApp(mylocalsconf.idapp, shared_consts.ConfSite.Notif_Reg_Push_Admin)) {
const nometot = tools.getNomeCognomeEUserNameByUser(mylocalsconf); const nometot = tools.getNomeCognomeEUserNameByUser(mylocalsconf);
tools.sendNotifToAdmin('Nuova Registrazione Utente: ' + nometot); const numutenti = await User.getNumUsers(mylocalsconf.idapp);
tools.sendNotifToAdmin('++ [' + numutenti + '] ' + nometot);
}
// if (tools.isManagAndAdminDifferent(idapp)) { // if (tools.isManagAndAdminDifferent(idapp)) {
// this.sendEmail_base('admin/registration/' + tools.LANGADMIN, tools.getManagerEmailByIdApp(idapp), mylocalsconf, ''); // this.sendEmail_base('admin/registration/' + tools.LANGADMIN, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');

View File

@@ -9,6 +9,8 @@ const cors = require('cors');
// console.log(" 2) fs"); // console.log(" 2) fs");
const fs = require('fs'); const fs = require('fs');
const server_constants = require('./tools/server_constants');
//const throttle = require('express-throttle-bandwidth'); //const throttle = require('express-throttle-bandwidth');
// app.use(throttle(1024 * 128)) // throttling bandwidth // app.use(throttle(1024 * 128)) // throttling bandwidth
@@ -429,6 +431,11 @@ async function faitest() {
// const $vers = tools.getVersionint('1.92.45'); // const $vers = tools.getVersionint('1.92.45');
if (true){
const prova = tools.getConfSiteOptionEnabledByIdApp('13', shared_consts.ConfSite.Notif_Reg_Push_Admin)
console.log('prova', prova);
}
if (testfind) { if (testfind) {
const {City} = require('./models/city'); const {City} = require('./models/city');

View File

@@ -15,6 +15,8 @@ const {CalZoom} = require('../models/calzoom');
const {MyBot} = require('../models/bot'); const {MyBot} = require('../models/bot');
const shared_consts = require('../tools/shared_nodejs'); const shared_consts = require('../tools/shared_nodejs');
const server_constants = require('../tools/server_constants');
// const {ListaIngresso} = require('../models/listaingresso'); // const {ListaIngresso} = require('../models/listaingresso');
const {MsgTemplate} = require('../models/msg_template'); const {MsgTemplate} = require('../models/msg_template');
@@ -728,24 +730,32 @@ module.exports = {
let text = ''; let text = '';
if (phase === this.phase.REGISTRATION) { if (phase === this.phase.REGISTRATION) {
if (tools.getConfSiteOptionEnabledByIdApp(mylocalsconf.idapp, shared_consts.ConfSite.Notif_Reg_Bot)) {
if (userdest) { if (userdest) {
NameFrom = await User.getNameSurnameByUsername(mylocalsconf.idapp, userdest, true) + aportador; NameFrom = await User.getNameSurnameByUsername(mylocalsconf.idapp,
userdest, true) + aportador;
aportador = NameFrom; aportador = NameFrom;
} }
const numutenti = await User.getNumUsers(mylocalsconf.idapp); const numutenti = await User.getNumUsers(mylocalsconf.idapp);
let nome = tools.getNomeCognomeEUserNameByUser(mylocalsconf.user); let nome = tools.getNomeCognomeEUserNameByUser(mylocalsconf.user);
text = printf(getstr(langdest, 'MSG_APORTADOR_USER_REGISTERED'), nome, numutenti, aportador); text = printf(getstr(langdest, 'MSG_APORTADOR_USER_REGISTERED'), nome,
numutenti, aportador);
}
} }
let addtext = ''; let addtext = '';
let rismsg = null; let rismsg = null;
if (text) {
if (!!mylocalsconf.user.aportador_solidario) { if (!!mylocalsconf.user.aportador_solidario) {
addtext = '[Inviato a ' + NameFrom + ']:' + '\n'; addtext = '[Inviato a ' + NameFrom + ']:' + '\n';
rismsg = await this.sendMsgTelegram(mylocalsconf.idapp, userdest, text); rismsg = await this.sendMsgTelegram(mylocalsconf.idapp, userdest, text);
} }
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text, false, null, userdest); await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp,
addtext + text, false, null, userdest);
}
if (phase === this.phase.REGISTRATION) { if (phase === this.phase.REGISTRATION) {
await this.askConfirmationUserRegistration(mylocalsconf.idapp, shared_consts.CallFunz.REGISTRATION, await this.askConfirmationUserRegistration(mylocalsconf.idapp, shared_consts.CallFunz.REGISTRATION,
@@ -1189,6 +1199,12 @@ module.exports = {
}, },
reloadSites: async function() {
tools.loadApps();
},
setVerifiedReg: async function (idapp, lang, usernameorig, usernameDest) { setVerifiedReg: async function (idapp, lang, usernameorig, usernameDest) {
try { try {
await User.setVerifiedByAportador(idapp, usernameDest, true); await User.setVerifiedByAportador(idapp, usernameDest, true);
@@ -1212,10 +1228,18 @@ module.exports = {
let domanda = ''; let domanda = '';
if (myfunc === shared_consts.CallFunz.REGISTRATION) { if (myfunc === shared_consts.CallFunz.REGISTRATION) {
const notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
if (notask_verif) {
// Non chiedi la verifica Registrazione
this.setVerifiedReg(myuser.idapp, myuser.lang, userDest, myuser.username);
} else {
const name = myuser.username + (myuser.name ? `(${myuser.name} + ' ' + ${myuser.surname})` : '') const name = myuser.username + (myuser.name ? `(${myuser.name} + ' ' + ${myuser.surname})` : '')
const linkuserprof = tools.getHostByIdApp(idapp) + '/my/' + myuser.username; const linkuserprof = tools.getHostByIdApp(idapp) + '/my/' + myuser.username;
domanda = printf(getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM'), domanda = printf(getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM'),
`<br>Username: <b>${name}</b> (${linkuserprof})<br>Email: ` + myuser.email); `<br>Username: <b>${name}</b> (${linkuserprof})<br>Email: ` +
myuser.email);
keyb = cl.getInlineKeyboard(myuser.lang, [ keyb = cl.getInlineKeyboard(myuser.lang, [
{ {
@@ -1232,15 +1256,12 @@ module.exports = {
}, },
]); ]);
} }
}
// INvia Msg // Invia Msg
if (domanda) {
const teleg_id = await User.TelegIdByUsername(idapp, userDest); const teleg_id = await User.TelegIdByUsername(idapp, userDest);
const notask_verif = await User.notAsk_VerifByUsername(idapp, userDest); await this.sendMsgTelegramByIdTelegram(myuser.idapp, teleg_id, domanda, undefined, undefined, true, keyb);
await this.sendMsgTelegramByIdTelegram(myuser.idapp, teleg_id, domanda,
undefined, undefined, true, keyb);bot
if (notask_verif) {
this.setVerifiedReg(myuser.idapp, myuser.lang, userDest, myuser.username);
} }
} catch (e) { } catch (e) {

View File

@@ -31,6 +31,7 @@ const webpush = require('web-push');
const FILELOG = 'filelog.txt'; const FILELOG = 'filelog.txt';
const FILEEVENTS = 'logevents.txt'; const FILEEVENTS = 'logevents.txt';
const FILEMANAGERS = 'logmanagers.txt'; const FILEMANAGERS = 'logmanagers.txt';
const FILEERRLOGIN = 'errlogin.txt';
const FILESOSTITUZIONI = 'log_sostituzioni.txt'; const FILESOSTITUZIONI = 'log_sostituzioni.txt';
const FILEIP_TO_BAN = 'log_iptoban.txt'; const FILEIP_TO_BAN = 'log_iptoban.txt';
const FILENAVE = 'logNave.txt'; const FILENAVE = 'logNave.txt';
@@ -878,8 +879,7 @@ module.exports = {
let actions = []; let actions = [];
if (cmd) { if (cmd) {
if (cmd === shared_consts.GROUPSCMD.REQGROUP) { if (cmd === shared_consts.GROUPSCMD.REQGROUP) {
descr = printf(this.get__('RICHIESTA_GRUPPO', lang), groupname, descr = printf(this.get__('RICHIESTA_GRUPPO', lang), groupname, arradmins.username);
arradmins.username);
openUrl = '/grp/' + groupname; openUrl = '/grp/' + groupname;
tag = 'reqgroups'; tag = 'reqgroups';
} else if (cmd === shared_consts.GROUPSCMD.BLOCK_USER) { } else if (cmd === shared_consts.GROUPSCMD.BLOCK_USER) {
@@ -1046,8 +1046,7 @@ module.exports = {
getHostByIdApp: function(idapp) { getHostByIdApp: function(idapp) {
const myapp = const myapp = this.getApps().find(item => item.idapp === idapp);
this.getApps().find(item => item.idapp === idapp);
if (myapp) { if (myapp) {
let siteport = (myapp.portapp && myapp.portapp !== '0') ? (':' + let siteport = (myapp.portapp && myapp.portapp !== '0') ? (':' +
myapp.portapp) : ''; myapp.portapp) : '';
@@ -1061,6 +1060,36 @@ module.exports = {
return ''; return '';
}, },
getConfSiteOptionEnabledByIdApp: function(idapp, option) {
const myapp = this.getApps().find(item => item.idapp === idapp);
if (myapp) {
if (myapp.hasOwnProperty('confsite')) {
if (myapp.confsite.hasOwnProperty('options')) {
return this.isBitActive(myapp.confsite.options, option);
}
}
}
return false;
},
getConfParamSiteByIdApp: function(idapp, field) {
const myapp = this.getApps().find(item => item.idapp === idapp);
if (myapp) {
if (myapp.hasOwnProperty('confsite')) {
if (myapp.confsite.hasOwnProperty(field)) {
return myapp.confsite[field];
}
}
}
return false;
},
isAbilitaNave: function(idapp) { isAbilitaNave: function(idapp) {
const myapp = this.getApps().find(item => item.idapp === idapp); const myapp = this.getApps().find(item => item.idapp === idapp);
return myapp.abilitanave; return myapp.abilitanave;
@@ -1107,12 +1136,7 @@ module.exports = {
}, },
getAskToVerifyReg: function(idapp) { getAskToVerifyReg: function(idapp) {
const myapp = this.getApps().find((item) => item.idapp === idapp); return tools.getConfSiteOptionEnabledByIdApp(idapp, shared_consts.ConfSite.Need_Aportador_On_DataReg_To_Verify_Reg);
if (myapp) {
return myapp.ask_to_verify_reg;
} else {
return false;
}
}, },
isManagAndAdminDifferent(idapp) { isManagAndAdminDifferent(idapp) {
@@ -2087,12 +2111,16 @@ module.exports = {
// if (err) throw err; // if (err) throw err;
// console.log('Saved!'); // console.log('Saved!');
// }); // });
try {
mystr = this.getstrDateTimeShort(new Date(), 'it') + ': ' + mystr; mystr = this.getstrDateTimeShort(new Date(), 'it') + ': ' + mystr;
const stream = fs.createWriteStream(filename, {flags: 'a'}); const stream = fs.createWriteStream(filename, {flags: 'a'});
stream.write('\n' + mystr); stream.write('\n' + mystr);
stream.end(); stream.end();
}catch (e) {
}
}, },
readlogfile(idapp, filename) { readlogfile(idapp, filename) {
@@ -2115,6 +2143,9 @@ module.exports = {
writeManagersLog(mystr) { writeManagersLog(mystr) {
this.writelogfile(mystr, FILEMANAGERS); this.writelogfile(mystr, FILEMANAGERS);
}, },
writeErrorLog(mystr) {
this.writelogfile(mystr, FILEERRLOGIN);
},
writeSostituzioniLog(mystr) { writeSostituzioniLog(mystr) {
this.writelogfile(mystr, FILESOSTITUZIONI); this.writelogfile(mystr, FILESOSTITUZIONI);
@@ -2542,4 +2573,15 @@ module.exports = {
return process.env.LOCALE !== '1'; return process.env.LOCALE !== '1';
}, },
refreshAllTablesInMem(idapp, table){
const telegrambot = require('../telegram/telegrambot');
if (table === shared_consts.TAB_MYBOTS) {
telegrambot.reloadMenuBot(idapp);
} else if (table === shared_consts.TAB_SITES) {
telegrambot.reloadSites();
}
}
}; };

View File

@@ -107,6 +107,6 @@ module.exports = Object.freeze({
TypeProj: { TypeProj: {
TYPE_PROJECT: 1, TYPE_PROJECT: 1,
TYPE_SUBDIR: 2, TYPE_SUBDIR: 2,
} },
}); });

View File

@@ -233,6 +233,12 @@ module.exports = {
CANCELED: 10, CANCELED: 10,
}, },
ConfSite: {
Notif_Reg_Bot: 1,
Notif_Reg_Push_Admin: 2,
Need_Aportador_On_DataReg_To_Verify_Reg: 4,
},
fieldsUserToChange() { fieldsUserToChange() {
return [ return [
'_id', '_id',
@@ -260,4 +266,5 @@ module.exports = {
'qualified']; 'qualified'];
}, },
}; };