diff --git a/front/salix/components/recover-password/index.html b/front/salix/components/recover-password/index.html index feb641efc8..cb8bbe06dc 100644 --- a/front/salix/components/recover-password/index.html +++ b/front/salix/components/recover-password/index.html @@ -12,10 +12,29 @@ + + + +
We will sent you a sms diff --git a/front/salix/components/recover-password/index.js b/front/salix/components/recover-password/index.js index 79df29b78f..723dd47c17 100644 --- a/front/salix/components/recover-password/index.js +++ b/front/salix/components/recover-password/index.js @@ -1,14 +1,16 @@ +import UserError from '../../../core/lib/user-error'; import ngModule from '../../module'; export default class Controller { - constructor($scope, $element, $http, vnApp, $translate, $state) { + constructor($scope, $element, $http, vnApp, $translate, $state, $location) { Object.assign(this, { $scope, $element, $http, vnApp, $translate, - $state + $state, + $location }); $scope.$watch('$ctrl.user', function(nuevoValor) { let isSms = /([+]\d{2})?\d{9}$/ig.test(nuevoValor ?? ''); @@ -16,24 +18,50 @@ export default class Controller { $scope.$ctrl.sms = isSms; }); } + // ONLY FOR TESTS + // $onInit() { + // this.$scope.$ctrl.sms = true; + // this.$scope.$ctrl.userId = '9'; + // this.$scope.$ctrl.user = '432978106'; + // } goToLogin() { this.vnApp.showSuccess(this.$translate.instant('Notification sent!')); this.$state.go('login'); } + goToChangePassword({valid: isValid, token}) { + if (!isValid) + this.vnApp.showError(this.$translate.instant('Invalid login')); + else { + this.$state.params.userId = this.userId; + this.$location.path('/reset-password').search('access_token', token.id); + } + } + goToOTP(otp) { + this.otp = true; + this.$state.params.otp = otp; + this.code = otp; + } submit() { - const params = { - user: this.user - }; + if (!this.user || (this.sms && !this.userId) || (this.otp && !this.code)) + throw new UserError(`Credentials not valid`); - this.$http.post('VnUsers/recoverPassword', params) - .then(() => { - this.goToLogin(); - }); + if (this.sms || this.otp) { + this.$http.post('VnUsers/recoverPasswordSMS', {id: this.userId, phone: this.user, otp: this.code}) + .then(({data}) => { + data.otp && this.goToOTP(data.otp); + data.valid && this.goToChangePassword(data); + }); + } else { + this.$http.post('VnUsers/recoverPassword', {user: this.user}) + .then(() => { + this.goToLogin(); + }); + } } } -Controller.$inject = ['$scope', '$element', '$http', 'vnApp', '$translate', '$state']; +Controller.$inject = ['$scope', '$element', '$http', 'vnApp', '$translate', '$state', '$location']; ngModule.vnComponent('vnRecoverPassword', { template: require('./index.html'), diff --git a/front/salix/components/recover-password/locale/es.yml b/front/salix/components/recover-password/locale/es.yml index 5fd032bd58..167f45e694 100644 --- a/front/salix/components/recover-password/locale/es.yml +++ b/front/salix/components/recover-password/locale/es.yml @@ -4,3 +4,5 @@ We will sent you a sms: Te enviaremos un sms para restablecer tu contraseña Notification sent!: ¡Notificación enviada! User or recovery email: Usuario o correo de recuperación User's phone: Móvil del usuario +User's id: Id del usuario +Credentials not valid: Credenciales no válidas diff --git a/front/salix/components/reset-password/index.js b/front/salix/components/reset-password/index.js index c0a10cc527..ba1240b45c 100644 --- a/front/salix/components/reset-password/index.js +++ b/front/salix/components/reset-password/index.js @@ -28,7 +28,7 @@ export default class Controller { throw new UserError(`Passwords don't match`); const headers = { - Authorization: this.$location.$$search.access_token + Authorization: this.$location.$$search.access_token ?? this.$state.params.access_token }; const newPassword = this.newPassword;