Skip to content

Commit

Permalink
feat(user): add certification routes
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Feb 3, 2025
1 parent 020e84f commit 41ff30d
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/controllers/user/certification-dirigeant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//

import type { NextFunction, Request, Response } from "express";
import { csrfToken } from "../../middlewares/csrf-protection";

//

export async function getCertificationDirigeantController(
req: Request,
res: Response,
next: NextFunction,
) {
try {
return res.render("user/certification-dirigeant", {
csrfToken: csrfToken(req),
pageTitle: "Certification dirigeant",
});
} catch (error) {
next(error);
}
}

export async function postCertificationDirigeantController(
_req: Request,
res: Response,
next: NextFunction,
) {
try {
return res.redirect("/users/certification-dirigeant/login-as");
} catch (error) {
next(error);
}
}

//

export async function getCertificationDirigeantLoginAsController(
req: Request,
res: Response,
next: NextFunction,
) {
try {
return res.render("user/certification-dirigeant-login-as", {
csrfToken: csrfToken(req),
pageTitle: "Se connecter en tant que",
});
} catch (error) {
next(error);
}
}

export async function postCertificationDirigeantLoginAsController(
_req: Request,
res: Response,
next: NextFunction,
) {
try {
return res.redirect("/users/certification-dirigeant/representing");
} catch (error) {
next(error);
}
}

//

export async function getCertificationDirigeantRepresentingController(
req: Request,
res: Response,
next: NextFunction,
) {
try {
const userOrganizations = [
{
id: "1",
siret: "12345678901234",
cached_libelle: "Organisation 1",
cached_adresse: "123 rue de la paix",
cached_libelle_activite_principale: "Activité principale 1",
},
];
return res.render("user/select-organization", {
csrfToken: csrfToken(req),
illustration: "illu-password.svg",
pageTitle: "Choisir une organisation",
userOrganizations,
});
} catch (error) {
next(error);
}
}
2 changes: 2 additions & 0 deletions src/middlewares/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ export const checkUserHasBeenGreetedForJoiningOrganizationMiddleware = (
try {
if (error) return next(error);

if (1) return res.redirect("/users/certification-dirigeant");

const userOrganisations = await getOrganizationsByUserId(
getUserFromAuthenticatedSession(req).id,
);
Expand Down
42 changes: 42 additions & 0 deletions src/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import {
} from "../controllers/organization";
import { postSignInWithAuthenticatorAppController } from "../controllers/totp";
import { get2faSignInController } from "../controllers/user/2fa-sign-in";
import {
getCertificationDirigeantController,
getCertificationDirigeantLoginAsController,
getCertificationDirigeantRepresentingController,
postCertificationDirigeantController,
postCertificationDirigeantLoginAsController,
} from "../controllers/user/certification-dirigeant";
import { postDeleteUserController } from "../controllers/user/delete";
import { postCancelModerationAndRedirectControllerFactory } from "../controllers/user/edit-moderation";
import { issueSessionOrRedirectController } from "../controllers/user/issue-session-or-redirect";
Expand Down Expand Up @@ -418,6 +425,41 @@ export const userRouter = () => {
postDeleteUserController,
);

userRouter.get(
"/certification-dirigeant",
rateLimiterMiddleware,
csrfProtectionMiddleware,
getCertificationDirigeantController,
);

userRouter.post(
"/certification-dirigeant",
rateLimiterMiddleware,
csrfProtectionMiddleware,
postCertificationDirigeantController,
);

userRouter.get(
"/certification-dirigeant/login-as",
rateLimiterMiddleware,
csrfProtectionMiddleware,
getCertificationDirigeantLoginAsController,
);

userRouter.post(
"/certification-dirigeant/login-as",
rateLimiterMiddleware,
csrfProtectionMiddleware,
postCertificationDirigeantLoginAsController,
);

userRouter.get(
"/certification-dirigeant/representing",
rateLimiterMiddleware,
csrfProtectionMiddleware,
getCertificationDirigeantRepresentingController,
);

return userRouter;
};

Expand Down
24 changes: 24 additions & 0 deletions src/views/user/certification-dirigeant-login-as.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div>
<h2 class="fr-h2">Vous allez vous connecter en tant que :</h2>
<center>
<h1 class="fr-h3 blue-france">Jacintha Froment</h1>
</center>

<form action="/users/certification-dirigeant/login-as" method="post">
<input type="hidden" name="_csrf" value="<%= csrfToken; %>" />

<fieldset class="fr-fieldset" aria-labelledby="agreement">
<div class="fr-fieldset__element">
<div class="fr-checkbox-group">
<input name="agreement" id="agreement" type="checkbox" />
<label class="fr-label" for="agreement">
J'accepte que FranceConnect transmette mes données au service pour
me connecter
</label>
</div>
</div>
</fieldset>

<button class="fr-btn" type="submit">Continuer</button>
</form>
</div>
28 changes: 28 additions & 0 deletions src/views/user/certification-dirigeant.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div>
<h1 class="fr-h3">Authentifier votre statut</h1>

<p>
Vous pouvez authentifier instantanément votre statut de dirigeant grâce à
FranceConnect.
</p>

<form action="/users/certification-dirigeant" method="post">
<input type="hidden" name="_csrf" value="<%= csrfToken; %>" />

<div class="fr-connect-group">
<button class="fr-connect">
<span class="fr-connect__login">S’identifier avec</span>
<span class="fr-connect__brand">FranceConnect</span>
</button>
<p>
<a
href="https://franceconnect.gouv.fr/"
target="_blank"
rel="noopener"
title="Qu’est-ce que FranceConnect ? - nouvelle fenêtre"
>Qu’est-ce que FranceConnect ?</a
>
</p>
</div>
</form>
</div>

0 comments on commit 41ff30d

Please sign in to comment.