- 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

@@ -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;