perf(salix): refs #6427 CLEAN CODE

This commit is contained in:
Javier Segarra 2024-05-24 08:01:54 +02:00
parent 1d04ca1c8a
commit 5bdbb1f2ee
1 changed files with 16 additions and 11 deletions

View File

@ -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'];