Aggiunto messaggio nella registrazione, dicendo che occorre avere Telegram installato.

PASSARE TUTTI I _DOC e mettergli .lean() prima dello then()  -> velocizza le Query di Mongodb
"Floriterapia
costellazioni familiari
coach motivazionale
Tecniche Essene"
Inserimento Gruppi: anche il comune obbligatorio
Far comparire le ultime persone registrate
Mettere il controllo dell'abilitazione del BOT Telegram solo dopo che conosco il suo username, e cosi gli metto anche il contatto telegram.
risolto foto profilo di telegram che non si salvava in automatico
tolto il controllo della email
aggiunto msg se errore al server, installare altro browser.
This commit is contained in:
paoloar77
2022-03-03 20:32:04 +01:00
parent 94a2a073e5
commit c1cecc5eb4
11 changed files with 228 additions and 169 deletions

View File

@@ -40,11 +40,11 @@ html
- var index = 0 - var index = 0
each product in orders.items each product in orders.items
- var descr = product._doc.order.product.name - var descr = product.order.product.name
- var img = product._doc.order.product.img - var img = product.order.product.img
- var price = product._doc.order.price - var price = product.order.price
- var after_price = product._doc.order.after_price - var after_price = product.order.after_price
- var qty = product._doc.order.quantity - var qty = product.order.quantity
- index = index + 1 - index = index + 1
table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center") table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")

View File

@@ -40,11 +40,11 @@ html
- var index = 0 - var index = 0
each product in orders.items each product in orders.items
- var descr = product._doc.order.product.name - var descr = product.order.product.name
- var img = product._doc.order.product.img - var img = product.order.product.img
- var price = product._doc.order.price - var price = product.order.price
- var after_price = product._doc.order.after_price - var after_price = product.order.after_price
- var qty = product._doc.order.quantity - var qty = product.order.quantity
- index = index + 1 - index = index + 1
table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center") table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")

View File

