Doppia modalità di Registrazione con lista extra utenti
This commit is contained in:
@@ -33,6 +33,13 @@ ContribtypeSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
ContribtypeSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
|
||||
ContribtypeSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Contribtype = this;
|
||||
|
||||
|
||||
@@ -97,6 +97,12 @@ DisciplineSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
DisciplineSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
const Discipline = mongoose.model('Discipline', DisciplineSchema);
|
||||
|
||||
module.exports = { Discipline };
|
||||
|
||||
265
src/server/models/extralist.js
Normal file
265
src/server/models/extralist.js
Normal file
@@ -0,0 +1,265 @@
|
||||
var bcrypt = require('bcryptjs');
|
||||
const mongoose = require('mongoose');
|
||||
const validator = require('validator');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const _ = require('lodash');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
mongoose.level = "F";
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
mongoose.set('debug', process.env.DEBUG);
|
||||
|
||||
var ExtraListSchema = new mongoose.Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
date_reg: {
|
||||
type: Date,
|
||||
},
|
||||
name_complete: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
surname: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
num_invitati: {
|
||||
type: Number,
|
||||
},
|
||||
is_in_whatsapp: {
|
||||
type: Boolean,
|
||||
},
|
||||
is_in_telegram: {
|
||||
type: Boolean,
|
||||
},
|
||||
cell_complete: {
|
||||
type: String
|
||||
},
|
||||
nationality: {
|
||||
type: String
|
||||
},
|
||||
aportador_solidario_name_surname: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
aportador_solidario_originale_name_surname: {
|
||||
type: String,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
col_b: {
|
||||
type: Number,
|
||||
},
|
||||
col_h: {
|
||||
type: Number,
|
||||
},
|
||||
registered: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ExtraListSchema.methods.toJSON = function () {
|
||||
var user = this;
|
||||
var userObject = user.toObject();
|
||||
|
||||
return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]);
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.findByUsername = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.findByCellAndNameSurname = function (idapp, cell_complete, name, surname) {
|
||||
var User = this;
|
||||
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'cell_complete': cell_complete,
|
||||
'name': name,
|
||||
'surname': surname,
|
||||
});
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.getUsersList = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return User.find({ 'idapp': idapp }, {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
date_reg: 1,
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.getFieldsForSearch = function () {
|
||||
return ['name', 'surname', 'cell_complete', 'aportador_solidario_name_surname', 'aportador_solidario_originale_name_surname']
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.findAllIdApp = function (idapp) {
|
||||
const ExtraList = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return ExtraList.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.ImportData = async function (locale, idapp, strdata) {
|
||||
|
||||
const ExtraList = this;
|
||||
|
||||
try {
|
||||
let numadded = 0;
|
||||
let numtot = 0;
|
||||
let numalreadyexisted = 0;
|
||||
|
||||
// Convert to array
|
||||
let arrusers = strdata.split('\n');
|
||||
let sep = ',';
|
||||
|
||||
// console.log('arrusers', arrusers);
|
||||
|
||||
try {
|
||||
for (const row of arrusers) {
|
||||
console.log('row', row);
|
||||
if (sep !== '' && row !== '') {
|
||||
let col = row.split(sep);
|
||||
if (col) {
|
||||
if (col.length > 0) {
|
||||
let user = null;
|
||||
try {
|
||||
user = new ExtraList({
|
||||
idapp: idapp,
|
||||
ind_order: col[0],
|
||||
name_complete: col[2],
|
||||
num_invitati: col[3],
|
||||
is_in_whatsapp: col[4] !== '',
|
||||
is_in_telegram: col[5] !== '',
|
||||
cell_complete: col[6],
|
||||
nationality: col[7],
|
||||
aportador_solidario_name_surname: col[8],
|
||||
aportador_solidario_ind_order: col[9],
|
||||
aportador_solidario_originale_name_surname: col[10],
|
||||
note: col[11],
|
||||
col_b: col[12],
|
||||
col_h: col[13]
|
||||
});
|
||||
|
||||
try {
|
||||
user.date_reg = col[1];
|
||||
} catch (e) {
|
||||
console.log('error ', e);
|
||||
}
|
||||
|
||||
namesurname = tools.extractNameAndSurnameByComplete(user.name_complete);
|
||||
user.name = namesurname.name;
|
||||
user.surname = namesurname.surname;
|
||||
|
||||
if (user.name && user.surname && user.cell_complete) {
|
||||
// Save into db
|
||||
await user.save();
|
||||
numadded++;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log('error ', e, col);
|
||||
}
|
||||
|
||||
numtot++;
|
||||
}
|
||||
// numalreadyexisted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
ris = { numadded, numtot, numalreadyexisted };
|
||||
|
||||
console.log(ris);
|
||||
return ris
|
||||
|
||||
} catch (e) {
|
||||
console.err(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
console.log(' createIndex User Index...');
|
||||
// ExtraListSchema.index({ username: 'text', name: 'text', surname: 'text', email: 'text' });
|
||||
// ExtraListSchema.index({ name: 'name' });
|
||||
// ExtraListSchema.index({ name: 1 });
|
||||
// ExtraListSchema.index({ surname: 1 });
|
||||
}
|
||||
|
||||
const ExtraList = mongoose.model('ExtraList', ExtraListSchema);
|
||||
|
||||
|
||||
module.exports = { ExtraList };
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ MailingListSchema.statics.getnumSent = async function (idapp, idmailinglist) {
|
||||
|
||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||
|
||||
return await MailingList.find(myfind).count();
|
||||
return await MailingList.countDocuments(myfind);
|
||||
};
|
||||
|
||||
MailingListSchema.statics.isOk = async function (idapp, iduser, idmailinglist) {
|
||||
@@ -82,7 +82,7 @@ MailingListSchema.statics.isOk = async function (idapp, iduser, idmailinglist) {
|
||||
|
||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||
|
||||
return await MailingList.find(myfind).count() > 0;
|
||||
return await MailingList.countDocuments(myfind) > 0;
|
||||
};
|
||||
|
||||
MailingListSchema.statics.findAllIdApp = async function (idapp) {
|
||||
|
||||
@@ -32,7 +32,6 @@ OpzEmailSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
|
||||
OpzEmailSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const OpzEmail = this;
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
@@ -73,16 +75,27 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key, def) {
|
||||
|
||||
};
|
||||
|
||||
SettingsSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
SettingsSchema.statics.findAllIdApp = function (idapp, serv) {
|
||||
const Settings = this;
|
||||
|
||||
const myfind = { idapp, serv };
|
||||
let myfind = '';
|
||||
if (serv)
|
||||
myfind = { idapp, serv };
|
||||
else
|
||||
myfind = { idapp };
|
||||
|
||||
return Settings.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const Settings = mongoose.model('Settings', SettingsSchema);
|
||||
|
||||
module.exports = { Settings };
|
||||
|
||||
@@ -49,6 +49,12 @@ TemplEmailSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
TemplEmailSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
|
||||
TemplEmailSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const TemplEmail = this;
|
||||
|
||||
@@ -163,7 +163,7 @@ TodoSchema.statics.findAllByUserIdAndCat = function (userId) {
|
||||
TodoSchema.statics.getArrIdParentInTable = function (userId) {
|
||||
var Todo = this;
|
||||
|
||||
return Todo.find(getQueryFilterTodo(userId)).distinct("category")
|
||||
return Todo.find(getQueryFilterTodo(userId)[0]).distinct("category")
|
||||
.then(arrcategory => {
|
||||
return arrcategory
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var bcrypt = require('bcryptjs');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const mongoose = require('mongoose');
|
||||
const validator = require('validator');
|
||||
const jwt = require('jsonwebtoken');
|
||||
@@ -19,10 +19,13 @@ mongoose.plugin(schema => {
|
||||
|
||||
mongoose.set('debug', process.env.DEBUG);
|
||||
|
||||
var UserSchema = new mongoose.Schema({
|
||||
const UserSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
already_registered: {
|
||||
type: Boolean,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -38,6 +41,9 @@ var UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
ind_order: {
|
||||
type: Number
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -114,6 +120,12 @@ var UserSchema = new mongoose.Schema({
|
||||
aportador_solidario: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_nome_completo: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
profile: {
|
||||
img: {
|
||||
type: String
|
||||
@@ -160,15 +172,15 @@ var UserSchema = new mongoose.Schema({
|
||||
});
|
||||
|
||||
UserSchema.methods.toJSON = function () {
|
||||
var user = this;
|
||||
var userObject = user.toObject();
|
||||
const user = this;
|
||||
const userObject = user.toObject();
|
||||
|
||||
return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]);
|
||||
};
|
||||
|
||||
UserSchema.methods.generateAuthToken = function (req) {
|
||||
// console.log("GENERA TOKEN : ");
|
||||
var user = this;
|
||||
const user = this;
|
||||
|
||||
const useragent = req.get('User-Agent');
|
||||
// tools.mylog("GENERATE USER-AGENT = ", useragent);
|
||||
@@ -208,7 +220,7 @@ UserSchema.statics.setPermissionsById = function (id, perm) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.isAdmin = function (user) {
|
||||
UserSchema.statics.isAdmin = function (perm) {
|
||||
try {
|
||||
return ((perm & shared_consts.Permissions.Admin) === shared_consts.Permissions.Admin);
|
||||
} catch (e) {
|
||||
@@ -242,8 +254,8 @@ UserSchema.statics.findByToken = function (token, typeaccess) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByTokenAnyAccess = function (token) {
|
||||
var User = this;
|
||||
var decoded;
|
||||
const User = this;
|
||||
let decoded;
|
||||
|
||||
try {
|
||||
decoded = jwt.verify(token, process.env.SIGNCODE);
|
||||
@@ -258,8 +270,8 @@ UserSchema.statics.findByTokenAnyAccess = function (token) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByCredentials = function (idapp, username, password) {
|
||||
var User = this;
|
||||
var pwd = "";
|
||||
const User = this;
|
||||
let pwd = "";
|
||||
|
||||
return User.findOne({ idapp, username: username }).then((user) => {
|
||||
if (!user) {
|
||||
@@ -345,7 +357,7 @@ UserSchema.statics.getDownlineByUsername = function (idapp, username) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
var User = this;
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'linkreg': linkreg,
|
||||
@@ -354,7 +366,7 @@ UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot) {
|
||||
var User = this;
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'email': email,
|
||||
@@ -366,7 +378,7 @@ UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot)
|
||||
|
||||
|
||||
UserSchema.statics.findByEmail = function (idapp, email) {
|
||||
var User = this;
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
@@ -375,7 +387,7 @@ UserSchema.statics.findByEmail = function (idapp, email) {
|
||||
};
|
||||
|
||||
UserSchema.pre('save', function (next) {
|
||||
var user = this;
|
||||
const user = this;
|
||||
|
||||
|
||||
/*
|
||||
@@ -396,7 +408,7 @@ UserSchema.pre('save', function (next) {
|
||||
UserSchema.methods.removeToken = function (token) {
|
||||
const user = this;
|
||||
|
||||
return user.update({
|
||||
return user.updateOne({
|
||||
$pull: {
|
||||
tokens: { token }
|
||||
}
|
||||
@@ -552,6 +564,22 @@ UserSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
UserSchema.statics.findAllIdApp = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return User.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, username) {
|
||||
try {
|
||||
|
||||
@@ -577,6 +605,24 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_order, username) {
|
||||
const User = this;
|
||||
|
||||
// Check if somewhere there is my username
|
||||
return User.find({ idapp, aportador_solidario_ind_order }, async (err, arrrec) => {
|
||||
if (arrrec) {
|
||||
for (const myuser of arrrec) {
|
||||
if (!myuser.aportador_solidario || myuser.aportador_solidario === tools.APORTADOR_NONE) {
|
||||
myuser.aportador_solidario = username;
|
||||
await myuser.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
console.log(' createIndex User Index...');
|
||||
|
||||
Reference in New Issue
Block a user