WIP: #6427 - SMS Recover Password #2037
|
@ -12,10 +12,29 @@
|
|||
</vn-textfield>
|
||||
<vn-textfield
|
||||
|
||||
ng-if="$ctrl.sms"
|
||||
disabled="$ctrl.otp"
|
||||
label="User's id"
|
||||
ng-model="$ctrl.userId"
|
||||
type="number"
|
||||
required="true"
|
||||
vn-focus>
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Y aqui igual en vez de poner dos, pondria algo como. te enviaremos un mensaje por el tipo de envio elegido o algo asi Y aqui igual en vez de poner dos, pondria algo como. te enviaremos un mensaje por el tipo de envio elegido o algo asi
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
ng-if="$ctrl.sms"
|
||||
disabled="$ctrl.otp"
|
||||
label="User's phone"
|
||||
ng-model="$ctrl.user"
|
||||
required="true"
|
||||
vn-focus>
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
ng-if="$ctrl.otp"
|
||||
label="Verification code"
|
||||
ng-model="$ctrl.code"
|
||||
vn-name="code"
|
||||
jsegarra marked this conversation as resolved
Outdated
juan
commented
Corregir tabulación Corregir tabulación
|
||||
autocomplete="false"
|
||||
class="vn-mt-md">
|
||||
</vn-textfield>
|
||||
<div class="text-secondary">
|
||||
<span ng-if="$ctrl.sms" translate>
|
||||
We will sent you a sms
|
||||
|
|
|
@ -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
|
||||
jsegarra marked this conversation as resolved
Outdated
alexm
commented
Esto cuando se usa?? Esto cuando se usa??
|
||||
});
|
||||
$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'),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
No entiendo el poner 2 vn-textfields con ifs.
Con poner `label="User, phone, or recovery email" sobraria.
Y tampoco se si deberia poder poner numeros de telefono para decir que son ellos (lo consultaria con Juan)
El teléfono se usa para validar la acción de recuperar la contraseña. Porque puede darse el caso que el usuario ponga su id y no le esté llegando el SMS porque en algún momento se equivocó de teléfono.
Entonces podría poner tu id, y mi numero de teléfono y te podría cambiar la contraseña?
Lo que se hacia con el correo es apartir del correo sacar el id del usuario. Supongo que con el telefono sera igual
No podrías, porque tu pones el id de usuario y teléfono, y si ambos valores no existen, no te envía SMS. En local puedes probar con el userId:9 que tiene el teléfono "432978106"
El teléfono de recuperación solo lo puede cambiar quien es propietario del registro, ya que tiene una validación del id del registro contra el id del usuario logeado
Pero vamos, que yo podría estar contaminado con el desarrollo, y a lo mejor tu consigues bordear la restricción. si es así, repórtamelo, por favor.