- Iscrizione Conacreis
This commit is contained in:
@@ -293,94 +293,6 @@ router.post('/', async (req, res) => {
|
||||
})
|
||||
});
|
||||
|
||||
// POST /users/iscriviti_conacreis
|
||||
router.post('/iscriviti_conacreis', async (req, res) => {
|
||||
tools.mylog("POST /users");
|
||||
const body = _.pick(req.body, ['name', 'surname', 'email', 'fiscalcode', 'residency_address', 'residency_city', 'residency_province', 'residency_country', 'residency_zipcode', 'dateofbirth', 'cell_phone', 'newsletter_on']);
|
||||
body.email = body.email.toLowerCase();
|
||||
|
||||
const user = new User(body);
|
||||
user.ipaddr = tools.getiPAddressUser(req);
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
||||
|
||||
if (!tools.isAlphaNumeric(body.name)) {
|
||||
await tools.snooze(5000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_NOT_VALID, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tools.blockwords(body.email) || tools.blockwords(body.name) || tools.blockwords(body.surname)) {
|
||||
// tools.writeIPToBan(user.ipaddr + ': [' + user.username + '] ' + user.name + ' ' + user.surname);
|
||||
await tools.snooze(5000);
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
|
||||
user.date_reg = new Date();
|
||||
|
||||
// Controlla se anche l'ultimo record era dallo stesso IP:
|
||||
const lastrec = await User.getLastRec(body.idapp);
|
||||
if (!!lastrec) {
|
||||
if (process.env.LOCALE !== "1") {
|
||||
if (lastrec.ipaddr === user.ipaddr) {
|
||||
// Se l'ha fatto troppo ravvicinato
|
||||
if (lastrec.date_reg) {
|
||||
let ris = tools.isdiffSecDateLess(lastrec.date_reg, 120);
|
||||
if (ris) {
|
||||
tools.writeIPToBan(user.ipaddr + ': ' + user.name + ' ' + user.surname);
|
||||
await tools.snooze(10000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_BANIP, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await user.save()
|
||||
.then(async () => {
|
||||
return await User.findByUsername(user.idapp, user.username, false)
|
||||
.then((usertrovato) => {
|
||||
|
||||
// tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato);
|
||||
if (usertrovato !== null) {
|
||||
return user.generateAuthToken(req);
|
||||
} else {
|
||||
res.status(400).send();
|
||||
return 0;
|
||||
}
|
||||
})
|
||||
.then(async (token) => {
|
||||
// tools.mylog("passo il TOKEN: ", token);
|
||||
|
||||
if (recextra) {
|
||||
recextra.registered = true;
|
||||
recextra.username = user.username;
|
||||
await recextra.save();
|
||||
|
||||
// await User.fixUsername(user.idapp, user.ind_order, user.username);
|
||||
}
|
||||
return token;
|
||||
})
|
||||
.then(async (token) => {
|
||||
|
||||
// tools.mylog("LINKREG = " + user.linkreg);
|
||||
// Invia un'email all'utente
|
||||
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
||||
console.log('res.locale', res.locale);
|
||||
// if (!tools.testing()) {
|
||||
await sendemail.sendEmail_Registration(user.lang, user.email, user, user.idapp, user.linkreg);
|
||||
// }
|
||||
res.header('x-auth', token).send(user);
|
||||
return true;
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error(e.message);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
});
|
||||
|
||||
router.get('/:idapp/:username', async (req, res) => {
|
||||
var username = req.params.username;
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
Reference in New Issue
Block a user