From 5bdbb1f2eea494c407094de71350de17ce291059 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 24 May 2024 08:01:54 +0200 Subject: [PATCH] perf(salix): refs #6427 CLEAN CODE --- .../components/recover-password/index.js | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/front/salix/components/recover-password/index.js b/front/salix/components/recover-password/index.js index 494a72df36..17d2a2bad0 100644 --- a/front/salix/components/recover-password/index.js +++ b/front/salix/components/recover-password/index.js @@ -31,10 +31,23 @@ export default class Controller { methodsAvailables() { return { 'email': { - url: 'VnUsers/recoverPassword', data: {user: this.user} + url: 'VnUsers/recoverPassword', + data: {user: this.user}, + cb: data => { + if (data === '') this.goToLogin(); + } }, 'sms': { - url: 'VnUsers/recoverPasswordSMS', data: {userId: this.user, verificationCode: this.verificationCode} + url: 'VnUsers/recoverPasswordSMS', + data: {userId: this.user, verificationCode: this.verificationCode}, + cb: data => { + if (this.method && this.code) { + data.token && this.goToChangePassword(data); + !data.token && this.goToLogin(); + } else + + data.code && this.handleCode(data.code); + } }, }; } @@ -44,15 +57,7 @@ export default class Controller { throw new UserError(`Credentials not valid`); const method = this.methodsAvailables()[this.method]; this.$http.post(method.url, method.data) - .then(({data}) => { - if (this.method && this.code) { - data.token && this.goToChangePassword(data); - !data.token && this.goToLogin(); - } else { - if (data === '') this.goToLogin(); - data.code && this.handleCode(data.code); - } - }); + .then(({data}) => method.cb(data)); } } Controller.$inject = ['$scope', '$element', '$http', 'vnApp', '$translate', '$state', '$location'];