Fix: Check if email address is already used
MODIFY
src/app/components/admin/create-developer/create-developer.component.html
src/app/components/admin/create-developer/create-developer.component.html
<mat-icon>warning</mat-icon>
<div class="box-content">Developer already exists.</div>
</mat-card>
+ <mat-card class="warning" *ngIf="this.checkEmailAlreadyUsed(this.userFormGroup.get('email').value)">
+ <mat-icon>warning</mat-icon>
+ <div class="box-content">Email already used.</div>
+ </mat-card>
<mat-card
class="info"
*ngIf="this.checkDeveloperNotExists(this.userFormGroup.get('username').value)
</form>
<div>
<button matStepperNext
- [disabled]="!this.checkDeveloperNotExists(this.userFormGroup.get('username').value) || !userFormGroup.valid">
+ [disabled]="!this.checkDeveloperNotExists(this.userFormGroup.get('username').value) || this.checkEmailAlreadyUsed(this.userFormGroup.get('email').value) || !userFormGroup.valid">
Next
</button>
<button routerLink="/admin">Cancel</button>

MODIFY
src/app/components/admin/create-developer/create-developer.component.ts
src/app/components/admin/create-developer/create-developer.component.ts
@@ -123,8 +123,11 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
console.error(errorMessage, error);
this.toasterService.pop('error', errorMessage, error.message);
- this.developerDataCache.developers.splice(this.developerDataCache.developers
- .findIndex(developer => developer.name.toLowerCase() === developerToCreate.name.toLowerCase()), 1);
+ const developerIndexToDelete = this.developerDataCache.developers
+ .findIndex(developer => developer.name.toLowerCase() === developerToCreate.name.toLowerCase());
+ if (developerIndexToDelete !== -1) {
+ this.developerDataCache.developers.splice(developerIndexToDelete, 1);
+ }
this.adminService.rollbackDeveloperCreation(developerToCreate, keycloakUserToCreate)
.subscribe(rollbackResponse => {
const rollbackMessage = 'Rollback executed';
@@ -147,6 +150,16 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
&& this.developerDataCache.developers.find((d) => d.name.toLowerCase() === username.toLowerCase()) === undefined;
}
+ /**
+ * Check if email adress is used
+ * @param email the email address
+ */
+ checkEmailAlreadyUsed(email: string) {
+ // check if the keycloak user does not exists
+ return this.keycloakUsers
+ && this.keycloakUsers.find((u) => u.email && u.email.toLowerCase() === email.toLowerCase()) !== undefined;
+ }
+
/**
* Check if the a password is required for an insert
* @param username the keycloak username
@@ -156,5 +169,4 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
return this.keycloakUsers
&& this.keycloakUsers.find((u) => u.username.toLowerCase() === username.toLowerCase()) === undefined;
}
-
}

Fix: Check if email address is already used