Doppia modalità di Registrazione con lista extra utenti

This commit is contained in:
Paolo Arena
2020-01-13 23:52:51 +01:00
parent 8f784df4fa
commit e23a3a792e
25 changed files with 829 additions and 163 deletions

View File

@@ -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...');