@@ -1,5 +1,4 @@
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema; const Schema = mongoose.Schema;
const shared_consts = require('../tools/shared_nodejs'); const shared_consts = require('../tools/shared_nodejs');
@@ -8,40 +7,39 @@ const Order = require('../models/order');
const CartSchema = new Schema({ const CartSchema = new Schema({
idapp: { idapp: {
type: String type: String,
}, },
userId: { type: Schema.Types.ObjectId, ref: 'User' }, userId: {type: Schema.Types.ObjectId, ref: 'User'},
totalQty: { type: Number, default: 0 }, totalQty: {type: Number, default: 0},
totalPrice: { type: Number, default: 0 }, totalPrice: {type: Number, default: 0},
department: { department: {
type: String, ref: 'Department' type: String, ref: 'Department',
}, },
items: [ items: [
{ {
order: order:
{ type: Schema.Types.ObjectId, ref: 'Order' } {type: Schema.Types.ObjectId, ref: 'Order'},
} },
], ],
note: { note: {
type: String type: String,
}, },
modify_at: { modify_at: {
type: Date type: Date,
}, },
}); });
var Cart = module.exports = mongoose.model('Cart', CartSchema); var Cart = module.exports = mongoose.model('Cart', CartSchema);
module.exports.findAllIdApp = async function (idapp, userId) { module.exports.findAllIdApp = async function(idapp, userId) {
const myfind = { idapp, userId }; const myfind = {idapp, userId};
return await Cart.findOne(myfind); return await Cart.findOne(myfind).lean();
}; };
module.exports.getCartByUserId = async function(uid, idapp) {
module.exports.getCartByUserId = async function (uid, idapp) { let query = {userId: uid, idapp};
let query = { userId: uid, idapp } const mycart = await Cart.findOne(query).lean();
const mycart = await Cart.findOne(query);
if (!!mycart) { if (!!mycart) {
for (const idkey in mycart.items) { for (const idkey in mycart.items) {
@@ -53,7 +51,7 @@ module.exports.getCartByUserId = async function (uid, idapp) {
} }
const myord = await Order.getTotalOrderById(idorder); const myord = await Order.getTotalOrderById(idorder);
if (myord.length > 0) { if (myord.length > 0) {
mycart.items[idkey]._doc.order = myord[0]; mycart.items[idkey].order = myord[0];
} }
} catch (e) { } catch (e) {
console.log('err', e); console.log('err', e);
@@ -63,66 +61,64 @@ module.exports.getCartByUserId = async function (uid, idapp) {
} }
return null; return null;
} };
module.exports.updateCartByUserId = function (userId, newCart, callback) { module.exports.updateCartByUserId = function(userId, newCart, callback) {
let query = { userId: userId } let query = {userId: userId};
Cart.find(query, function (err, c) { Cart.find(query, function(err, c) {
if (err) throw err if (err) throw err;
//exist cart in databse //exist cart in databse
if (c.length > 0) { if (c.length > 0) {
Cart.findOneAndUpdate( Cart.findOneAndUpdate(
{ userId: userId }, {userId: userId},
{ {
$set: { $set: {
items: newCart.items, items: newCart.items,
totalQty: newCart.totalQty, totalQty: newCart.totalQty,
totalPrice: newCart.totalPrice, totalPrice: newCart.totalPrice,
userId: userId userId: userId,
} },
}, },
{ new: true }, {new: true},
callback callback,
) );
} else { } else {
//no cart in database //no cart in database
newCart.save(callback) newCart.save(callback);
} }
}) });
} };
module.exports.updateCartByCartId = async function (cartId, newCart) { module.exports.updateCartByCartId = async function(cartId, newCart) {
// delete newCart._doc._id; // delete newCart._doc._id;
const items = newCart._doc.items; const items = newCart.items;
const totalQty = newCart.totalQty; const totalQty = newCart.totalQty;
const totalPrice = newCart.totalPrice; const totalPrice = newCart.totalPrice;
const modify_at = new Date(); const modify_at = new Date();
return await Cart.findOneAndUpdate({ _id: cartId }, { return Cart.findOneAndUpdate({_id: cartId}, {
$set: { $set: {
items, items,
totalPrice, totalPrice,
totalQty, totalQty,
modify_at modify_at,
} },
}, { new: false }) }, {new: false}).lean().then((ris) => {
.then((ris) => { return ris;
return ris; }).catch(err => {
}).catch(err => { console.log('err', err);
console.log('err', err); return null;
return null });
})
} };
module.exports.deleteCartByCartId = async function (cartId) { module.exports.deleteCartByCartId = async function(cartId) {
return await Cart.remove({ _id: cartId }); return await Cart.remove({_id: cartId});
} };
module.exports.createCart = async function(newCart) {
module.exports.createCart = async function (newCart) { return await newCart.save();
return await newCart.save() };
}

View File

@@ -160,8 +160,8 @@ NewstosentSchema.statics.isActivated = async function (_id) {
const Newstosent = this; const Newstosent = this;
try { try {
const mydoc = await Newstosent.findOne({ _id }); const mydoc = await Newstosent.findOne({ _id }).lean();
return (mydoc._doc.activate); return (mydoc.activate);
} catch (e) { } catch (e) {
return false return false
} }

View File

@@ -109,7 +109,7 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
query.userId = uid; query.userId = uid;
} }
myorderscart = await OrdersCart.find(query); myorderscart = await OrdersCart.find(query).lean();
for (let ind = 0; ind < myorderscart.length; ind++) { for (let ind = 0; ind < myorderscart.length; ind++) {
for (const idkey in myorderscart[ind].items) { for (const idkey in myorderscart[ind].items) {
@@ -119,10 +119,10 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
if (!!myorder) { if (!!myorder) {
idorder = myorderscart[ind].items[idkey].order._id.toString(); idorder = myorderscart[ind].items[idkey].order._id.toString();
} }
myorderscart[ind]._doc.nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId); myorderscart[ind].nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId);
const myord = await Order.getTotalOrderById(idorder); const myord = await Order.getTotalOrderById(idorder);
if (myord.length > 0) { if (myord.length > 0) {
myorderscart[ind].items[idkey]._doc.order = myord[0]; myorderscart[ind].items[idkey].order = myord[0];
} }
} catch (e) { } catch (e) {
console.log('err', e); console.log('err', e);
@@ -154,7 +154,7 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) { module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) {
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } } let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
const myorderscart = await OrdersCart.find(query); const myorderscart = await OrdersCart.find(query).lean();
for (let ind = 0; ind < myorderscart.length; ind++) { for (let ind = 0; ind < myorderscart.length; ind++) {
for (const idkey in myorderscart[ind].items) { for (const idkey in myorderscart[ind].items) {
@@ -164,10 +164,10 @@ module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) {
if (!!myorder) { if (!!myorder) {
idorder = myorderscart[ind].items[idkey].order._id.toString(); idorder = myorderscart[ind].items[idkey].order._id.toString();
} }
myorderscart[ind]._doc.nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId); myorderscart[ind].nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId);
const myord = await Order.getTotalOrderById(idorder); const myord = await Order.getTotalOrderById(idorder);
if (myord.length > 0) { if (myord.length > 0) {
myorderscart[ind].items[idkey]._doc.order = myord[0]; myorderscart[ind].items[idkey].order = myord[0];
} }
} catch (e) { } catch (e) {
console.log('err', e); console.log('err', e);
@@ -181,7 +181,7 @@ module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) {
module.exports.getOrderById = async function (Id, idapp) { module.exports.getOrderById = async function (Id, idapp) {
let query = { _id: Id, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } } let query = { _id: Id, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
const myorderscart = await OrdersCart.find(query); const myorderscart = await OrdersCart.find(query).lean();
for (let ind = 0; ind < myorderscart.length; ind++) { for (let ind = 0; ind < myorderscart.length; ind++) {
for (const idkey in myorderscart[ind].items) { for (const idkey in myorderscart[ind].items) {
@@ -191,10 +191,10 @@ module.exports.getOrderById = async function (Id, idapp) {
if (!!myorder) { if (!!myorder) {
idorder = myorderscart[ind].items[idkey].order._id.toString(); idorder = myorderscart[ind].items[idkey].order._id.toString();
} }
myorderscart[ind]._doc.nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId); myorderscart[ind].nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId);
const myord = await Order.getTotalOrderById(idorder); const myord = await Order.getTotalOrderById(idorder);
if (myord.length > 0) { if (myord.length > 0) {
myorderscart[ind].items[idkey]._doc.order = myord[0]; myorderscart[ind].items[idkey].order = myord[0];
} }
} catch (e) { } catch (e) {
console.log('err', e); console.log('err', e);

View File

@@ -4,6 +4,7 @@ const validator = require('validator');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const _ = require('lodash'); const _ = require('lodash');
const tools = require('../tools/general'); const tools = require('../tools/general');
const {Settings} = require('../models/settings'); const {Settings} = require('../models/settings');
@@ -996,7 +997,7 @@ UserSchema.statics.getindOrderDuplicate = function(idapp) {
return User.aggregate(User.getUsersNationalityQuery(idapp)).then(ris => { return User.aggregate(User.getUsersNationalityQuery(idapp)).then(ris => {
// console.table(ris); // console.table(ris);
return JSON.stringify(ris); return ris;
}); });
}; };
@@ -1875,7 +1876,7 @@ UserSchema.statics.UsersByIdTelegram = async function(idapp, teleg_id) {
return User.find({ return User.find({
idapp, 'profile.teleg_id': teleg_id, idapp, 'profile.teleg_id': teleg_id,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}).then((rec) => { }).lean().then((rec) => {
return (!!rec) ? rec._doc : null; return (!!rec) ? rec._doc : null;
}).catch((e) => { }).catch((e) => {
console.error('UserExistByIdTelegram', e); console.error('UserExistByIdTelegram', e);
@@ -1891,7 +1892,7 @@ UserSchema.statics.setPicProfile = async function(idapp, username, imgpic) {
return User.findOneAndUpdate({ return User.findOneAndUpdate({
idapp, username, idapp, username,
}, {$set: fields_to_update}, {new: false}).then((record) => { }, {$set: fields_to_update}, {new: false}).lean().then((record) => {
return !!record; return !!record;
}); });
@@ -1903,7 +1904,7 @@ UserSchema.statics.TelegIdByUsername = async function(idapp, username) {
return User.findOne({ return User.findOne({
idapp, username, idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'profile.teleg_id': 1}).then((rec) => { }, {'profile.teleg_id': 1}).lean().then((rec) => {
return (!!rec) ? rec.profile.teleg_id : null; return (!!rec) ? rec.profile.teleg_id : null;
}).catch((e) => { }).catch((e) => {
console.error('TelegIdByUsername', e); console.error('TelegIdByUsername', e);
@@ -1914,7 +1915,7 @@ UserSchema.statics.notAsk_VerifByUsername = async function(idapp, username) {
return User.findOne({ return User.findOne({
idapp, username, idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'notask_verif': 1}).then((rec) => { }, {'notask_verif': 1}).lean().then((rec) => {
return (!!rec && rec.notask_verif) ? true: false; return (!!rec && rec.notask_verif) ? true: false;
}).catch((e) => { }).catch((e) => {
console.error('notAsk_VerifByUsername', e); console.error('notAsk_VerifByUsername', e);
@@ -1932,7 +1933,7 @@ UserSchema.statics.SetTelegramCheckCode = async function(
return User.findOneAndUpdate({ return User.findOneAndUpdate({
_id: id, _id: id,
}, {$set: fields_to_update}, {new: false}).then((record) => { }, {$set: fields_to_update}, {new: false}).lean().then((record) => {
return !!record; return !!record;
}); });
@@ -1966,7 +1967,7 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) {
return User.findOneAndUpdate({ return User.findOneAndUpdate({
idapp, idapp,
_id: id, _id: id,
}, {$set: fields_to_update}, {new: false}).then((record) => { }, {$set: fields_to_update}, {new: false}).lean().then((record) => {
return record; return record;
}); });
@@ -2690,8 +2691,8 @@ UserSchema.statics.checkUser = async function(idapp, username) {
notask_verif: 1, notask_verif: 1,
'profile.teleg_id': 1, 'profile.teleg_id': 1,
'profile.teleg_checkcode': 1, 'profile.teleg_checkcode': 1,
}).then((rec) => { }).lean().then((rec) => {
return JSON.stringify(rec); return rec;
}); });
}; };
@@ -2720,7 +2721,18 @@ UserSchema.statics.calculateStat = async function(idapp, username) {
const numGroups = await MyGroup.countDocuments({idapp}); const numGroups = await MyGroup.countDocuments({idapp});
return {numMySkills, numMyGoods, numMyBachecas, numUsersReg, numGroups}; let numByTab = {}
const globalTables = require('../tools/globalTables');
for (let table of shared_consts.TABLES_VISU_STAT_IN_HOME) {
let mytable = globalTables.getTableByTableName(table);
if (mytable) {
numByTab[table] = await mytable.countDocuments({idapp});
}
}
return {numByTab, numUsersReg};
} catch (e) { } catch (e) {
console.error(e.message); console.error(e.message);
} }
@@ -2752,7 +2764,7 @@ UserSchema.statics.findAllDistinctNationality = async function(idapp) {
return User.aggregate(User.getDistinctNationalityQuery(idapp)).then(ris => { return User.aggregate(User.getDistinctNationalityQuery(idapp)).then(ris => {
// console.table(ris); // console.table(ris);
return JSON.stringify(ris); return ris;
}); });
}; };
@@ -2863,7 +2875,7 @@ UserSchema.statics.calcRegDaily = async function(idapp) {
return User.aggregate(User.getUsersRegDaily(idapp, 30)).then(ris => { return User.aggregate(User.getUsersRegDaily(idapp, 30)).then(ris => {
// console.table(ris); // console.table(ris);
return JSON.stringify(ris); return ris;
}); });
}; };
@@ -2872,7 +2884,7 @@ UserSchema.statics.calcRegWeekly = async function(idapp) {
return User.aggregate(User.getUsersRegWeekly(idapp, 20 * 7)).then(ris => { return User.aggregate(User.getUsersRegWeekly(idapp, 20 * 7)).then(ris => {
// console.table(ris); // console.table(ris);
return JSON.stringify(ris.slice(0, -1)); return ris.slice(0, -1);
}); });
}; };
@@ -3160,9 +3172,9 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
$or: [ $or: [
{deleted: {$exists: false}}, {deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}], {deleted: {$exists: true, $eq: false}}],
}, {username: 1}); }, {username: 1}).lean();
recUser._doc.profile.asked_friends = listSentMyRequestFriends recUser.profile.asked_friends = listSentMyRequestFriends
? listSentMyRequestFriends ? listSentMyRequestFriends
: []; : [];
@@ -3176,7 +3188,7 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
{deleted: {$exists: true, $eq: false}}], {deleted: {$exists: true, $eq: false}}],
}, MyGroup.getWhatToShow_Unknown()); }, MyGroup.getWhatToShow_Unknown());
recUser._doc.profile.asked_groups = listSentMyRequestGroups recUser.profile.asked_groups = listSentMyRequestGroups
? listSentMyRequestGroups ? listSentMyRequestGroups
: []; : [];
@@ -3190,7 +3202,7 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
{deleted: {$exists: true, $eq: false}}], {deleted: {$exists: true, $eq: false}}],
}); });
recUser._doc.profile.manage_mygroups = listManageGroups recUser.profile.manage_mygroups = listManageGroups
? listManageGroups ? listManageGroups
: []; : [];

