Skip to content

Commit

Permalink
Merge pull request #57 from atnos/CU-ck097u_add_email_validation_and_…
Browse files Browse the repository at this point in the history
…update_condition

Cu ck097u add email validation and update condition
  • Loading branch information
syl-p authored Jan 21, 2021
2 parents 69b61ca + 6543d65 commit 5df3fd1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,43 @@
>
<!-- *ngSwitchCase="'forgetPassword'" -->
<fieldset>
<div class="form-group">
<div
class="form-group"
[ngClass]="{ 'is-invalid': f.email.hasError('email') }"
>
<p class="msg" *ngIf="msgFromBack">
{{ msgFromBack }}
</p>
<legend>Récupération de compte</legend>
<input
type="text"
placeholder="Adresse email"
id="pia-account-email"
formControlName="email"
email
/>
<label for="pia-account-email" *ngIf="f.email.value.length > 0">
Email
</label>
<p class="msg" *ngIf="f.email.hasError('email')">
Veuillez renseigner une adresse email valide.
</p>
</div>
<div class="validForm">
<button (click)="onCanceled()">
Annuler
</button>
<button
[disabled]="forgetPassword.invalid"
[disabled]="forgetPassword.invalid || loading"
type="submit"
class="btn btn-green"
>
<!-- (click)="changeDisplay('resetPassword')" -->
Continuer
<ng-container *ngIf="loading; else loadingElse">
...
</ng-container>
<ng-template #loadingElse>
continuer
</ng-template>
</button>
</div>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { AuthService } from 'src/app/services/auth.service';

@Component({
selector: 'app-forget-password',
Expand All @@ -10,8 +11,13 @@ export class ForgetPasswordComponent implements OnInit {
@Output() canceled = new EventEmitter<boolean>();
@Output() validated = new EventEmitter<boolean>();
forgetPassword: FormGroup;
loading: boolean = false;
msgFromBack: string;

constructor(private formBuilder: FormBuilder) {
constructor(
private formBuilder: FormBuilder,
private authService: AuthService
) {
// Prepare forgetPassword form
this.forgetPassword = this.formBuilder.group({
email: ['', Validators.required]
Expand All @@ -29,9 +35,16 @@ export class ForgetPasswordComponent implements OnInit {
}

ngOnSubmit() {
return new Promise(resolve => {
this.validated.emit(true);
resolve(true);
});
this.loading = true;
this.authService
.checkPassword(this.forgetPassword.controls.password.value)
.then(() => {
this.loading = false;
this.validated.emit(true);
})
.catch(err => {
this.loading = false;
this.msgFromBack = err;
});
}
}
6 changes: 5 additions & 1 deletion src/app/modules/home/forms/password/password.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@
</div>
<div class="validForm">
<button (click)="onCanceled()">Annuler</button>
<button [disabled]="signUp.invalid" type="submit" class="btn btn-green">
<button
[disabled]="signUp.invalid || loading"
type="submit"
class="btn btn-green"
>
<ng-container *ngIf="loading; else loadingElse">
...
</ng-container>
Expand Down
8 changes: 6 additions & 2 deletions src/app/modules/home/forms/sign-in/sign-in.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<fieldset>
<div>
<legend>S'identifier</legend>
<p class="msg" *ngIf="fromSignUp">
<p class="msg is-valid" *ngIf="fromSignUp">
Votre mot de passe a été enregistré. Vous pouvez dès à présent vous
connecter.
</p>
Expand Down Expand Up @@ -37,7 +37,11 @@
<button (click)="onCanceled()">
Créer un compte
</button>
<button [disabled]="logIn.invalid" type="submit" class="btn btn-green">
<button
[disabled]="logIn.invalid || loading"
type="submit"
class="btn btn-green"
>
<ng-container *ngIf="loading; else loadingElse">
...
</ng-container>
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/home/forms/sign-in/sign-in.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
p {
align-self: flex-end;
}
button:disabled {
cursor: not-allowed;
background-color: inherit;
}
}
div:last-of-type {
label {
Expand Down
14 changes: 0 additions & 14 deletions src/app/modules/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,4 @@ export class HomeComponent implements OnInit, OnDestroy {
ngOnDestroy(): void {
this.renderer.removeClass(document.body, 'pia-authentication');
}

checkPasswordAvaibility() {}

onSignIn(): Promise<any> {
return new Promise(resolve => {
resolve(true);
});
}

onSignUp(): Promise<any> {
return new Promise(resolve => {
resolve(true);
});
}
}

0 comments on commit 5df3fd1

Please sign in to comment.