Add logs
All checks were successful
All checks were successful
This commit is contained in:
parent
c33d4faacd
commit
8d5871fcf0
@ -31,51 +31,56 @@ export default class UserController extends ApiController {
|
||||
@Post("/api/v1/idnot/user/:code")
|
||||
protected async getUserInfosFromIdnot(req: Request, response: Response) {
|
||||
try {
|
||||
console.error("[getUserInfosFromIdnot] Début de la fonction");
|
||||
const code = req.params["code"];
|
||||
console.log("code", code);
|
||||
console.error("[getUserInfosFromIdnot] Code reçu:", code);
|
||||
|
||||
if (!code) throw new Error("code is required");
|
||||
|
||||
console.error("[getUserInfosFromIdnot] Tentative de récupération du token IdNot");
|
||||
const idNotToken = await this.idNotService.getIdNotToken(code);
|
||||
console.log("idNotToken", idNotToken);
|
||||
console.error("[getUserInfosFromIdnot] Token IdNot reçu:", idNotToken);
|
||||
|
||||
if (!idNotToken) {
|
||||
console.error("IdNot token undefined");
|
||||
console.error("[getUserInfosFromIdnot] Erreur: Token IdNot non défini");
|
||||
this.httpValidationError(response, "IdNot token undefined");
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("[getUserInfosFromIdnot] Tentative de création/récupération de l'utilisateur");
|
||||
const user = await this.idNotService.getOrCreateUser(idNotToken);
|
||||
console.log("user", user);
|
||||
console.error("[getUserInfosFromIdnot] Utilisateur récupéré:", user);
|
||||
|
||||
if (!user) {
|
||||
console.error("User not found");
|
||||
console.error("[getUserInfosFromIdnot] Erreur: Utilisateur non trouvé");
|
||||
this.httpUnauthorized(response, "Email not found");
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("[getUserInfosFromIdnot] Mise à jour de l'utilisateur");
|
||||
await this.idNotService.updateUser(user.uid);
|
||||
|
||||
//Whitelist feature
|
||||
//Get user with contact
|
||||
console.error("[getUserInfosFromIdnot] Récupération des données Prisma de l'utilisateur");
|
||||
const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true });
|
||||
|
||||
if (!prismaUser) {
|
||||
console.error("Prisma user not found");
|
||||
console.error("[getUserInfosFromIdnot] Erreur: Utilisateur Prisma non trouvé");
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate user to be able to use his contact
|
||||
console.error("[getUserInfosFromIdnot] Hydratation de l'utilisateur");
|
||||
const userHydrated = User.hydrate<User>(prismaUser, { strategy: "excludeAll" });
|
||||
|
||||
|
||||
if (!userHydrated.contact?.email || userHydrated.contact?.email === "") {
|
||||
console.error("Email not found");
|
||||
console.error("[getUserInfosFromIdnot] Erreur: Email non trouvé pour l'utilisateur hydraté");
|
||||
this.httpUnauthorized(response, "Email not found");
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("[getUserInfosFromIdnot] Vérification de l'abonnement");
|
||||
let isSubscribed = await this.subscriptionsService.isUserSubscribed(user.uid, userHydrated.office_membership?.uid!);
|
||||
console.error("[getUserInfosFromIdnot] Statut de l'abonnement:", isSubscribed);
|
||||
|
||||
//Check if user is whitelisted
|
||||
// const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
|
||||
@ -91,16 +96,17 @@ export default class UserController extends ApiController {
|
||||
|
||||
await this.idNotService.updateOffice(user.office_uid);
|
||||
|
||||
console.error("[getUserInfosFromIdnot] Récupération du payload JWT");
|
||||
const payload = await this.authService.getUserJwtPayload(user.idNot);
|
||||
console.log("payload", payload);
|
||||
|
||||
console.error("[getUserInfosFromIdnot] Payload JWT:", payload);
|
||||
|
||||
if (!payload) {
|
||||
console.error("No payload");
|
||||
console.error("[getUserInfosFromIdnot] Erreur: Pas de payload JWT");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSubscribed && (userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin")) {
|
||||
console.error("[getUserInfosFromIdnot] Utilisateur admin/super-admin non abonné - récupération des règles spéciales");
|
||||
|
||||
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({
|
||||
where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" },
|
||||
@ -110,26 +116,31 @@ export default class UserController extends ApiController {
|
||||
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
if (!manageSubscriptionRules[0]) return;
|
||||
if (!manageSubscriptionRules[0]) {
|
||||
console.error("[getUserInfosFromIdnot] Erreur: Règles de gestion d'abonnement non trouvées");
|
||||
return;
|
||||
}
|
||||
|
||||
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
|
||||
console.error("[getUserInfosFromIdnot] Règles appliquées:", payload.rules);
|
||||
|
||||
isSubscribed = true;
|
||||
}
|
||||
|
||||
if (!isSubscribed) {
|
||||
console.error("User not subscribed");
|
||||
console.error("[getUserInfosFromIdnot] Erreur: Utilisateur non abonné");
|
||||
this.httpUnauthorized(response, "User not subscribed");
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("[getUserInfosFromIdnot] Génération des tokens");
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
console.log("SUCCESSFUL LOGIN");
|
||||
console.error("[getUserInfosFromIdnot] CONNEXION RÉUSSIE");
|
||||
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error("[getUserInfosFromIdnot] Erreur critique:", error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user