- Downline User

- Not registered if already exists.
- Forgot Password
This commit is contained in:
Paolo Arena
2020-01-30 01:19:25 +01:00
parent 25ad3e91c2
commit 512a8c14e2
12 changed files with 551 additions and 44 deletions

View File

@@ -5,8 +5,9 @@ var file = `.env.${node_env}`;
// GLOBALI (Uguali per TUTTI)
process.env.LINKVERIF_REG = '/vreg';
process.env.LINK_REQUEST_NEWPASSWORD = '/requestnewpwd';
process.env.LINK_UPDATE_PASSWORD = '/updatepassword';
process.env.LINK_UPDATE_PWD = '/updatepwd';
process.env.LINK_CHECK_UPDATES = '/checkupdates';
process.env.LINK_UPDATE_PASSWORD = '/updatepwd';
process.env.KEY_APP_ID = 'KKPPAA5KJK435J3KSS9F9D8S9F8SD98F9SDF';
console.log("FILE : " + file);

View File

@@ -167,6 +167,28 @@ ExtraListSchema.statics.getUsersList = function (idapp) {
};
ExtraListSchema.statics.getDownlineNotRegisteredByNameSurname = function (idapp, nameandsurname) {
const ExtraList = this;
return ExtraList.find({
'aportador_solidario_name_surname': nameandsurname,
registered: false,
}, {
username: 1,
name: 1,
surname: 1,
verified_email: 1,
'profile.teleg_id': 1,
'profile.saw_zoom_presentation': 1,
made_gift: 1,
email: 1,
date_reg: 1,
img: 1
}, (err, arrrec) => {
return arrrec
});
};
ExtraListSchema.statics.getFieldsForSearch = function () {
return ['username', 'name', 'surname', 'cell_complete', 'aportador_solidario_name_surname', 'aportador_solidario_originale_name_surname']

View File

@@ -332,6 +332,8 @@ UserSchema.statics.getUserShortDataByUsername = function (idapp, username) {
name: 1,
surname: 1,
verified_email: 1,
'profile.teleg_id': 1,
'profile.saw_zoom_presentation': 1,
made_gift: 1,
email: 1,
date_reg: 1,
@@ -357,6 +359,8 @@ UserSchema.statics.getDownlineByUsername = function (idapp, username) {
name: 1,
surname: 1,
verified_email: 1,
'profile.teleg_id': 1,
'profile.saw_zoom_presentation': 1,
made_gift: 1,
email: 1,
date_reg: 1,
@@ -366,17 +370,44 @@ 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,
'profile.teleg_id': { $gt: 1 },
'profile.saw_zoom_presentation': true,
});
};
UserSchema.statics.getUsersNationalityQuery = function (idapp) {
const query = [
{
$match: { idapp }
},
{
$group: { _id: "$profile.nationality", count: { $sum: 1 } }
},
{
$sort: { count: -1 }
}
];
return query
};
UserSchema.statics.getindOrderDuplicate = function (idapp) {
const User = this;
return User.aggregate(User.getUsersNationalityQuery(idapp))
.then(ris => {
// console.table(ris);
return JSON.stringify(ris);
});
};
UserSchema.statics.getnumInvitati = function (idapp, username) {
const User = this;
@@ -462,6 +493,17 @@ UserSchema.statics.getEmailByUsername = async function (idapp, username) {
});
};
UserSchema.statics.getAportadorSolidarioByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username })
.then((rec) => {
return ((rec) ? rec.aportador_solidario : '');
}).catch((e) => {
console.error('getAportadorSolidarioByUsername', e);
});
};
UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
const User = this;
@@ -671,10 +713,18 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
dashboard.aportador = await User.getUserShortDataByUsername(idapp, aportador_solidario);
// Data of my Downline
dashboard.downline = await User.getDownlineByUsername(idapp, username);
const arrap = await User.getDownlineByUsername(idapp, aportador_solidario);
dashboard.numpeople_aportador = arrap.length;
for (let index = 0; index < dashboard.downline.length; ++index) {
dashboard.downline[index].downline = await User.getDownlineByUsername(idapp, dashboard.downline[index].username);
dashboard.downline = await User.getDownlineByUsername(idapp, username);
dashboard.downbyuser = {};
for (const down of dashboard.downline) {
dashboard.downbyuser[down.username] = await User.getDownlineByUsername(idapp, down.username);
for (const down2 of dashboard.downbyuser[down.username]) {
dashboard.downbyuser[down2.username] = await User.getDownlineByUsername(idapp, down2.username);
}
}
return dashboard;
} catch (e) {
@@ -701,6 +751,18 @@ UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_
};
UserSchema.statics.findByCellAndNameSurname = function (idapp, cell, name, surname) {
const User = this;
return User.findOne({
'idapp': idapp,
'profile.cell': cell,
'name': name,
'surname': surname,
});
};
UserSchema.statics.getUsersRegistered = async function (idapp) {
const User = this;
@@ -788,7 +850,7 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
};
UserSchema.statics.getUsersNationalityQuery = function (idapp) {
UserSchema.statics.getDistinctNationalityQuery = function (idapp) {
const query = [
{
$match: { idapp }
@@ -807,7 +869,7 @@ UserSchema.statics.getUsersNationalityQuery = function (idapp) {
UserSchema.statics.findAllDistinctNationality = async function (idapp) {
const User = this;
return User.aggregate(User.getUsersNationalityQuery(idapp))
return User.aggregate(User.getDistinctNationalityQuery(idapp))
.then(ris => {
// console.table(ris);
return JSON.stringify(ris);
@@ -852,6 +914,29 @@ if (tools.INITDB_FIRSTIME) {
// UserSchema.index({ surname: 1 });
}
UserSchema.statics.DbOp = async function (idapp, mydata) {
const User = this;
try {
if (mydata.dbop === 'changeCellInt') {
arrusers = await User.find({ 'idapp': idapp });
let num = 0;
for (const rec of arrusers) {
let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell);
await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } })
num++;
}
return { num };
// return await User.updateMany({ idapp }, { $set: { 'profile.cell': { $concat: ["$profile.intcode_cell", "$profile.cell"] } } })
}
} catch (e) {
console.error(e);
}
};
const User = mongoose.model('User', UserSchema);

View File

@@ -18,10 +18,21 @@ const { ObjectID } = require('mongodb');
router.post('/', authenticate, async (req, res) => {
const idapp = req.body.idapp;
let username = req.body.username;
const aportador_solidario = req.user.aportador_solidario;
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) && (username) !== req.user.username) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
let aportador_solidario = req.user.aportador_solidario;
const dashboard = await User.getDashboard(idapp, aportador_solidario, req.user.username);
if (username) {
aportador_solidario = await User.getAportadorSolidarioByUsername(idapp, username)
} else {
username = req.user.username;
}
const dashboard = await User.getDashboard(idapp, aportador_solidario, username);
if (dashboard)
res.send({ dashboard });
else

View File

@@ -5,6 +5,8 @@ const router = express.Router(),
const jwt = require('jsonwebtoken');
const telegrambot = require('../telegram/telegrambot');
const sendemail = require('../sendemail');
const { authenticate, authenticate_noerror } = require('../middleware/authenticate');
@@ -94,8 +96,9 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => {
const email = body.email;
console.log("POST " + process.env.LINK_REQUEST_NEWPASSWORD + " idapp= " + idapp + " email = " + email);
User.findByEmail(idapp, email).then((user) => {
User.findByEmail(idapp, email).then(async (user) => {
if (!user) {
await tools.snooze(5000);
return res.status(200).send({ code: server_constants.RIS_CODE_EMAIL_NOT_EXIST, msg: '' });
} else {
// Creo il tokenforgot
@@ -118,17 +121,20 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => {
// Invio la Nuova Password richiesta dal reset!
// Ritorna il token per poter effettuare le chiamate...
router.post(process.env.LINK_UPDATE_PASSWORD, (req, res) => {
var body = _.pick(req.body, ['idapp', 'email', 'tokenforgot', 'password']);
var idapp = body.idapp;
var email = body.email;
var tokenforgot = body.tokenforgot;
var password = body.password;
console.log("POST " + process.env.LINK_UPDATE_PASSWORD + " idapp= " + idapp + " email = " + email + " tokenforgot = " + tokenforgot);
router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
const body = _.pick(req.body, ['idapp', 'email', 'tokenforgot', 'password']);
const idapp = body.idapp;
const email = body.email;
const tokenforgot = body.tokenforgot;
const password = body.password;
const msg = "Richiesta Nuova Password: idapp= " + idapp + " email = " + email;
console.log(msg);
telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
User.findByLinkTokenforgot(idapp, email, tokenforgot).then((user) => {
if (!user) {
return res.status(404).send();
return res.send({code: server_constants.RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND});
} else {
// aggiorna la nuova password
user.password = password;
@@ -140,7 +146,7 @@ router.post(process.env.LINK_UPDATE_PASSWORD, (req, res) => {
// Salva lo User
user.save().then(() => {
res.header('x-auth', token).send({ user }); // Ritorna il token di ritorno
res.header('x-auth', token).send({code: server_constants.RIS_CODE_OK}); // Ritorna il token di ritorno
});
})
}

View File

@@ -62,11 +62,11 @@ router.post('/', async (req, res) => {
user.verified_email = true;
}
if (user.profile.intcode_cell) {
if (user.profile.cell.substring(0, user.profile.intcode_cell.length) === user.profile.intcode_cell) {
user.profile.cell = user.profile.cell.substring(user.profile.intcode_cell.length)
}
}
// if (user.profile.intcode_cell) {
// if (user.profile.cell.substring(0, user.profile.intcode_cell.length) === user.profile.intcode_cell) {
// user.profile.cell = user.profile.cell.substring(user.profile.intcode_cell.length)
// }
// }
let exit;
// Check if already esist email or username
@@ -93,9 +93,18 @@ router.post('/', async (req, res) => {
if (exit === 1)
return;
let recuser = null;
recuser = await User.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name, user.surname);
if (recuser) {
// User already registered!
res.status(400).send({ code: server_constants.RIS_CODE_USER_ALREADY_EXIST, msg: '' });
return 1;
}
let recextra = null;
recextra = await ExtraList.findByCellAndNameSurname(user.idapp, getMobileComplete(user), user.name, user.surname);
recextra = await ExtraList.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name, user.surname);
let nomeaportador_corretto = "";
if (recextra) {
nomeaportador_corretto = recextra.aportador_solidario_name_surname;
@@ -103,6 +112,9 @@ router.post('/', async (req, res) => {
nomeaportador_corretto = recextra.aportador_solidario_originale_name_surname;
}
const lastuser = await User.getLastUser(user.idapp);
const lastextra = await ExtraList.getLastUser(user.idapp);
let lastindorder = 0;
@@ -139,10 +151,10 @@ router.post('/', async (req, res) => {
if (already_registered) {
// Check in the extraList if is present!
if (!recextra) {
console.log('Utente non trovato; ', user);
const msg = 'Utente non trovato: ' + user.name + ' ' + user.surname + ' ' + user.profile.nationality + ' ' + user.profile.intcode_cell + user.profile.cell + ' email: ' + user.email + ' username: ' + user.username;
const msg = 'Utente non trovato: ' + user.name + ' ' + user.surname + ' ' + user.profile.nationality + ' ' + user.profile.cell + ' email: ' + user.email + ' username: ' + user.username;
console.log('Utente non trovato; ', msg);
telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
res.status(400).send({ code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND, msg: '' });
res.status(400).send({ code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND, msg: 'Controlla se il numero ' + user.profile.cell + ' è corretto.' });
return 1;
} else {
user.ind_order = recextra.ind_order;
@@ -267,11 +279,12 @@ router.post('/login', (req, res) => {
let resalreadysent = false;
User.findByCredentials(user.idapp, user.username, user.password)
.then((user) => {
.then(async (user) => {
// tools.mylog("CREDENZIALI ! ");
if (!user) {
tools.mylogshow("Errore LOGIN ! Username o password Errati: ", body.username, body.password);
await tools.snooze(3000);
const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
tools.mylogshow(msg);
telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
}
@@ -363,5 +376,17 @@ router.post('/import_extralist', async (req, res) => {
res.send(ris);
});
router.post('/dbop', async (req, res) => {
const mydata = req.body.mydata;
idapp = req.body.idapp;
locale = req.body.locale;
const ris = await User.DbOp(idapp, mydata);
console.log('ris', ris);
res.send(ris);
});
module.exports = router;

View File

@@ -147,8 +147,8 @@ module.exports = {
strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINKVERIF_REG + `?idapp=${idapp}&idlink=${idreg}`;
return strlinkreg;
},
getlinkRequestNewPassword: function (idapp, username, tokenforgot) {
strlinkreg = tools.getHostByIdApp(idapp) + "/#" + process.env.LINK_REQUEST_NEWPASSWORD + `?idapp=${idapp}&username=${username}&=tokenforgot=${tokenforgot}`;
getlinkRequestNewPassword: function (idapp, email, tokenforgot) {
strlinkreg = tools.getHostByIdApp(idapp) + process.env.LINK_UPDATE_PASSWORD + `?idapp=${idapp}&email=${email}&tokenforgot=${tokenforgot}`;
return strlinkreg;
},
sendEmail_Registration: async function (lang, emailto, user, idapp, idreg) {
@@ -191,7 +191,7 @@ module.exports = {
name: user.name,
username: user.username,
surname: user.surname,
strlinksetpassword: this.getlinkRequestNewPassword(idapp, user.username, tokenforgot),
strlinksetpassword: this.getlinkRequestNewPassword(idapp, emailto, tokenforgot),
emailto: emailto,
};

View File

@@ -66,7 +66,7 @@ const Menu = {
LINK_CONDIVIDERE: emoji.get('link') + ' Link da condividere',
ZOOM: emoji.get('information_source') + ' Zoom (Conferenze)',
INFO: emoji.get('information_source') + ' Informazioni',
ASSISTENZA: emoji.get('open_hands') + ' Assistenza',
ASSISTENZA: emoji.get('open_hands') + ' Chat e Assistenza',
ADMIN: emoji.get('information_desk_person') + ' Admin',
ALTRO: emoji.get('newspaper') + ' Altro',

View File

@@ -43,7 +43,7 @@ textlang = {
"Nuova Registrazione": "Nuova Registrazione",
"Effettuata una Nuova Registrazione": "Effettuata una Nuova Registrazione",
"partecipanti": "partecipanti",
'TESTO_ASSISTENZA': "Chat d'Aiuto e Supporto: 'AYNI Help & Support'\nEntra in questa chat:\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n\n1 - Poni il tuo quesito, chiedi assistenza.\n2 - Terminata l\'assistenza, uscirete da quella Chat.\n\nPotrete rientrare tutte le volte che ce ne sia necessità.",
'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI-BiblioBacheca: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI Help & Support'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Poni il tuo quesito, chiedi assistenza.\n2 - Terminata l\'assistenza, uscirete da quella Chat.\nPotrete rientrare tutte le volte che ce ne sia necessità." ,
'BENVENUTO': "Benvenuto",
'EMAIL_VERIF': "Email Verificata",
'EMAIL_NON_VERIF': "Email Non Verificata\nleggi la tua casella email e trova **\"Confermare la Registrazione a Ayni\"**<br>e clicca sul bottone **\"Verifica Registrazione\"**",
@@ -59,7 +59,7 @@ textlang = {
"Effettuata una Nuova Registrazione": "Se ha realizado un nuevo registro",
"partecipanti": "participantes",
'TESTO_ASSISTENZA': "Chat d'Aiuto e Supporto: 'AYNI Help & Support'\nEntra in questa chat:\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n\n1 - Poni il tuo quesito, chiedi assistenza.\n2 - Terminata l\'assistenza, uscirete da quella Chat.\n\nPotrete rientrare tutte le volte che ce ne sia necessità.",
'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI-BiblioBacheca: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI Help & Support'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Poni il tuo quesito, chiedi assistenza.\n2 - Terminata l\'assistenza, uscirete da quella Chat.\nPotrete rientrare tutte le volte che ce ne sia necessità." ,
'BENVENUTO': "Benvenuto",
'EMAIL_VERIF': "Email Verificata",
'EMAIL_NON_VERIF': "Email Non Verificata\nleggi la tua casella email e trova **\"Confermare la Registrazione a Ayni\"**<br>e clicca sul bottone **\"Verifica Registrazione\"**",
@@ -71,7 +71,7 @@ textlang = {
},
us: {
"partecipanti": "participants",
'TESTO_ASSISTENZA': "Chat d'Aiuto e Supporto: 'AYNI Help & Support'\nEntra in questa chat:\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n\n1 - Poni il tuo quesito, chiedi assistenza.\n2 - Terminata l\'assistenza, uscirete da quella Chat.\n\nPotrete rientrare tutte le volte che ce ne sia necessità.",
'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI-BiblioBacheca: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI Help & Support'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Poni il tuo quesito, chiedi assistenza.\n2 - Terminata l\'assistenza, uscirete da quella Chat.\nPotrete rientrare tutte le volte che ce ne sia necessità." ,
'BENVENUTO': "Benvenuto",
'EMAIL_VERIF': "Email Verificata",
'EMAIL_NON_VERIF': "Email Non Verificata\nleggi la tua casella email e trova **\"Confermare la Registrazione a Ayni\"**<br>e clicca sul bottone **\"Verifica Registrazione\"**",
@@ -545,6 +545,10 @@ module.exports = {
query.push(mysort)
}
let numrowend = params.endRow - params.startRow;
if (numrowend < 0)
numrowend = 1;
query.push(
{
$group: {
@@ -559,7 +563,7 @@ module.exports = {
{
$project: {
count: 1,
rows: { $slice: ['$results', params.startRow, params.endRow - params.startRow] }
rows: { $slice: ['$results', params.startRow, numrowend] }
}
}
);
@@ -845,6 +849,10 @@ module.exports = {
} catch (e) {
return ''
}
}
},
removespaces(mystr) {
return mystr.replace(/\s+/g, '')
},
};

View File

@@ -10,6 +10,7 @@ module.exports = Object.freeze({
RIS_CODE_USER_EXTRALIST_NOTFOUND: -70,
RIS_CODE_USERNAME_ALREADY_EXIST: -60,
RIS_CODE_EMAIL_ALREADY_EXIST: -50,
RIS_CODE_USER_ALREADY_EXIST: -48,
RIS_CODE_EMAIL_NOT_EXIST: -45,
RIS_CODE_EMAIL_NOT_SENT: -40,
RIS_CODE_ERR_UNAUTHORIZED: -30,
@@ -20,6 +21,7 @@ module.exports = Object.freeze({
RIS_CODE_LOGIN_OK: 1,
RIS_CODE_HTTP_INVALID_TOKEN: 403,
RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND: -23,
RIS_SUBSCRIBED_OK: 1,
RIS_SUBSCRIBED_ALREADYEXIST: 2,