Merge pull request #38 from Quantum-P3/feature/US-08

fix validaciones password
This commit is contained in:
Eduardo Quiros 2021-07-17 02:50:36 +00:00 committed by GitHub
commit 9f731e1003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 17 deletions

View File

@ -305,19 +305,35 @@
<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">&times;</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>
@ -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>

View File

@ -26,6 +26,7 @@ export class SettingsComponent implements OnInit {
isSaving = false;
success = false;
successPassword = false;
samePassword = false;
error = false;
errorPassword = false;
doNotMatch = false;
@ -143,16 +144,27 @@ 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(
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)
);
}
}
}
trackUserById(index: number, item: IUser): number {
return item.id!;
@ -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;

View File

@ -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": {