Skip to content

Commit 9bdfc86

Browse files
hbaltypYassine
authored andcommitted
feat(admins): faciliter le process de réinitialisation de mot de passe
1 parent 8dbea5d commit 9bdfc86

File tree

3 files changed

+110
-10
lines changed

3 files changed

+110
-10
lines changed

packages/portail-admins/src/app/modules/structure/components/users/users.component.html

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ <h2>Utilisateurs enregistrés: {{ users.length }} utilisateurs</h2>
121121
<td>
122122
{{ USER_ROLES_LABELS[user.role] }}
123123
</td>
124-
<td>
124+
<td class="d-flex gap-2">
125125
<a
126126
target="_blank"
127127
class="btn btn-outline-primary"
@@ -136,8 +136,52 @@ <h2>Utilisateurs enregistrés: {{ users.length }} utilisateurs</h2>
136136
>
137137
🔗 Lien</a
138138
>
139+
<button
140+
class="btn btn-outline-primary"
141+
(click)="openConfirmationModdal(user)"
142+
type="button"
143+
>
144+
Réinitialiser mot de passe
145+
</button>
139146
</td>
140147
</tr>
141148
</tbody>
142149
</table>
150+
151+
<ng-template #confirmPasswordReinit let-modal>
152+
<div class="modal-header">
153+
<h4 class="modal-title">Confirmation</h4>
154+
<button
155+
type="button"
156+
class="btn-close"
157+
aria-label="Close"
158+
(click)="modal.dismiss()"
159+
></button>
160+
</div>
161+
<div class="modal-body">
162+
<p>
163+
Êtes-vous sûr de vouloir réinitialiser le mot de passe de l'utilisateur:
164+
<span class="fw-bold">
165+
{{ userForPasswordReinit.email }}
166+
</span>
167+
?
168+
</p>
169+
</div>
170+
<div class="modal-footer">
171+
<button
172+
type="button"
173+
class="btn btn-lg btn-outline-dark"
174+
(click)="modal.dismiss()"
175+
>
176+
Annuler
177+
</button>
178+
<button
179+
type="button"
180+
class="btn btn-primary"
181+
(click)="doResetPassword(userForPasswordReinit.email)"
182+
>
183+
Confirmer
184+
</button>
185+
</div>
186+
</ng-template>
143187
</div>
Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
1-
import { Component, Input, OnInit } from "@angular/core";
21
import {
3-
SortValues,
4-
StructureCommon,
2+
Component,
3+
Input,
4+
OnDestroy,
5+
OnInit,
6+
TemplateRef,
7+
ViewChild,
8+
} from "@angular/core";
9+
import {
510
USER_FONCTION_LABELS,
611
UserFonction,
12+
SortValues,
13+
StructureCommon,
714
UserStructureRole,
815
} from "@domifa/common";
9-
import { Subscription } from "rxjs";
16+
17+
import { Subject, Subscription } from "rxjs";
1018
import {
1119
StructureService,
1220
UserStructureWithSecurity,
1321
} from "../../services/structure.service";
1422
import { environment } from "../../../../../environments/environment";
1523
import { subMonths } from "date-fns";
24+
import { NgbModal, NgbModalRef } from "@ng-bootstrap/ng-bootstrap";
1625

1726
@Component({
1827
selector: "app-users",
1928
templateUrl: "./users.component.html",
2029
styleUrl: "./users.component.css",
2130
})
22-
export class UsersComponent implements OnInit {
31+
export class UsersComponent implements OnInit, OnDestroy {
2332
public users: UserStructureWithSecurity[] = [];
2433
public sortValue: SortValues = "asc";
2534
public currentKey = "id";
2635
public twoMonthsAgo = subMonths(new Date(), 2);
27-
36+
public reloadUsers = new Subject<void>();
2837
public readonly frontendUrl = environment.frontendUrl;
2938
public readonly USER_FONCTION = UserFonction;
3039
public readonly _USER_FONCTION_LABELS = USER_FONCTION_LABELS;
@@ -34,14 +43,31 @@ export class UsersComponent implements OnInit {
3443
simple: "Instructeur",
3544
facteur: "Facteur",
3645
};
37-
3846
@Input({ required: true }) public structure: StructureCommon;
3947
private subscription = new Subscription();
4048
public searching = true;
49+
@ViewChild("confirmPasswordReinit", { static: true })
50+
public confirmPasswordReinit!: TemplateRef<NgbModalRef>;
4151

42-
constructor(private readonly structureService: StructureService) {}
52+
public userForPasswordReinit?: UserStructureWithSecurity;
53+
constructor(
54+
private readonly structureService: StructureService,
55+
private readonly modalService: NgbModal
56+
) {}
4357

4458
ngOnInit(): void {
59+
this.loadUsers();
60+
61+
// Subscribe to reloadUsers subject to reload the list when triggered
62+
this.subscription.add(
63+
this.reloadUsers.subscribe(() => {
64+
this.loadUsers();
65+
})
66+
);
67+
}
68+
69+
private loadUsers(): void {
70+
this.searching = true;
4571
this.subscription.add(
4672
this.structureService.getUsers(this.structure.id).subscribe((users) => {
4773
this.users = users.map((user) => {
@@ -50,7 +76,31 @@ export class UsersComponent implements OnInit {
5076
}
5177
return user;
5278
});
79+
this.searching = false;
5380
})
5481
);
5582
}
83+
84+
public openConfirmationModdal(user: UserStructureWithSecurity): void {
85+
this.userForPasswordReinit = user;
86+
this.modalService.open(this.confirmPasswordReinit, {
87+
size: "s",
88+
centered: true,
89+
});
90+
}
91+
92+
public doResetPassword(email: string): void {
93+
if (!email) return;
94+
this.subscription.add(
95+
this.structureService
96+
.resetStructureAdminPassword(email)
97+
.subscribe(() => this.reloadUsers.next())
98+
);
99+
100+
this.modalService.dismissAll();
101+
}
102+
103+
ngOnDestroy(): void {
104+
this.subscription.unsubscribe();
105+
}
56106
}

packages/portail-admins/src/app/modules/structure/services/structure.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Observable } from "rxjs";
55
import { environment } from "../../../../environments/environment";
66

77
const BASE_URL = `${environment.apiUrl}admin/structures`;
8-
8+
const RESET_PASSWORD_URL = `${environment.apiUrl}users/get-password-token`;
99
export type UserStructureWithSecurity = UserStructure & {
1010
temporaryTokens: {
1111
type?: string;
@@ -34,6 +34,12 @@ export class StructureService {
3434
);
3535
}
3636

37+
public resetStructureAdminPassword(email: string): Observable<void> {
38+
return this.http.post<void>(`${RESET_PASSWORD_URL}`, {
39+
email,
40+
});
41+
}
42+
3743
public getMetabaseUrl(params: MetabaseParams): Observable<{ url: string }> {
3844
return this.http.post<{ url: string }>(
3945
`${BASE_URL}/metabase-stats`,

0 commit comments

Comments
 (0)