refs #6427 feat: front restorePasswordSMS
This commit is contained in:
parent
bfc8cda8a2
commit
8d6fc401a1
|
@ -12,10 +12,29 @@
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
ng-if="$ctrl.sms"
|
ng-if="$ctrl.sms"
|
||||||
|
disabled="$ctrl.otp"
|
||||||
|
label="User's id"
|
||||||
|
ng-model="$ctrl.userId"
|
||||||
|
type="number"
|
||||||
|
required="true"
|
||||||
|
vn-focus>
|
||||||
|
</vn-textfield>
|
||||||
|
<vn-textfield
|
||||||
|
ng-if="$ctrl.sms"
|
||||||
|
disabled="$ctrl.otp"
|
||||||
label="User's phone"
|
label="User's phone"
|
||||||
ng-model="$ctrl.user"
|
ng-model="$ctrl.user"
|
||||||
|
required="true"
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
|
<vn-textfield
|
||||||
|
ng-if="$ctrl.otp"
|
||||||
|
label="Verification code"
|
||||||
|
ng-model="$ctrl.code"
|
||||||
|
vn-name="code"
|
||||||
|
autocomplete="false"
|
||||||
|
class="vn-mt-md">
|
||||||
|
</vn-textfield>
|
||||||
<div class="text-secondary">
|
<div class="text-secondary">
|
||||||
<span ng-if="$ctrl.sms" translate>
|
<span ng-if="$ctrl.sms" translate>
|
||||||
We will sent you a sms
|
We will sent you a sms
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
|
import UserError from '../../../core/lib/user-error';
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
constructor($scope, $element, $http, vnApp, $translate, $state) {
|
constructor($scope, $element, $http, vnApp, $translate, $state, $location) {
|
||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
$scope,
|
$scope,
|
||||||
$element,
|
$element,
|
||||||
$http,
|
$http,
|
||||||
vnApp,
|
vnApp,
|
||||||
$translate,
|
$translate,
|
||||||
$state
|
$state,
|
||||||
|
$location
|
||||||
});
|
});
|
||||||
$scope.$watch('$ctrl.user', function(nuevoValor) {
|
$scope.$watch('$ctrl.user', function(nuevoValor) {
|
||||||
let isSms = /([+]\d{2})?\d{9}$/ig.test(nuevoValor ?? '');
|
let isSms = /([+]\d{2})?\d{9}$/ig.test(nuevoValor ?? '');
|
||||||
|
@ -16,24 +18,50 @@ export default class Controller {
|
||||||
$scope.$ctrl.sms = isSms;
|
$scope.$ctrl.sms = isSms;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// ONLY FOR TESTS
|
||||||
|
// $onInit() {
|
||||||
|
// this.$scope.$ctrl.sms = true;
|
||||||
|
// this.$scope.$ctrl.userId = '9';
|
||||||
|
// this.$scope.$ctrl.user = '432978106';
|
||||||
|
// }
|
||||||
|
|
||||||
goToLogin() {
|
goToLogin() {
|
||||||
this.vnApp.showSuccess(this.$translate.instant('Notification sent!'));
|
this.vnApp.showSuccess(this.$translate.instant('Notification sent!'));
|
||||||
this.$state.go('login');
|
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() {
|
submit() {
|
||||||
const params = {
|
if (!this.user || (this.sms && !this.userId) || (this.otp && !this.code))
|
||||||
user: this.user
|
throw new UserError(`Credentials not valid`);
|
||||||
};
|
|
||||||
|
|
||||||
this.$http.post('VnUsers/recoverPassword', params)
|
if (this.sms || this.otp) {
|
||||||
.then(() => {
|
this.$http.post('VnUsers/recoverPasswordSMS', {id: this.userId, phone: this.user, otp: this.code})
|
||||||
this.goToLogin();
|
.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', {
|
ngModule.vnComponent('vnRecoverPassword', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -4,3 +4,5 @@ We will sent you a sms: Te enviaremos un sms para restablecer tu contraseña
|
||||||
Notification sent!: ¡Notificación enviada!
|
Notification sent!: ¡Notificación enviada!
|
||||||
User or recovery email: Usuario o correo de recuperación
|
User or recovery email: Usuario o correo de recuperación
|
||||||
User's phone: Móvil del usuario
|
User's phone: Móvil del usuario
|
||||||
|
User's id: Id del usuario
|
||||||
|
Credentials not valid: Credenciales no válidas
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default class Controller {
|
||||||
throw new UserError(`Passwords don't match`);
|
throw new UserError(`Passwords don't match`);
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
Authorization: this.$location.$$search.access_token
|
Authorization: this.$location.$$search.access_token ?? this.$state.params.access_token
|
||||||
};
|
};
|
||||||
|
|
||||||
const newPassword = this.newPassword;
|
const newPassword = this.newPassword;
|
||||||
|
|
Loading…
Reference in New Issue