From ce300e7edf22e049f91e339cbfd572daafe44c77 Mon Sep 17 00:00:00 2001 From: Fabio-Ramirez Date: Wed, 18 Mar 2026 13:09:42 -0300 Subject: [PATCH] =?UTF-8?q?AM=20-=20Perfil=20profesional=20-=20Recuperar?= =?UTF-8?q?=20contrase=C3=B1a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth/auth.controller.ts | 62 ++++++++++++++++++++++------------------- auth/routes/routes.ts | 5 +++- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/auth/auth.controller.ts b/auth/auth.controller.ts index 3b6284c5f7..fafcdde7b9 100644 --- a/auth/auth.controller.ts +++ b/auth/auth.controller.ts @@ -231,38 +231,42 @@ export async function sendOtpAndNotify(username): Promise { const usuario = await AuthUsers.findOne({ usuario: username }); // Se mantiene la validación para usuarios temporales con email - if (usuario && usuario.tipo === 'temporal' && usuario.email) { - // Genera un código OTP de 6 dígitos - const otpCode = crypto.randomInt(100000, 999999).toString(); - - usuario.otp = { - code: otpCode, - expiresAt: new Date(Date.now() + 60 * 60 * 1000), // 10 minutos en milisegundos - }; - - usuario.audit(userScheduler); - await usuario.save(); - - const extras: any = { - titulo: 'Código de Verificación', - usuario, - otpCode, - }; - const htmlToSend = await renderHTML('emails/otp-code.html', extras); - - const options: MailOptions = { - from: enviarMail.auth.user, - to: usuario.email.toString(), - subject: 'Tu código de verificación', - text: '', - html: htmlToSend, - attachments: null, - }; - await sendMail(options); + if (usuario) { + if (usuario.tipo === 'temporal' && usuario.email) { + // Genera un código OTP de 6 dígitos + const otpCode = crypto.randomInt(100000, 999999).toString(); + + usuario.otp = { + code: otpCode, + expiresAt: new Date(Date.now() + 60 * 60 * 1000), // 10 minutos en milisegundos + }; + + usuario.audit(userScheduler); + await usuario.save(); + + const extras: any = { + titulo: 'Código de Verificación', + usuario, + otpCode, + }; + const htmlToSend = await renderHTML('emails/otp-code.html', extras); + + const options: MailOptions = { + from: enviarMail.auth.user, + to: usuario.email.toString(), + subject: 'Tu código de verificación', + text: '', + html: htmlToSend, + attachments: null, + }; + await sendMail(options); + } else { + return null; + } return usuario; } else { // El usuario no existe o no es un usuario temporal con email - return null; + throw { tipo: 'cuentaInexistenteAndes' }; } } catch (error) { throw error; diff --git a/auth/routes/routes.ts b/auth/routes/routes.ts index 8177a00ff0..169b2d5d84 100644 --- a/auth/routes/routes.ts +++ b/auth/routes/routes.ts @@ -276,7 +276,10 @@ router.post('/sendOTPCode', async (req, res, next) => { } else { return next(403); } - } catch (error) { + } catch (error: any) { + if (error.tipo === 'cuentaInexistenteAndes') { + return res.json({ status: 'cuentaInexistenteAndes' }); + } return next(error); } });