Skip to content

Commit 14ef9a6

Browse files
committed
fix(frontend): fix login in 'mon-domifa' & register multiple users
1 parent 425cf19 commit 14ef9a6

File tree

5 files changed

+109
-23
lines changed

5 files changed

+109
-23
lines changed

packages/backend/src/auth/guards/AppUserGuard.guard.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { UserStructureRole, UserSupervisorRole } from "@domifa/common";
22
import { CanActivate, ExecutionContext, Injectable } from "@nestjs/common";
33
import { Reflector } from "@nestjs/core";
44
import { getCurrentScope } from "@sentry/node";
5-
import { UserProfile, UserStructureAuthenticated } from "../../_common/model";
5+
import {
6+
UserProfile,
7+
UserStructureAuthenticated,
8+
UserUsagerAuthenticated,
9+
} from "../../_common/model";
610
import { UserSupervisorAuthenticated } from "../../_common/model/users/user-supervisor";
711
import { expiredTokenRepositiory } from "../../database";
812
import { addLogContext, appLogger } from "../../util";
@@ -15,6 +19,7 @@ export class AppUserGuard implements CanActivate {
1519
public async canActivate(context: ExecutionContext): Promise<boolean> {
1620
const request = context.switchToHttp().getRequest();
1721
const user = request.user as
22+
| UserUsagerAuthenticated
1823
| UserStructureAuthenticated
1924
| UserSupervisorAuthenticated;
2025

@@ -25,18 +30,29 @@ export class AppUserGuard implements CanActivate {
2530
},
2631
});
2732

28-
let userScope = {
29-
email: user.email,
33+
let userScope: {
34+
id: number;
35+
structureId?: number | null;
36+
role?: UserSupervisorRole | UserStructureRole;
37+
email?: string | null;
38+
} = {
3039
id: user._userId,
31-
role: user.role,
3240
structureId: null,
3341
};
3442

3543
if (user._userProfile === "structure") {
3644
userScope = {
3745
...userScope,
46+
role: user?.role,
47+
email: user?.email,
3848
structureId: user?.structureId,
3949
};
50+
} else if (user._userProfile === "supervisor") {
51+
userScope = {
52+
...userScope,
53+
role: user?.role,
54+
email: user?.email,
55+
};
4056
}
4157

4258
getCurrentScope().setUser(userScope);
@@ -103,6 +119,10 @@ export class AppUserGuard implements CanActivate {
103119
const isValidProfile = authChecker.checkProfile(user, ...allowUserProfiles);
104120

105121
if (isValidProfile) {
122+
if (user._userProfile === "usager") {
123+
return true;
124+
}
125+
106126
if (
107127
user._userProfile === "structure" &&
108128
allowUserStructureRoles?.length

packages/frontend/src/app/modules/manage-users/components/register-user-admin/register-user-admin.component.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class RegisterUserAdminComponent implements OnInit, OnDestroy {
4444

4545
private subscription = new Subscription();
4646
private unsubscribe: Subject<void> = new Subject();
47+
public me!: UserStructure | null;
4748

4849
@Output() public getUsers = new EventEmitter<void>();
4950

@@ -66,7 +67,7 @@ export class RegisterUserAdminComponent implements OnInit, OnDestroy {
6667
}
6768

6869
public ngOnInit(): void {
69-
const user = this.authService.currentUserValue;
70+
this.me = this.authService.currentUserValue;
7071

7172
this.userForm = this.formBuilder.group({
7273
email: [
@@ -83,7 +84,7 @@ export class RegisterUserAdminComponent implements OnInit, OnDestroy {
8384
this.user.prenom,
8485
[Validators.required, Validators.minLength(2), NoWhiteSpaceValidator],
8586
],
86-
structureId: [user?.structureId, []],
87+
structureId: [this.me.structureId, []],
8788
});
8889
}
8990

@@ -97,23 +98,28 @@ export class RegisterUserAdminComponent implements OnInit, OnDestroy {
9798
} else {
9899
this.loading = true;
99100
this.subscription.add(
100-
this.usersService.registerUser(this.userForm.value).subscribe({
101-
next: () => {
102-
this.loading = false;
103-
this.submitted = false;
104-
this.getUsers.emit();
105-
this.form.nativeElement.reset();
106-
this.toastService.success(
107-
"Le nouveau compte a été créé avec succès, votre collaborateur vient de recevoir un email pour ajouter son mot de passe."
108-
);
109-
},
110-
error: () => {
111-
this.loading = false;
112-
this.toastService.error(
113-
"veuillez vérifier les champs marqués en rouge dans le formulaire"
114-
);
115-
},
116-
})
101+
this.usersService
102+
.registerUser({
103+
...this.userForm.value,
104+
structureId: this.me.structureId,
105+
})
106+
.subscribe({
107+
next: () => {
108+
this.loading = false;
109+
this.submitted = false;
110+
this.getUsers.emit();
111+
this.form.nativeElement.reset();
112+
this.toastService.success(
113+
"Le nouveau compte a été créé avec succès, votre collaborateur vient de recevoir un email pour ajouter son mot de passe."
114+
);
115+
},
116+
error: () => {
117+
this.loading = false;
118+
this.toastService.error(
119+
"veuillez vérifier les champs marqués en rouge dans le formulaire"
120+
);
121+
},
122+
})
117123
);
118124
}
119125
}

packages/portail-usagers/src/app/modules/shared/components/custom-toastr/custom-toastr.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { CustomToast } from "../../types/CustomToast.type";
66

77
import { CustomToastClass } from "../../types";
88
import { IconName } from "@fortawesome/fontawesome-svg-core";
9+
import { fadeIn } from "../../../../shared";
910

1011
@Component({
12+
animations: [fadeIn],
1113
selector: "app-custom-toastr",
1214
templateUrl: "./custom-toastr.component.html",
1315
styleUrls: ["./custom-toastr.component.css"],
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
animate,
3+
animation,
4+
keyframes,
5+
style,
6+
transition,
7+
trigger,
8+
useAnimation,
9+
} from "@angular/animations";
10+
11+
export const fadeIn = trigger("fadeIn", [
12+
transition(":enter", [
13+
style({ opacity: 0 }),
14+
animate("0.3s ease-in", style({ opacity: 1 })),
15+
]),
16+
]);
17+
18+
export const fadeInOut = trigger("fadeInOut", [
19+
transition(":enter", [
20+
style({ opacity: 0 }),
21+
animate("0.3s ease-in", style({ opacity: 1 })),
22+
]),
23+
transition(":leave", [
24+
style({ opacity: 1 }),
25+
animate("0.5s ease-in-out", style({ opacity: 0 })),
26+
]),
27+
]);
28+
29+
export const bounce = trigger("bounce", [
30+
transition(":leave, * => 0", [
31+
style({ opacity: 1 }),
32+
animate(100, style({ opacity: 0 })),
33+
]),
34+
transition(
35+
":increment, :decrement",
36+
useAnimation(
37+
animation(
38+
animate(
39+
"{{ timing }}s {{ delay }}s cubic-bezier(0.215, 0.610, 0.355, 1.000)",
40+
keyframes([
41+
style({ opacity: 0, transform: "scale3d(.3, .3, .3)", offset: 0 }),
42+
style({ transform: "scale3d(1.1, 1.1, 1.1)", offset: 0.2 }),
43+
style({ transform: "scale3d(.9, .9, .9)", offset: 0.4 }),
44+
style({
45+
opacity: 1,
46+
transform: "scale3d(1.1, 1.1, 1.1)",
47+
offset: 0.6,
48+
}),
49+
style({ transform: "scale3d(.95, .95, .95)", offset: 0.8 }),
50+
style({ opacity: 1, transform: "scale3d(1, 1, 1)", offset: 1 }),
51+
]),
52+
),
53+
{ params: { timing: 0.5, delay: 0 } },
54+
),
55+
),
56+
),
57+
]);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
//@index('./*', f => `export * from '${f.path}'`)
2+
export * from "./animations";
23
export * from "./MATOMO_INJECTORS.const";

0 commit comments

Comments
 (0)