- Iscrizione Conacreis
- Ordini - Carrello
This commit is contained in:
82
src/server/router/iscrittiConacreis_router.js
Executable file
82
src/server/router/iscrittiConacreis_router.js
Executable file
@@ -0,0 +1,82 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const IscrittiConacreis = require('../models/iscrittiConacreis');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const { Settings } = require('../models/settings');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
|
||||
// POST /iscritti_conacreis
|
||||
router.post('/', async (req, res) => {
|
||||
tools.mylog("POST /iscritti_conacreis");
|
||||
const body = _.pick(req.body, ['idapp', 'userId', 'name', 'surname', 'email', 'fiscalcode', 'residency_address', 'residency_city', 'residency_province', 'residency_country', 'residency_zipcode', 'dateofbirth', 'cell_phone', 'newsletter_on', 'iscrizione_compilata', 'annoTesseramento', 'note', 'accetta_carta_costituzionale_on', 'terms']);
|
||||
body.email = body.email.toLowerCase();
|
||||
|
||||
const iscritti = new IscrittiConacreis(body);
|
||||
iscritti.ipaddr = tools.getiPAddressUser(req);
|
||||
iscritti.lang = req.locale;
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + iscritti.lang, "IDAPP", iscritti.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(iscritti.ipaddr + ': [' + iscritti.username + '] ' + iscritti.name + ' ' + iscritti.surname);
|
||||
await tools.snooze(5000);
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
iscritti.dateofreg = new Date();
|
||||
|
||||
// Controlla se anche l'ultimo record era dallo stesso IP:
|
||||
const lastrec = await IscrittiConacreis.getLastRec(body.idapp);
|
||||
if (!!lastrec) {
|
||||
if (process.env.LOCALE !== "1") {
|
||||
if (lastrec.ipaddr === iscritti.ipaddr) {
|
||||
// Se l'ha fatto troppo ravvicinato
|
||||
if (lastrec.date_reg) {
|
||||
let ris = tools.isdiffSecDateLess(lastrec.date_reg, 120);
|
||||
if (ris) {
|
||||
tools.writeIPToBan(iscritti.ipaddr + ': ' + iscritti.name + ' ' + iscritti.surname);
|
||||
await tools.snooze(10000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_BANIP, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await iscritti.save()
|
||||
.then(async () => {
|
||||
await sendemail.sendEmail_IscrizioneConacreis(iscritti.lang, iscritti.email, iscritti, iscritti.idapp);
|
||||
// }
|
||||
return res.status(200).send();
|
||||
}).catch((e) => {
|
||||
console.error(e.message);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user