-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #841 from xkostka2/PT-128
feat(user-profile): change password
- Loading branch information
Showing
8 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
libs/perun/dialogs/src/lib/change-password-dialog/change-password-dialog.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.display-flex { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.white-space-pre { | ||
white-space: pre; | ||
} |
46 changes: 46 additions & 0 deletions
46
libs/perun/dialogs/src/lib/change-password-dialog/change-password-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<h1 mat-dialog-title>{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.TITLE' | translate}}</h1> | ||
<div class="dialog-container user-theme" mat-dialog-content> | ||
<form *ngIf="!loading" [formGroup]="formGroup"> | ||
<div class="display-flex"> | ||
<mat-form-field> | ||
<mat-label>{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.OLD_PASSWORD' | translate}}</mat-label> | ||
<input formControlName="oldPasswordCtrl" matInput required type="password"> | ||
<mat-error *ngIf="oldPwd.hasError('required')">{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.FIELD_EMPTY' | translate}}</mat-error> | ||
</mat-form-field> | ||
|
||
<mat-form-field> | ||
<mat-label>{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.NEW_PASSWORD' | translate}}</mat-label> | ||
<input formControlName="passwordCtrl" matInput required type="password"> | ||
<mat-error *ngIf="newPwd.hasError('required')">{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.FIELD_EMPTY' | translate}}</mat-error> | ||
<mat-error *ngIf="newPwd.hasError('isWeak') && !newPwd.hasError('minlength')">{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.PWD_WEAK' | translate}}</mat-error> | ||
<mat-error *ngIf="newPwd.hasError('minlength')">{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.PWD_SHORT' | translate}}</mat-error> | ||
</mat-form-field> | ||
|
||
<mat-form-field> | ||
<mat-label>{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.NEW_PASSWORD_AGAIN' | translate}}</mat-label> | ||
<input formControlName="passwordAgainCtrl" matInput required type="password"> | ||
<mat-error *ngIf="newPwdAgain.hasError('required')">{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.FIELD_EMPTY' | translate}}</mat-error> | ||
<mat-error *ngIf="newPwdAgain.hasError('noPasswordMatch')">{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.PWD_DONT_MATCH' | translate}}</mat-error> | ||
</mat-form-field> | ||
|
||
<p class="white-space-pre">{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.PASSWORD_INFO' | translate}}</p> | ||
</div> | ||
</form> | ||
<mat-spinner *ngIf="loading" class="ml-auto mr-auto"></mat-spinner> | ||
</div> | ||
|
||
<div *ngIf="!loading" mat-dialog-actions> | ||
<div class="ml-auto"> | ||
<button (click)="close()" mat-button> | ||
{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.CANCEL' | translate}} | ||
</button> | ||
<button | ||
(click)="changePassword()" | ||
[disabled]="formGroup.invalid" | ||
class="ml-2" | ||
color="accent" | ||
mat-flat-button> | ||
{{'SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.CHANGE' | translate}} | ||
</button> | ||
</div> | ||
</div> |
65 changes: 65 additions & 0 deletions
65
libs/perun/dialogs/src/lib/change-password-dialog/change-password-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Component, Inject, OnInit } from '@angular/core'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { UsersManagerService } from '@perun-web-apps/perun/openapi'; | ||
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import { CustomValidators } from '@perun-web-apps/perun/utils'; | ||
import { NotificatorService } from '@perun-web-apps/perun/services'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
export interface ChangePasswordDialogData { | ||
namespace: string; | ||
login: string; | ||
} | ||
|
||
@Component({ | ||
selector: 'perun-web-apps-change-password-dialog', | ||
templateUrl: './change-password-dialog.component.html', | ||
styleUrls: ['./change-password-dialog.component.css'] | ||
}) | ||
export class ChangePasswordDialogComponent implements OnInit { | ||
|
||
formGroup: FormGroup; | ||
oldPwd: AbstractControl; | ||
newPwd: AbstractControl; | ||
newPwdAgain: AbstractControl; | ||
successMessage: string; | ||
loading: boolean; | ||
|
||
constructor(private dialogRef: MatDialogRef<ChangePasswordDialogComponent>, | ||
@Inject(MAT_DIALOG_DATA) private data: ChangePasswordDialogData, | ||
private _formBuilder: FormBuilder, | ||
private usersManagerService: UsersManagerService, | ||
private notificator: NotificatorService, | ||
private translate: TranslateService) { | ||
translate.get('SHARED_LIB.PERUN.COMPONENTS.CHANGE_PASSWORD_DIALOG.SUCCESS').subscribe(m => this.successMessage = m); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.formGroup = this._formBuilder.group({ | ||
oldPasswordCtrl: ['', Validators.required], | ||
passwordCtrl: ['', Validators.compose([ | ||
CustomValidators.patternValidator([/\d/, /[A-Z]/, /[a-z]/, /[$&+,:;=?@#|'<>.^*()%!-]/]), | ||
Validators.minLength(10)]) | ||
], | ||
passwordAgainCtrl: [''] | ||
}, { | ||
validator: CustomValidators.passwordMatchValidator | ||
}); | ||
this.oldPwd = this.formGroup.get('oldPasswordCtrl'); | ||
this.newPwd = this.formGroup.get('passwordCtrl'); | ||
this.newPwdAgain = this.formGroup.get('passwordAgainCtrl'); | ||
} | ||
|
||
close() { | ||
this.dialogRef.close(false); | ||
} | ||
|
||
changePassword() { | ||
this.loading = true; | ||
this.usersManagerService.changePasswordForLogin(this.data.login, this.data.namespace, this.newPwd.value, this.oldPwd.value, true).subscribe(() => { | ||
this.notificator.showSuccess(this.successMessage); | ||
this.loading = false; | ||
this.dialogRef.close(true); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters