Skip to content

Commit 73aa82a

Browse files
committed
feat(admins): faciliter le process de réinitialisation de mot de passe
1 parent a70f92a commit 73aa82a

File tree

3 files changed

+107
-8
lines changed

3 files changed

+107
-8
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
@@ -104,7 +104,7 @@ <h2>Utilisateurs enregistrés: {{ users.length }} utilisateurs</h2>
104104
<td>
105105
{{ USER_ROLES_LABELS[user.role] }}
106106
</td>
107-
<td>
107+
<td class="d-flex gap-2">
108108
<a
109109
target="_blank"
110110
class="btn btn-outline-primary"
@@ -119,8 +119,52 @@ <h2>Utilisateurs enregistrés: {{ users.length }} utilisateurs</h2>
119119
>
120120
🔗 Lien</a
121121
>
122+
<button
123+
class="btn btn-outline-primary"
124+
(click)="openConfirmationModdal(user)"
125+
type="button"
126+
>
127+
Réinitialiser mot de passe
128+
</button>
122129
</td>
123130
</tr>
124131
</tbody>
125132
</table>
133+
134+
<ng-template #confirmPasswordReinit let-modal>
135+
<div class="modal-header">
136+
<h4 class="modal-title">Confirmation</h4>
137+
<button
138+
type="button"
139+
class="btn-close"
140+
aria-label="Close"
141+
(click)="modal.dismiss()"
142+
></button>
143+
</div>
144+
<div class="modal-body">
145+
<p>
146+
Êtes-vous sûr de vouloir réinitialiser le mot de passe de l'utilisateur:
147+
<span class="fw-bold">
148+
{{ userForPasswordReinit.nom }} {{ userForPasswordReinit.prenom }}
149+
</span>
150+
?
151+
</p>
152+
</div>
153+
<div class="modal-footer">
154+
<button
155+
type="button"
156+
class="btn btn-lg btn-outline-dark"
157+
(click)="modal.dismiss()"
158+
>
159+
Annuler
160+
</button>
161+
<button
162+
type="button"
163+
class="btn btn-primary"
164+
(click)="doResetPassword(userForPasswordReinit.email)"
165+
>
166+
Confirmer
167+
</button>
168+
</div>
169+
</ng-template>
126170
</div>
Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,64 @@
1-
import { Component, Input, OnInit } from "@angular/core";
1+
import {
2+
Component,
3+
Input,
4+
OnDestroy,
5+
OnInit,
6+
TemplateRef,
7+
ViewChild,
8+
} from "@angular/core";
29
import { SortValues, StructureCommon, UserStructureRole } from "@domifa/common";
3-
import { Subscription } from "rxjs";
10+
import { Subject, Subscription } from "rxjs";
411
import {
512
StructureService,
613
UserStructureWithSecurity,
714
} from "../../services/structure.service";
815
import { environment } from "../../../../../environments/environment";
916
import { subMonths } from "date-fns";
17+
import { NgbModal, NgbModalRef } from "@ng-bootstrap/ng-bootstrap";
1018

1119
@Component({
1220
selector: "app-users",
1321
templateUrl: "./users.component.html",
1422
styleUrl: "./users.component.css",
1523
})
16-
export class UsersComponent implements OnInit {
24+
export class UsersComponent implements OnInit, OnDestroy {
1725
public users: UserStructureWithSecurity[] = [];
1826
public sortValue: SortValues = "asc";
1927
public currentKey = "id";
2028
public twoMonthsAgo = subMonths(new Date(), 2);
21-
29+
public reloadUsers = new Subject<void>();
2230
public readonly frontendUrl = environment.frontendUrl;
2331
public readonly USER_ROLES_LABELS: { [key in UserStructureRole]: string } = {
2432
admin: "Administrateur",
2533
responsable: "Gestionnaire",
2634
simple: "Instructeur",
2735
facteur: "Facteur",
2836
};
29-
3037
@Input({ required: true }) public structure: StructureCommon;
3138
private subscription = new Subscription();
3239
public searching = true;
40+
@ViewChild("confirmPasswordReinit", { static: true })
41+
public confirmPasswordReinit!: TemplateRef<NgbModalRef>;
3342

34-
constructor(private readonly structureService: StructureService) {}
43+
public userForPasswordReinit?: UserStructureWithSecurity;
44+
constructor(
45+
private readonly structureService: StructureService,
46+
private readonly modalService: NgbModal
47+
) {}
3548

3649
ngOnInit(): void {
50+
this.loadUsers();
51+
52+
// Subscribe to reloadUsers subject to reload the list when triggered
53+
this.subscription.add(
54+
this.reloadUsers.subscribe(() => {
55+
this.loadUsers();
56+
})
57+
);
58+
}
59+
60+
private loadUsers(): void {
61+
this.searching = true;
3762
this.subscription.add(
3863
this.structureService.getUsers(this.structure.id).subscribe((users) => {
3964
this.users = users.map((user) => {
@@ -42,7 +67,31 @@ export class UsersComponent implements OnInit {
4267
}
4368
return user;
4469
});
70+
this.searching = false;
4571
})
4672
);
4773
}
74+
75+
public openConfirmationModdal(user: UserStructureWithSecurity): void {
76+
this.userForPasswordReinit = user;
77+
this.modalService.open(this.confirmPasswordReinit, {
78+
size: "s",
79+
centered: true,
80+
});
81+
}
82+
83+
public doResetPassword(email: string): void {
84+
if (!email) return;
85+
this.subscription.add(
86+
this.structureService
87+
.resetStructureAdminPassword(email)
88+
.subscribe(() => this.reloadUsers.next())
89+
);
90+
91+
this.modalService.dismissAll();
92+
}
93+
94+
ngOnDestroy(): void {
95+
this.subscription.unsubscribe();
96+
}
4897
}

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)