++ diffusori
fixed user chip
This commit is contained in:
100
mongodb/Diffusori.mongodb
Normal file
100
mongodb/Diffusori.mongodb
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
// MongoDB Playground
|
||||||
|
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
|
||||||
|
// Make sure you are connected to enable completions and to be able to run a playground.
|
||||||
|
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
|
||||||
|
|
||||||
|
// Select the database to use.
|
||||||
|
use('test_FreePlanet');
|
||||||
|
|
||||||
|
let aggregation = [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
idapp: "13",
|
||||||
|
$or: [
|
||||||
|
{
|
||||||
|
deleted: {
|
||||||
|
$exists: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deleted: {
|
||||||
|
$exists: true,
|
||||||
|
$eq: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: "$aportador_solidario",
|
||||||
|
count: {
|
||||||
|
$sum: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$match: { "count": { $gte: 2 } }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$sort: {
|
||||||
|
count: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: "users",
|
||||||
|
let: {
|
||||||
|
username: "$_id",
|
||||||
|
idapp: "13",
|
||||||
|
},
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
$eq: [
|
||||||
|
"$$username",
|
||||||
|
"$username",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$eq: [
|
||||||
|
"$$idapp",
|
||||||
|
"$idapp",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
as: "user",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $unwind: "$user" },
|
||||||
|
{
|
||||||
|
$replaceRoot: {
|
||||||
|
newRoot: {
|
||||||
|
$mergeObjects: [ "$user", "$$ROOT" ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$project: {
|
||||||
|
_id: 0,
|
||||||
|
count: 1,
|
||||||
|
aportador_solidario: 1,
|
||||||
|
username: 1,
|
||||||
|
name: 1,
|
||||||
|
surname: 1,
|
||||||
|
lasttimeonline: 1,
|
||||||
|
idapp: 1,
|
||||||
|
"profile.img": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
db.users.aggregate(aggregation);
|
||||||
|
|
||||||
@@ -136,6 +136,9 @@ const UserSchema = new mongoose.Schema({
|
|||||||
tokenforgot: {
|
tokenforgot: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
tokenforgot_code: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
date_tokenreg: {
|
date_tokenreg: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
@@ -1164,6 +1167,17 @@ UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot)
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.findByLinkTokenforgotCode = function (idapp, email, tokenforgot_code) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
return User.findOne({
|
||||||
|
email,
|
||||||
|
tokenforgot_code,
|
||||||
|
date_tokenforgot: { $gte: tools.IncDateNow(-1000 * 60 * 60 * 4) }, // 4 ore fa!
|
||||||
|
idapp,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.createNewRequestPwd = function (idapp, email) {
|
UserSchema.statics.createNewRequestPwd = function (idapp, email) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
@@ -1177,9 +1191,10 @@ UserSchema.statics.createNewRequestPwd = function (idapp, email) {
|
|||||||
user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
||||||
toString();
|
toString();
|
||||||
user.date_tokenforgot = new Date();
|
user.date_tokenforgot = new Date();
|
||||||
|
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||||
user.lasttimeonline = new Date();
|
user.lasttimeonline = new Date();
|
||||||
return await user.save().then(async () => {
|
return await user.save().then(async () => {
|
||||||
await sendemail.sendEmail_RequestNewPassword(user.lang, user, user.email, user.idapp, user.tokenforgot);
|
await sendemail.sendEmail_RequestNewPassword(user.lang, user, user.email, user.idapp, user.tokenforgot, user.tokenforgot_code);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -1202,10 +1217,12 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function (ida
|
|||||||
user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
||||||
toString();
|
toString();
|
||||||
user.date_tokenforgot = new Date();
|
user.date_tokenforgot = new Date();
|
||||||
|
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||||
user.lasttimeonline = new Date();
|
user.lasttimeonline = new Date();
|
||||||
|
user.code_pwd_reset = 0;
|
||||||
|
|
||||||
return await user.save().then(() => {
|
return await user.save().then(() => {
|
||||||
return tools.getlinkRequestNewPassword(idapp, user.email, user.tokenforgot);
|
return tools.getlinkRequestNewPassword(idapp, user.email, user.tokenforgot, user.tokenforgot_code);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3501,6 +3518,18 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.getDiffusoriUsers = async function (idapp) {
|
||||||
|
const User = this;
|
||||||
|
|
||||||
|
const lastn = 10;
|
||||||
|
|
||||||
|
return await User.aggregate(User.getQueryUsersDiffusori(idapp)).then(ris => {
|
||||||
|
// console.table(ris);
|
||||||
|
return ris;
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.checkUser = async function (idapp, username) {
|
UserSchema.statics.checkUser = async function (idapp, username) {
|
||||||
const User = this;
|
const User = this;
|
||||||
|
|
||||||
@@ -3580,6 +3609,7 @@ UserSchema.statics.findAllDistinctNationality = async function (idapp) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
|
UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
|
||||||
|
|
||||||
const query = [
|
const query = [
|
||||||
@@ -3611,6 +3641,101 @@ UserSchema.statics.getUsersRegDaily = function (idapp, nrec) {
|
|||||||
return query;
|
return query;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.getQueryUsersDiffusori = function (idapp) {
|
||||||
|
|
||||||
|
const query = [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
idapp,
|
||||||
|
$or: [
|
||||||
|
{
|
||||||
|
deleted: {
|
||||||
|
$exists: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deleted: {
|
||||||
|
$exists: true,
|
||||||
|
$eq: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: "$aportador_solidario",
|
||||||
|
count: {
|
||||||
|
$sum: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$match: { "count": { $gte: 2 } }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$sort: {
|
||||||
|
count: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $limit: 20 },
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: "users",
|
||||||
|
let: {
|
||||||
|
username: "$_id",
|
||||||
|
idapp,
|
||||||
|
},
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
$eq: [
|
||||||
|
"$$username",
|
||||||
|
"$username",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$eq: [
|
||||||
|
"$$idapp",
|
||||||
|
"$idapp",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
as: "user",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $unwind: "$user" },
|
||||||
|
{
|
||||||
|
$replaceRoot: {
|
||||||
|
newRoot: {
|
||||||
|
$mergeObjects: [ "$user", "$$ROOT" ],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$project: {
|
||||||
|
_id: 0,
|
||||||
|
count: 1,
|
||||||
|
aportador_solidario: 1,
|
||||||
|
username: 1,
|
||||||
|
name: 1,
|
||||||
|
surname: 1,
|
||||||
|
lasttimeonline: 1,
|
||||||
|
idapp: 1,
|
||||||
|
"profile.img": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return query;
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.getUsersRegWeekly = function (idapp, nrec) {
|
UserSchema.statics.getUsersRegWeekly = function (idapp, nrec) {
|
||||||
|
|
||||||
const query = [
|
const query = [
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -48,6 +48,7 @@ router.post('/load', async (req, res) => {
|
|||||||
reg_weekly: await User.calcRegWeekly(idapp),
|
reg_weekly: await User.calcRegWeekly(idapp),
|
||||||
lastsreg: await User.getLastUsers(idapp),
|
lastsreg: await User.getLastUsers(idapp),
|
||||||
lastsonline: await User.getLastOnlineUsers(idapp),
|
lastsonline: await User.getLastOnlineUsers(idapp),
|
||||||
|
diffusorilist: await User.getDiffusoriUsers(idapp),
|
||||||
checkuser: await User.checkUser(idapp, username),
|
checkuser: await User.checkUser(idapp, username),
|
||||||
// navi_partite: await Nave.getNaviPartite(idapp),
|
// navi_partite: await Nave.getNaviPartite(idapp),
|
||||||
// navi_in_partenza: await Nave.getNaviInPartenza(idapp),
|
// navi_in_partenza: await Nave.getNaviInPartenza(idapp),
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sendEmail_RequestNewPassword: async function(lang, user, emailto, idapp, tokenforgot) {
|
sendEmail_RequestNewPassword: async function(lang, user, emailto, idapp, tokenforgot, tokenforgot_code) {
|
||||||
|
|
||||||
let mylocalsconf = {
|
let mylocalsconf = {
|
||||||
idapp,
|
idapp,
|
||||||
@@ -286,6 +286,7 @@ module.exports = {
|
|||||||
locale: lang,
|
locale: lang,
|
||||||
nomeapp: tools.getNomeAppByIdApp(idapp),
|
nomeapp: tools.getNomeAppByIdApp(idapp),
|
||||||
strlinksetpassword: tools.getlinkRequestNewPassword(idapp, emailto, tokenforgot),
|
strlinksetpassword: tools.getlinkRequestNewPassword(idapp, emailto, tokenforgot),
|
||||||
|
tokenforgot_code,
|
||||||
emailto: emailto,
|
emailto: emailto,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user