You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2021/11/09 08:53:03 UTC

[incubator-streampipes] branch STREAMPIPES-426 updated: [STREAMPIPES-426] Improve form validation in user dialogs

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch STREAMPIPES-426
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/STREAMPIPES-426 by this push:
     new 31f8e2b  [STREAMPIPES-426] Improve form validation in user dialogs
     new 6124c2a  Merge branch 'STREAMPIPES-426' of github.com:apache/incubator-streampipes into STREAMPIPES-426
31f8e2b is described below

commit 31f8e2be6b566ee77fbb099720cc921f3bef472c
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Tue Nov 9 09:52:35 2021 +0100

    [STREAMPIPES-426] Improve form validation in user dialogs
---
 .../edit-user-dialog/edit-user-dialog.component.html           |  4 +++-
 .../edit-user-dialog/edit-user-dialog.component.ts             | 10 ++++++++++
 ui/src/app/login/components/register/register.component.html   |  2 ++
 ui/src/app/login/components/register/register.component.ts     |  6 +-----
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.html b/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.html
index 525d089..3dcc8a6 100644
--- a/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.html
+++ b/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.html
@@ -22,6 +22,7 @@
             <form [formGroup]="parentForm" fxFlex="100" fxLayout="column">
                 <div class="general-options-panel" fxLayout="column">
                     <span class="general-options-header">Basics</span>
+                    <mat-error *ngIf="registrationError">{{registrationError}}</mat-error>
                     <mat-form-field color="accent" *ngIf="!isUserAccount">
                         <mat-label>Username</mat-label>
                         <input formControlName="username" fxFlex
@@ -34,6 +35,7 @@
                                matInput
                                required
                                data-cy="new-user-email">
+                        <mat-error>Must be a valid email address.</mat-error>
                     </mat-form-field>
                     <mat-form-field color="accent" *ngIf="isUserAccount">
                         <mat-label>Full Name</mat-label>
@@ -42,7 +44,6 @@
                                required
                                data-cy="new-user-full-name">
                     </mat-form-field>
-
                 </div>
                 <div fxLayout="column" class="general-options-panel" *ngIf="!editMode && isUserAccount">
                     <span class="general-options-header">Password</span>
@@ -62,6 +63,7 @@
                                required
                                data-cy="new-user-password-repeat">
                     </mat-form-field>
+                    <mat-error *ngIf="parentForm.hasError('notMatching')">Passwords do not match.</mat-error>
                 </div>
                 <div fxLayout="column" class="general-options-panel" *ngIf="!isUserAccount">
                     <span class="general-options-header">Authentication</span>
diff --git a/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.ts b/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.ts
index 74ea318..d075178 100644
--- a/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.ts
+++ b/ui/src/app/configuration/security-configuration/edit-user-dialog/edit-user-dialog.component.ts
@@ -61,6 +61,8 @@ export class EditUserDialogComponent implements OnInit {
   availableRoles: RoleDescription[];
   availableGroups: Group[] = [];
 
+  registrationError: string;
+
   constructor(private dialogRef: DialogRef<EditUserDialogComponent>,
               private availableRolesService: AvailableRolesService,
               private fb: FormBuilder,
@@ -77,6 +79,9 @@ export class EditUserDialogComponent implements OnInit {
     this.isUserAccount = this.user instanceof UserAccount;
     this.parentForm = this.fb.group({});
     this.parentForm.addControl('username', new FormControl(this.clonedUser.username, Validators.required));
+    if (this.isUserAccount) {
+      this.parentForm.controls['username'].setValidators([Validators.required, Validators.email]);
+    }
     this.parentForm.addControl('accountEnabled', new FormControl(this.clonedUser.accountEnabled));
     this.parentForm.addControl('accountLocked', new FormControl(this.clonedUser.accountLocked));
     if (this.clonedUser instanceof UserAccount) {
@@ -117,6 +122,7 @@ export class EditUserDialogComponent implements OnInit {
   }
 
   save() {
+    this.registrationError = undefined;
     if (this.editMode) {
       if (this.isUserAccount) {
         this.userService.updateUser(this.clonedUser as UserAccount).subscribe(() => {
@@ -131,10 +137,14 @@ export class EditUserDialogComponent implements OnInit {
       if (this.isUserAccount) {
         this.userService.createUser(this.clonedUser as UserAccount).subscribe(() => {
           this.close(true);
+        }, error => {
+          this.registrationError = error.error.notifications[0].title;
         });
       } else {
         this.userService.createServiceAccount(this.clonedUser as ServiceAccount).subscribe(() => {
           this.close(true);
+        }, error => {
+          this.registrationError = error.error.notifications[0].title;
         });
       }
     }
diff --git a/ui/src/app/login/components/register/register.component.html b/ui/src/app/login/components/register/register.component.html
index ba012a5..1949503 100644
--- a/ui/src/app/login/components/register/register.component.html
+++ b/ui/src/app/login/components/register/register.component.html
@@ -27,6 +27,7 @@
                     <mat-label>Email</mat-label>
                     <input formControlName="username" fxFlex
                            matInput>
+                    <mat-error *ngIf="parentForm.controls.username.errors">Must be an email address.</mat-error>
                 </mat-form-field>
                 <mat-form-field color="accent">
                     <mat-label>Initial password</mat-label>
@@ -42,6 +43,7 @@
                            matInput
                            required>
                 </mat-form-field>
+                <mat-error *ngIf="parentForm.hasError('notMatching')">Passwords do not match.</mat-error>
                 <div class="form-actions" style="margin-top:20px;">
                     <button mat-button mat-raised-button color="accent" (click)="registerUser()"
                             [disabled]="!parentForm.valid" *ngIf="!registrationSuccess">
diff --git a/ui/src/app/login/components/register/register.component.ts b/ui/src/app/login/components/register/register.component.ts
index b1dd4d8..6cac15d 100644
--- a/ui/src/app/login/components/register/register.component.ts
+++ b/ui/src/app/login/components/register/register.component.ts
@@ -50,14 +50,10 @@ export class RegisterComponent implements OnInit {
 
   ngOnInit(): void {
     this.parentForm = this.fb.group({});
-    this.parentForm.addControl('username', new FormControl('', Validators.required));
+    this.parentForm.addControl('username', new FormControl('', [Validators.required, Validators.email]));
     this.parentForm.addControl('password', new FormControl('', Validators.required));
     this.parentForm.addControl('repeatPassword', new FormControl('', Validators.required));
     this.parentForm.setValidators(checkPasswords);
-
-    this.parentForm.valueChanges.subscribe((v) => {
-      this.registrationData = {username: v.username, password: v.password};
-    });
   }
 
   registerUser() {