fix validaciones password
This commit is contained in:
		
							parent
							
								
									18ca4042ce
								
							
						
					
					
						commit
						ff4a6d2194
					
				| 
						 | 
				
			
			@ -305,26 +305,42 @@
 | 
			
		|||
      <div class="row mb-3 pb-3" style="border-bottom: 1px solid #e7ebf3">
 | 
			
		||||
        <div
 | 
			
		||||
          class="alert alert-danger"
 | 
			
		||||
          *ngIf="errorPassword && !doNotMatch && !successPassword"
 | 
			
		||||
          *ngIf="errorPassword && !doNotMatch && !successPassword && !samePassword"
 | 
			
		||||
          jhiTranslate="global.messages.info.authenticated.passwordForm"
 | 
			
		||||
          data-cy="loginError"
 | 
			
		||||
        ></div>
 | 
			
		||||
 | 
			
		||||
        <div *ngIf="successPassword" class="alert alert-success alert-dismissible fade show" role="alert">
 | 
			
		||||
        <div
 | 
			
		||||
          *ngIf="successPassword && !errorPassword && !samePassword && !doNotMatch"
 | 
			
		||||
          class="alert alert-success alert-dismissible fade show"
 | 
			
		||||
          role="alert"
 | 
			
		||||
        >
 | 
			
		||||
          Sus contraseña fue actualizada de manera exitosa
 | 
			
		||||
          <!-- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
 | 
			
		||||
            <span aria-hidden="true">×</span>
 | 
			
		||||
          </button>-->
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div class="alert alert-danger" *ngIf="doNotMatch && !successPassword" jhiTranslate="global.messages.error.dontmatch">
 | 
			
		||||
        <div
 | 
			
		||||
          class="alert alert-danger"
 | 
			
		||||
          *ngIf="doNotMatch && !successPassword && !errorPassword"
 | 
			
		||||
          jhiTranslate="global.messages.error.dontmatch"
 | 
			
		||||
        >
 | 
			
		||||
          The password and its confirmation do not match!
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div
 | 
			
		||||
          class="alert alert-danger"
 | 
			
		||||
          *ngIf="samePassword && !successPassword && !errorPassword && !doNotMatch"
 | 
			
		||||
          jhiTranslate="global.messages.error.samePassword"
 | 
			
		||||
        >
 | 
			
		||||
          The password and its confirmation do not match!
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div class="form-group w-100">
 | 
			
		||||
          <label class="form-control-label" for="field_password">Contraseña actual</label>
 | 
			
		||||
          <input
 | 
			
		||||
            type="password"
 | 
			
		||||
            type="text"
 | 
			
		||||
            class="form-control"
 | 
			
		||||
            name="password"
 | 
			
		||||
            id="field_password"
 | 
			
		||||
| 
						 | 
				
			
			@ -371,7 +387,7 @@
 | 
			
		|||
        <div class="form-group w-100">
 | 
			
		||||
          <label class="form-control-label" for="field_passwordNew">Contraseña nueva</label>
 | 
			
		||||
          <input
 | 
			
		||||
            type="password"
 | 
			
		||||
            type="text"
 | 
			
		||||
            class="form-control"
 | 
			
		||||
            name="passwordNew"
 | 
			
		||||
            id="field_passwordNew"
 | 
			
		||||
| 
						 | 
				
			
			@ -418,7 +434,7 @@
 | 
			
		|||
        <div class="form-group w-100">
 | 
			
		||||
          <label class="form-control-label" for="field_passwordNewConfirm">Confirmar contraseña nueva</label>
 | 
			
		||||
          <input
 | 
			
		||||
            type="password"
 | 
			
		||||
            type="text"
 | 
			
		||||
            class="form-control"
 | 
			
		||||
            name="passwordNewConfirm"
 | 
			
		||||
            id="field_passwordNewConfirm"
 | 
			
		||||
| 
						 | 
				
			
			@ -477,7 +493,7 @@
 | 
			
		|||
          type="submit"
 | 
			
		||||
          id="save-entity"
 | 
			
		||||
          data-cy="entityCreateSaveButton"
 | 
			
		||||
          [disabled]="isSaving"
 | 
			
		||||
          [disabled]="passwordForm.invalid || isSaving"
 | 
			
		||||
          class="ds-btn ds-btn--primary"
 | 
			
		||||
        >
 | 
			
		||||
          <span jhiTranslate="entity.action.save">Save</span>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,7 @@ export class SettingsComponent implements OnInit {
 | 
			
		|||
  isSaving = false;
 | 
			
		||||
  success = false;
 | 
			
		||||
  successPassword = false;
 | 
			
		||||
  samePassword = false;
 | 
			
		||||
  error = false;
 | 
			
		||||
  errorPassword = false;
 | 
			
		||||
  doNotMatch = false;
 | 
			
		||||
| 
						 | 
				
			
			@ -143,14 +144,25 @@ export class SettingsComponent implements OnInit {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  savePassword(): void {
 | 
			
		||||
    this.successPassword = false;
 | 
			
		||||
    this.doNotMatch = false;
 | 
			
		||||
    this.samePassword = false;
 | 
			
		||||
    this.errorPassword = false;
 | 
			
		||||
 | 
			
		||||
    const passwordNew = this.passwordForm.get(['passwordNew'])!.value;
 | 
			
		||||
    if (passwordNew !== this.passwordForm.get(['passwordNewConfirm'])!.value) {
 | 
			
		||||
      this.doNotMatch = true;
 | 
			
		||||
    const passwordOld = this.passwordForm.get(['password'])!.value;
 | 
			
		||||
    if (passwordOld == passwordNew) {
 | 
			
		||||
      this.samePassword = true;
 | 
			
		||||
    } else {
 | 
			
		||||
      this.passwordService.save(this.passwordForm.get(['passwordNew'])!.value, this.passwordForm.get(['password'])!.value).subscribe(
 | 
			
		||||
        () => (this.successPassword = true),
 | 
			
		||||
        () => (this.errorPassword = true)
 | 
			
		||||
      );
 | 
			
		||||
      if (passwordNew !== this.passwordForm.get(['passwordNewConfirm'])!.value) {
 | 
			
		||||
        (this.doNotMatch = true), (this.samePassword = false);
 | 
			
		||||
      } else {
 | 
			
		||||
        this.passwordService.save(passwordNew, passwordOld).subscribe(
 | 
			
		||||
          () => (this.successPassword = true),
 | 
			
		||||
 | 
			
		||||
          () => (this.errorPassword = true)
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -175,15 +187,16 @@ export class SettingsComponent implements OnInit {
 | 
			
		|||
 | 
			
		||||
  protected subscribeToSaveResponse(result: Observable<HttpResponse<IUsuarioExtra>>): void {
 | 
			
		||||
    result.pipe(finalize(() => this.onSaveFinalize())).subscribe(
 | 
			
		||||
      () => (
 | 
			
		||||
        (this.success = true),
 | 
			
		||||
        this.router.navigate(['account/settings']).then(() => {
 | 
			
		||||
          window.location.reload();
 | 
			
		||||
        })
 | 
			
		||||
      ),
 | 
			
		||||
      () => ((this.success = true), this.windowReload()),
 | 
			
		||||
      response => this.processError(response)
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
  windowReload() {
 | 
			
		||||
    this.router.navigate(['account/settings']).then(() => {
 | 
			
		||||
      window.location.reload();
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  processError(response: HttpErrorResponse): void {
 | 
			
		||||
    if (response.status === 400) {
 | 
			
		||||
      this.error = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,6 +68,7 @@
 | 
			
		|||
          "suffix": ", puede intentar con las cuentas predeterminadas:<br/>- Administrador (usuario=\"admin\" y contraseña=\"admin\") <br/>- Usuario (usuario=\"user\" y contraseña=\"user\").",
 | 
			
		||||
          "updateForm": "Ocurrió un error al actualizar su información, favor revisar los campos e intentar de nuevo",
 | 
			
		||||
          "passwordForm": "Ocurrió un error al actualizar su contraseña, favor revisar los campos e intentar de nuevo",
 | 
			
		||||
 | 
			
		||||
          "botonInicio": "Iniciar Sesión"
 | 
			
		||||
        },
 | 
			
		||||
        "register": {
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +77,8 @@
 | 
			
		|||
        }
 | 
			
		||||
      },
 | 
			
		||||
      "error": {
 | 
			
		||||
        "dontmatch": "¡La contraseña y la confirmación de contraseña no coinciden!"
 | 
			
		||||
        "samePassword": "La contraseña actual y la nueva contraseña no pueden ser iguales",
 | 
			
		||||
        "dontmatch": "La contraseña y la confirmación de contraseña no coinciden"
 | 
			
		||||
      },
 | 
			
		||||
      "validate": {
 | 
			
		||||
        "newpassword": {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue