diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html index 526e3a3ede64803594cced2c85aa8c3ab7febd2d..1ab1982ba9e350967125465594dd12cb30ba557b 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -100,8 +100,17 @@ </div> <div class="form-group" fxLayout="column"> <label for="email">Courriel personnel</label> + <p class="special invalid" *ngIf="this.accountForm.get('email').hasError('alreadyExist')"> + L'email est déja utilisé. + </p> <div fxLayout="row" fxLayoutGap="13px"> - <input type="text" (input)="setValidationsForm()" formControlName="email" class="form-input" /> + <input + type="text" + (input)="setValidationsForm()" + (keyup)="verifyUserExist($event.target.value)" + formControlName="email" + class="form-input" + /> <img *ngIf="accountForm.get('email').valid" src="../../assets/form/validate.svg" alt="logo valid" /> <img *ngIf="accountForm.get('email').invalid && accountForm.get('email').value" @@ -113,7 +122,7 @@ <div class="form-group" fxLayout="column"> <label for="password">Création de mot de passe</label> <p - class="password" + class="special" [ngClass]="{ invalid: accountForm.get('password').invalid && accountForm.get('password').value }" > Le mot de passe doit contenir au minimum : 8 caractères dont un caractère spécial, un caractère en majuscule diff --git a/src/app/form/form.component.scss b/src/app/form/form.component.scss index 203a87dacfe3a1eed81fb8d603fbc5e1393a0452..7169d27acc9a1ccd471f85e14e1c4e75a1a8c2ee 100644 --- a/src/app/form/form.component.scss +++ b/src/app/form/form.component.scss @@ -151,7 +151,7 @@ h3 { margin-top: 10px; margin-bottom: 0; @include cn-regular-18; - &.password { + &.special { @include cn-regular-14; color: $grey-3; diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 6832ffc8a1dd63d5f94939cf74c52b64e7ea41c7..5da4fa9a642de61863a04baec2726e85fb7208a9 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -557,4 +557,15 @@ export class FormComponent implements OnInit { this.resolve(hasAccept); this.showConfirmationModal = false; } + + public verifyUserExist(inputEmail): void { + if (this.accountForm.get('email').valid) { + this.profileService.isEmailAlreadyUsed(inputEmail).subscribe((isExist) => { + if (isExist) { + this.accountForm.get('email').setErrors({ alreadyExist: true }); + this.setValidationsForm(); + } + }); + } + } } diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index a196203fda3801b7d685b23b35d24e1a6869d95f..849d148b45d4d0ca414206768b4a165ac7b17985 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -67,4 +67,8 @@ export class ProfileService { public changeEmail(newEmail: string, oldEmail: string): Observable<User> { return this.http.post<any>(`${this.baseUrl}/change-email`, { newEmail, oldEmail }); } + + public isEmailAlreadyUsed(newMail: string): Observable<Boolean> { + return this.http.post<Boolean>(`${this.baseUrl}/verify-exist-user`, { newMail }); + } }