From fe3a97cd38d03c825b7bfc8b69eb489d72fc6172 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 26 Mar 2024 08:27:44 +0100 Subject: [PATCH] refs #6427 perf: minor changes --- back/methods/vn-user/recover-passwordSMS.js | 38 +-------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/back/methods/vn-user/recover-passwordSMS.js b/back/methods/vn-user/recover-passwordSMS.js index 4a70e3184..a7759d9d5 100644 --- a/back/methods/vn-user/recover-passwordSMS.js +++ b/back/methods/vn-user/recover-passwordSMS.js @@ -1,41 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); const authCode = require('../../models/authCode'); -const OTP_CHAR = ':'; -function original({id, phone}) { - const total = parseInt(phone) + parseInt(id); - const value = total.toString().slice(-6); - - return parseInt(value); // Devolvemos un nĂºmero entero, no una cadena -} -function reverse(params) { - const _original = original(params); - return parseInt(_original.toString().split('').reverse().join('')); -} - -function selectOTPMethod() { - const otpIndex = Math.floor(Math.random() * Object.keys(OTP_TYPES).length); - return Object.keys(OTP_TYPES)[otpIndex]; -} -function generateOTP(params, _otpType, format = true) { - const otpType = _otpType ?? selectOTPMethod(); - const otp = OTP_TYPES[otpType](params); - if (format) return formatOTP({otpType, otp}); - return {otpType, otp}; -} - -function formatOTP({otpType, otp}) { - return `${otpType}${OTP_CHAR}${otp}`; -} - -function checkOTP(params, otp) { - const [otpType, value] = otp.split(OTP_CHAR); - return generateOTP(params, otpType) === formatOTP(otpType, value); -} - -const OTP_TYPES = { - // 'A': original, - 'B': reverse, -}; module.exports = Self => { Self.remoteMethod('recoverPasswordSMS', { description: 'Send SMS to the user', @@ -102,7 +66,7 @@ module.exports = Self => { const code = await authCode(user, myOptions); - if (process.env.NODE_ENV != 'production') + if (process.env.NODE_ENV === 'production') await Self.app.models.Sms.send({req: {accessToken: {userId: id}}}, +phone, code); return {otp: true}; } catch (err) {