View File

@@ -110,5 +110,9 @@ module.exports = {
{_id: 108, idSector: [10], descr: 'Affrancamento'}, {_id: 108, idSector: [10], descr: 'Affrancamento'},
{_id: 109, idSector: [10], descr: 'Supporto'}, {_id: 109, idSector: [10], descr: 'Supporto'},
{_id: 110, idSector: [10], descr: 'Consulenza'}, {_id: 110, idSector: [10], descr: 'Consulenza'},
{_id: 111, idSector: [6], descr: 'Floriterapia'},
{_id: 112, idSector: [6], descr: 'Costellazioni Familiari'},
{_id: 113, idSector: [6], descr: 'Coach Motivazionale'},
{_id: 114, idSector: [6], descr: 'Tecniche Essene'},
], ],
}; };

View File

@@ -558,7 +558,7 @@ async function faitest() {
const langdest = 'it'; const langdest = 'it';
telegrambot.askConfirmationUserRegistration(myuser.idapp, telegrambot.askConfirmationUserRegistration(myuser.idapp,
shared_consts.CallFunz.REGISTRATION, myuser, 'perseo77', langdest); shared_consts.CallFunz.REGISTRATION, myuser);
} }

View File

@@ -198,6 +198,7 @@ MsgBot = {
DONNA: ['donna', 'femmina'], DONNA: ['donna', 'femmina'],
FARE_DOMANDA: ['fare una domanda', 'posso farti una domanda'], FARE_DOMANDA: ['fare una domanda', 'posso farti una domanda'],
DIVENTERO_RICCA: ['diventerò ricc'], DIVENTERO_RICCA: ['diventerò ricc'],
DOVE_VUOI_VIVERE: ['dove vuoi vivere'],
MA_ALLORA: ['ma allora'], MA_ALLORA: ['ma allora'],
}; };
@@ -772,12 +773,6 @@ module.exports = {
addtext + text, false, null, userdest); addtext + text, false, null, userdest);
} }
if (phase === this.phase.REGISTRATION) {
await this.askConfirmationUserRegistration(mylocalsconf.idapp,
shared_consts.CallFunz.REGISTRATION,
mylocalsconf.user, userdest, langdest);
}
/* /*
// Invia richiesta allo Sponsor // Invia richiesta allo Sponsor
const domanda = printf(getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM'), const domanda = printf(getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM'),
@@ -1236,62 +1231,6 @@ module.exports = {
} }
}, },
askConfirmationUserRegistration: async function(
idapp, myfunc, myuser, userDest = '', langdest = '') {
const cl = getclTelegByidapp(idapp);
try {
let keyb = null;
let domanda = '';
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 linkuserprof = tools.getHostByIdApp(idapp) + '/my/' +
myuser.username;
domanda = printf(getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM'),
`<br>Username: <b>${name}</b> (${linkuserprof})<br>Email: ` +
myuser.email);
keyb = cl.getInlineKeyboard(myuser.lang, [
{
text: '✅ Abilita ' + myuser.username,
callback_data: InlineConferma.RISPOSTA_SI +
shared_consts.CallFunz.REGISTRATION + tools.SEP +
myuser.username + tools.SEP + userDest,
},
{
text: '🚫 Rifiuta ' + myuser.username,
callback_data: InlineConferma.RISPOSTA_NO +
shared_consts.CallFunz.REGISTRATION + tools.SEP +
myuser.username + tools.SEP + userDest,
},
]);
}
}
// Invia Msg
if (domanda) {
const teleg_id = await User.TelegIdByUsername(idapp, userDest);
await this.sendMsgTelegramByIdTelegram(myuser.idapp, teleg_id, domanda,
undefined, undefined, true, keyb);
}
} catch (e) {
console.error('Error askConfirmationUserRegistration', e);
}
},
}; };
@@ -1328,6 +1267,69 @@ async function sendMsgTelegramToTheAdmin(idapp, text, msg) {
} }
async function askConfirmationUserRegistration(idapp, myfunc, myuser, usernametelegram = '', name_telegram = '', surname_telegram = '') {
const cl = getclTelegByidapp(idapp);
try {
const userDest = myuser.aportador_solidario;
const langdest = myuser.lang;
let keyb = null;
let domanda = '';
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 linkuserprof = tools.getHostByIdApp(idapp) + '/my/' +
myuser.username;
domanda = printf(getstr(langdest, 'MSG_APORTADOR_ASK_CONFIRM'),
`<br>Username: <b>${name}</b><br>Profilo su APP: ${linkuserprof}<br>Email: ` +
myuser.email);
if (usernametelegram) {
domanda += '<br>Profilo su Telegram [' + name_telegram + ' ' + surname_telegram + ']:<br>' + 'https://t.me/' + usernametelegram;
}
keyb = cl.getInlineKeyboard(myuser.lang, [
{
text: '✅ Abilita ' + myuser.username,
callback_data: InlineConferma.RISPOSTA_SI +
shared_consts.CallFunz.REGISTRATION + tools.SEP +
myuser.username + tools.SEP + userDest,
},
{
text: '🚫 Rifiuta ' + myuser.username,
callback_data: InlineConferma.RISPOSTA_NO +
shared_consts.CallFunz.REGISTRATION + tools.SEP +
myuser.username + tools.SEP + userDest,
},
]);
}
}
// Invia Msg
if (domanda) {
const teleg_id = await User.TelegIdByUsername(idapp, userDest);
await local_sendMsgTelegramByIdTelegram(idapp, teleg_id, domanda,
undefined, undefined, true, keyb);
}
} catch (e) {
console.error('Error askConfirmationUserRegistration', e);
}
}
function getusernameByUser(idapp, msg) { function getusernameByUser(idapp, msg) {
let username = ''; let username = '';
let rec = this.getRecInMem(msg); let rec = this.getRecInMem(msg);
@@ -1381,6 +1383,24 @@ async function local_sendMsgTelegram(idapp, username, text) {
} }
async function local_sendMsgTelegramByIdTelegram(idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec,
MyForm = null) {
console.log('sendMsgTelegramByIdTelegram', text);
if (!idtelegram)
return;
const cl = getclTelegByidapp(idapp);
if (cl && idtelegram) {
return await cl.sendMsg(idtelegram, text, null, MyForm, message_id,
chat_id, ripr_menuPrec);
}
}
function getstr(lang, key, param1) { function getstr(lang, key, param1) {
let mystr = ''; let mystr = '';
@@ -1598,6 +1618,14 @@ class Telegram {
msg.from.last_name || ''); msg.from.last_name || '');
await this.sendMsg(msg.from.id, await this.sendMsg(msg.from.id,
printf(getstr(rec.user.lang, 'MSG_SET_USERNAME_OK'))); printf(getstr(rec.user.lang, 'MSG_SET_USERNAME_OK')));
if (!rec.user.verified_by_aportador) {
askConfirmationUserRegistration(this.idapp,
shared_consts.CallFunz.REGISTRATION, rec.user,
msg.from.username || '', msg.from.first_name || '',
msg.from.last_name || '');
}
} else { } else {
if (!rec.user.profile.username_telegram) { if (!rec.user.profile.username_telegram) {
return this.checkIfUsernameTelegramSet(msg, rec.user); return this.checkIfUsernameTelegramSet(msg, rec.user);
@@ -1711,8 +1739,9 @@ class Telegram {
emo.GIFT_HEART; emo.GIFT_HEART;
} else if (MsgBot.MA_ALLORA.find((rec) => testo.indexOf(rec) > -1)) { } else if (MsgBot.MA_ALLORA.find((rec) => testo.indexOf(rec) > -1)) {
risp = 'Ma allora cosa?'; risp = 'Ma allora cosa?';
} else if (MsgBot.TROVAMI_UN_UOMO_DONNA.find( } else if (MsgBot.DOVE_VUOI_VIVERE.find((rec) => testo.indexOf(rec) > -1)) {
(rec) => testo.indexOf(rec) > -1)) { risp = 'Mah a me piacerebbe vivere al mare, ma anche vicino al verde, in montagna. Sarebbe l\'ideale 😄';
} else if (MsgBot.TROVAMI_UN_UOMO_DONNA.find((rec) => testo.indexOf(rec) > -1)) {
risp = 'Eh non è cosi facile. Ma se t\'impegni a cercare ci riuscirai. Nel frattempo trova la tua strada, fai il tuo percorso interiore, e magari arriva proprio quando meno te l\'aspetti'; risp = 'Eh non è cosi facile. Ma se t\'impegni a cercare ci riuscirai. Nel frattempo trova la tua strada, fai il tuo percorso interiore, e magari arriva proprio quando meno te l\'aspetti';
} else if (MsgBot.SEI_LIBERO_STASERA.find( } else if (MsgBot.SEI_LIBERO_STASERA.find(
(rec) => testo.indexOf(rec) > -1)) { (rec) => testo.indexOf(rec) > -1)) {
@@ -2568,9 +2597,15 @@ class Telegram {
if (recuser) { if (recuser) {
this.setPhotoProfile(rec, msg); this.setPhotoProfile(rec, msg);
let username = recuser.name; let username = recuser.name;
this.sendMsg(msg.from.id, this.sendMsg(msg.from.id,
printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, tools.getHostByIdApp(this.idapp))); printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, tools.getHostByIdApp(this.idapp)));
if (msg.from.username) {
askConfirmationUserRegistration(this.idapp,
shared_consts.CallFunz.REGISTRATION, recuser,msg.from.username || '', msg.from.first_name || '', msg.from.last_name || '');
}
this.checkIfUsernameTelegramSet(msg, recuser); this.checkIfUsernameTelegramSet(msg, recuser);
// local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg); // local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg);
} else { } else {
@@ -3098,9 +3133,12 @@ class Telegram {
if (recuser) { if (recuser) {
if (!(recuser.menuSaved[idapp])) if (!(recuser.menuSaved[idapp]))
load = true; load = true;
if (recuser.menuDb || recuser.pageChange)
load = true;
} }
} }
if (load || !recuser.menuDb || recuser.pageChange) { if (load) {
// Check if you are Admin // Check if you are Admin
const user = await User.UserByIdTelegram(idapp, id); const user = await User.UserByIdTelegram(idapp, id);
@@ -3154,7 +3192,7 @@ class Telegram {
recuser.pageChange = false; recuser.pageChange = false;
recuser.menuSaved[idapp] = arrlang; recuser.menuSaved[idapp] = arrlang;
} }
return recuser.menuSaved[idapp]; return recuser ? recuser.menuSaved[idapp] : null;
} catch (e) { } catch (e) {
console.log('Err loadMenuFromDb: ' + e); console.log('Err loadMenuFromDb: ' + e);
} }
@@ -3205,7 +3243,7 @@ class Telegram {
return ''; return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) { } else if (recdb.type === shared_consts.BOTTYPE_MENU) {
if (recdb.value) { if (recdb.value) {
this.isMenu(rec, msg, recdb.value, true); this.isMenu(recuser, msg, recdb.value, true);
return shared_consts.RIS_OK; return shared_consts.RIS_OK;
} }
} }
@@ -3411,18 +3449,24 @@ class Telegram {
const file_path = result.file_path; const file_path = result.file_path;
const photo_url = 'https://api.telegram.org/file/bot' + token + '/' + file_path; const photo_url = 'https://api.telegram.org/file/bot' + token + '/' + file_path;
console.log('photo_url', photo_url); console.log('1) photo_url', photo_url);
let filename = tools.extractFileName(photo_url); let filename = tools.extractFileName(photo_url);
myfileprofile += filename; myfileprofile += filename;
console.log('myfileprofile', myfileprofile);
const pathfile = tools.extractFilePath(myfileprofile);
tools.mkdirpath(pathfile);
console.log('2) myfileprofile', pathfile);
return tools.downloadImage(photo_url, myfileprofile). return tools.downloadImage(photo_url, myfileprofile).
then((ris) => { then((ris) => {
console.log('setPicProfile ris', ris); console.log('3) setPicProfile ris', ris);
return User.setPicProfile(idapp, username, filename).then((ris) => { return User.setPicProfile(idapp, username, filename).then((ris) => {
console.log('sendMsg picprofile Copied !'); console.log('4) sendMsg picprofile Copied !');
local_sendMsgTelegram(idapp, username, printf(getstr(lang, 'MSG_SET_PICPROFILE'), editprofile)); local_sendMsgTelegram(idapp, username, printf(getstr(lang, 'MSG_SET_PICPROFILE'), editprofile));
}); });
// console.log('scaricato'); // console.log('scaricato');
}).catch((err) => {
console.error('Error setPhotoProfile', err);
}); });
}); });

View File

@@ -2626,6 +2626,7 @@ module.exports = {
dest: filepath dest: filepath
}); });
}catch (e) { }catch (e) {
console.error('Err download image', e);
return false; return false;
} }

View File

@@ -96,6 +96,8 @@ module.exports = {
TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups'], TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups'],
TABLES_REC_ID: ['skills', 'goods', 'subskills'], TABLES_REC_ID: ['skills', 'goods', 'subskills'],
TABLES_VISU_STAT_IN_HOME: ['myskills', 'mybachecas', 'mygoods', 'mygroups'],
TABLES_ID_NUMBER: [ TABLES_ID_NUMBER: [
'permissions', 'permissions',
'levels', 'levels',