fix Registrazione data

fix linkref
fix controllo login
This commit is contained in:
Paolo Arena
2020-01-20 01:48:25 +01:00
parent e23a3a792e
commit 6dcaea5f1c
21 changed files with 779 additions and 171 deletions

View File

@@ -6,6 +6,8 @@ const _ = require('lodash');
const tools = require('../tools/general');
const { Settings } = require('../models/settings');
const shared_consts = require('../tools/shared_nodejs');
const queryclass = require('../classes/queryclass');
@@ -23,9 +25,6 @@ const UserSchema = new mongoose.Schema({
userId: {
type: String,
},
already_registered: {
type: Boolean,
},
email: {
type: String,
required: true,
@@ -103,7 +102,9 @@ const UserSchema = new mongoose.Schema({
},
date_reg: {
type: Date,
default: Date.now()
},
date_temp_reg: {
type: Date,
},
date_tokenforgot: {
type: Date
@@ -126,6 +127,9 @@ const UserSchema = new mongoose.Schema({
aportador_solidario_ind_order: {
type: Number,
},
note: {
type: String,
},
profile: {
img: {
type: String
@@ -164,6 +168,12 @@ const UserSchema = new mongoose.Schema({
dateofbirth: {
type: Date,
},
my_dream: {
type: String,
},
saw_zoom_presentation: {
type: Boolean
},
sex: {
type: Number,
},
@@ -347,7 +357,7 @@ UserSchema.statics.getDownlineByUsername = function (idapp, username) {
name: 1,
surname: 1,
verified_email: 1,
made_gift: 11,
made_gift: 1,
email: 1,
date_reg: 1,
img: 1
@@ -356,6 +366,26 @@ UserSchema.statics.getDownlineByUsername = function (idapp, username) {
});
};
UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) {
const User = this;
return User.count({
idapp,
aportador_solidario: username,
teleg_id: { $gt: 1 },
saw_zoom_presentation: true,
});
};
UserSchema.statics.getnumInvitati = function (idapp, username) {
const User = this;
return User.count({
idapp,
aportador_solidario: username,
});
};
UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
const User = this;
@@ -440,7 +470,7 @@ UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
UserSchema.statics.TelegIdByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username }, {'profile.teleg_id': 1})
return await User.findOne({ idapp, username }, { 'profile.teleg_id': 1 })
.then((rec) => {
return (!!rec) ? rec.profile.teleg_id : null;
}).catch((e) => {
@@ -484,7 +514,7 @@ UserSchema.statics.SetTelegramIdSuccess = async function (idapp, username, teleg
UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username }, {name: 1, surname: 1})
return await User.findOne({ idapp, username }, { name: 1, surname: 1 })
.then((rec) => {
return (!!rec) ? `${rec.name} ${rec.surname}` : '';
}).catch((e) => {
@@ -493,11 +523,10 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
};
UserSchema.statics.getusersManagers = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.manage_telegram': true }, {'profile.teleg_id': 1})
return await User.find({ idapp, 'profile.manage_telegram': true }, { 'profile.teleg_id': 1 })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -505,6 +534,29 @@ UserSchema.statics.getusersManagers = async function (idapp) {
});
};
UserSchema.statics.getUsersTelegALL = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } }, { 'profile.teleg_id': 1 })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
console.error('getusersManagers', e);
});
};
UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) {
const User = this;
return await User.findOne({ idapp, 'profile.manage_telegram': true, 'profile.teleg_id': idtelegram }, { 'profile.teleg_id': 1 })
.then((rec) => {
return (!!rec && rec.profile.teleg_id === idtelegram);
}).catch((e) => {
console.error('getusersManagers', e);
return false
});
};
UserSchema.statics.getUsersList = function (idapp) {
const User = this;
@@ -523,7 +575,6 @@ UserSchema.statics.getUsersList = function (idapp) {
};
UserSchema.statics.getUsersListByParams = function (params) {
const User = this;
@@ -623,6 +674,46 @@ UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_
};
UserSchema.statics.getUsersRegistered = async function (idapp) {
const User = this;
const myfind = { idapp };
return await User.count(myfind);
};
UserSchema.statics.getLastUsers = async function (idapp) {
const User = this;
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5);
return await User.find({ idapp }).sort({ date_temp_reg: -1 }).limit(lastn);
};
UserSchema.statics.checkUser = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username }, {
verified_email: 1,
'profile.teleg_id': 1,
'profile.teleg_checkcode': 1,
});
};
UserSchema.statics.calculateStat = async function (idapp, username) {
const User = this;
return calcstat = {
numinvitati: await User.getnumInvitati(idapp, username),
numinvitati_attivi: await User.getnumInvitatiAttivi(idapp, username),
};
};
if (tools.INITDB_FIRSTIME) {
console.log(' createIndex User Index...');