Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 468fdcd

Browse files
committed
✨ mis en place de la feature pour le rappel de mot de passe
1 parent 746e6eb commit 468fdcd

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

src/app/modules/authentication/pages/forgot-password/forgot-password.component.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@ <h2 class="mt-6 text-3xl font-semibold text-slate-900">Mot de passe oublié?</h2
66
</p>
77
</div>
88

9-
<form action="#" method="POST" class="mt-8 space-y-6">
9+
<!-- Session Status -->
10+
<cosna-success *ngIf="message$ | async; let message" [message]="message" class="mt-4"></cosna-success>
11+
12+
<!-- Validation Errors -->
13+
<cosna-errors *ngIf="error$ | async; let error" [message]="error" class="mt-4"></cosna-errors>
14+
15+
<form [formGroup]="form" (submit)="submit()" class="mt-8 space-y-6">
1016
<div>
1117
<cosna-input-overlaping-label
1218
label="Adresse E-mail"
1319
name="email"
14-
value=""
20+
formControlName="email"
1521
></cosna-input-overlaping-label>
1622
</div>
1723

1824
<div class="flex items-center justify-end">
19-
<cosna-button-primary type="submit">
25+
<cosna-button-primary type="submit" class="justify-center" [loading$]="(loading$)">
2026
Envoyer le lien de réinitialisation
2127
</cosna-button-primary>
2228
</div>
2329
</form>
2430

2531
<p class="mt-2 text-right">
26-
<a routerLink="/auth/login" class="inline-flex items-center text-secondary-500 hover:text-secondary-600 hover:underline text-sm leading-5 font-medium">
32+
<a routerLink="/auth/login" class="inline-flex items-center text-sm font-medium leading-5 text-secondary-500 hover:text-secondary-600 hover:underline">
2733
<svg class="w-5 h-5 mr-1" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg">
2834
<path d="M6.75 15.75L3 12M3 12L6.75 8.25M3 12H21" />
2935
</svg>
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3+
import { Store } from '@ngrx/store';
4+
import { Observable } from 'rxjs';
5+
import { forgotPasswordAction } from '../../store/auth.actions';
6+
import { selectError, selectLoading, selectMessage } from '../../store/auth.selectors';
27

38
@Component({
49
templateUrl: './forgot-password.component.html',
510
})
611
export class ForgotPasswordComponent implements OnInit {
12+
public form: FormGroup = this.formBuilder.group({
13+
email: ['', [Validators.required, Validators.email]],
14+
});
15+
public error$: Observable<string | null> = this.store.select(selectError);
16+
public message$: Observable<string | null> = this.store.select(selectMessage);
17+
public loading$: Observable<boolean> = this.store.select(selectLoading);
718

8-
constructor() { }
19+
constructor(private formBuilder: FormBuilder, private store: Store) { }
920

10-
ngOnInit(): void {
21+
ngOnInit(): void {}
22+
23+
public submit() {
24+
if (this.form.valid) {
25+
this.store.dispatch(forgotPasswordAction(this.form.getRawValue()));
26+
}
1127
}
1228

1329
}

src/app/modules/authentication/pages/login/login.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2 class="mt-6 text-3xl font-semibold text-slate-900">Connectez-vous</h2>
4141
</div>
4242

4343
<div>
44-
<cosna-button-primary type="submit" class="relative justify-center w-full group disabled:opacity-50 disabled:cursor-not-allowed" [loading$]="(loading$)">
44+
<cosna-button-primary type="submit" class="justify-center w-full group" [loading$]="(loading$)">
4545
<span *ngIf="!(loading$ | async)" class="absolute inset-y-0 left-0 flex items-center pl-3">
4646
<svg class="w-5 h-5 text-primary-500 group-hover:text-primary-400" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
4747
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 1C7.51472 1 5.5 3.01472 5.5 5.5V9H5C3.89543 9 3 9.89543 3 11V17C3 18.1046 3.89543 19 5 19H15C16.1046 19 17 18.1046 17 17V11C17 9.89543 16.1046 9 15 9H14.5V5.5C14.5 3.01472 12.4853 1 10 1ZM13 9V5.5C13 3.84315 11.6569 2.5 10 2.5C8.34315 2.5 7 3.84315 7 5.5V9H13Z" />

src/app/modules/authentication/store/auth.effects.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ export class AuthEffects {
3636

3737
forgotPasswordEffect = createEffect(() => this.actions$.pipe(
3838
ofType(AuthActions.forgotPasswordAction),
39+
switchMap(({ email }: { email: string }) =>
40+
this.authService.forgotPassword(email).pipe(
41+
map(({ message }: { message: string }) => {
42+
console.log(message);
43+
return AuthActions.forgotPasswordSuccessAction({ message })
44+
}),
45+
catchError((error) => {
46+
console.log(error);
47+
return of(
48+
AuthActions.forgotPasswordFailureAction({
49+
error: error.error?.message ?? 'Unknown error occurred',
50+
})
51+
)
52+
})
53+
)
54+
)
3955
));
4056

4157
resetPasswordEffect = createEffect(() => this.actions$.pipe(

src/app/modules/authentication/store/auth.reducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const authReducer = createReducer(
5858
return {
5959
...state,
6060
isLoading: false,
61+
error: null,
6162
message,
6263
}
6364
}
@@ -68,6 +69,7 @@ export const authReducer = createReducer(
6869
return {
6970
...state,
7071
isLoading: false,
72+
error: null,
7173
message,
7274
user,
7375
}

0 commit comments

Comments
 (0)