Richiesta Cambio Password: ti manda il codice a 6 cifre e poterlo inserire sulla APP.

This commit is contained in:
Surya Paolo
2022-12-11 18:04:02 +01:00
parent 3eef70f3f3
commit 1d7a98fc3f
4 changed files with 102 additions and 37 deletions

View File

@@ -135,26 +135,34 @@ router.post(process.env.LINKVERIF_REG, (req, res) => {
// Faccio richiesta di una Nuova Password
router.post(process.env.LINK_REQUEST_NEWPASSWORD, async (req, res) => {
const body = _.pick(req.body, ['idapp', 'email']);
const idapp = body.idapp;
const email = body.email.toLowerCase().trim();
console.log(
'POST ' + process.env.LINK_REQUEST_NEWPASSWORD + ' idapp= ' + idapp +
' email = ' + email);
try {
const ris = await User.createNewRequestPwd(idapp, email);
if (ris) {
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
const body = _.pick(req.body, ['idapp', 'email', 'codetocheck']);
const idapp = body.idapp;
const email = body.email.toLowerCase().trim();
const codetocheck = body.codetocheck ? body.codetocheck.trim() : '';
// Check if too many requests
if (await User.tooManyReqPassword(idapp, email, true)) {
console.log(process.env.LINK_REQUEST_NEWPASSWORD, 'TOO MANY REQUESTS !!! EXIT ', email);
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: 'TOO MANY REQUESTS' });
return false;
}
console.log(
'POST ' + process.env.LINK_REQUEST_NEWPASSWORD + ' idapp= ' + idapp +
' email = ' + email);
const reqpwd = await User.createNewRequestPwd(idapp, email, codetocheck);
if (reqpwd && reqpwd.ris) {
res.send({ code: server_constants.RIS_CODE_OK, msg: '', link: reqpwd.link });
} else {
tools.snooze(5000);
return res.status(200).
send({ code: server_constants.RIS_CODE_EMAIL_NOT_EXIST, msg: '' });
}
} catch (e) {
console.log(process.env.LINK_REQUEST_NEWPASSWORD, e.message);
res.status(400).send();
res.send({ code: server_constants.RIS_CODE_ERR, msg: e });
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
}
});