Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b05fd91411 | |||
| aaa9d0812b | |||
| 7568afb888 | |||
| 6371fca14a | |||
| e111d5be28 | |||
| c70d4a5f11 | |||
| ad5c271b05 | |||
| 19a588ac25 | |||
| ad524978df | |||
| 2ce78547b7 | |||
| 81a3fc0e03 | |||
| 2615961bf1 | |||
| fb967e3af3 | |||
| c283a34784 | |||
| a48c616ecc | |||
| cd1149a23a | |||
| 58c8ff56ba |
@@ -0,0 +1,27 @@
|
|||||||
|
name: "Build and push image"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
name: "Build Docker image"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: registry.docker.polytech.djalim.fr
|
||||||
|
username: ${{ secrets.registry_login }}
|
||||||
|
password: ${{ secrets.registry_pass }}
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: registry.docker.polytech.djalim.fr/polympr:latest
|
||||||
+3
-2
@@ -3,10 +3,11 @@ FROM denoland/deno:alpine
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN deno cache main.ts --allow-import flag
|
|
||||||
|
RUN deno cache main.ts --allow-import
|
||||||
RUN deno task build
|
RUN deno task build
|
||||||
|
|
||||||
USER deno
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
EXPOSE 443
|
EXPOSE 443
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,12 @@ import { AsyncRoute } from "$fresh/src/server/types.ts";
|
|||||||
|
|
||||||
export interface AuthenticatedState {
|
export interface AuthenticatedState {
|
||||||
isAuthenticated: true;
|
isAuthenticated: true;
|
||||||
isFromPolytech: boolean;
|
session: CasContent;
|
||||||
role: "etudiant" | "professeur" | "administration" | "autre";
|
|
||||||
displayName: string;
|
|
||||||
uid: string;
|
|
||||||
availablePages: Record<string, string>;
|
availablePages: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UnauthenticatedState {
|
interface UnauthenticatedState {
|
||||||
isAuthenticated: false;
|
isAuthenticated: false;
|
||||||
isFromPolytech: false;
|
|
||||||
session: undefined;
|
session: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#Local mode, set to true to access admin pages with any users
|
||||||
|
LOCAL=false
|
||||||
+1
-1
@@ -2,7 +2,7 @@ import { defineConfig } from "$fresh/server.ts";
|
|||||||
import ensureDatabases from "$root/databases/ensure.ts";
|
import ensureDatabases from "$root/databases/ensure.ts";
|
||||||
import { load } from "@std/dotenv";
|
import { load } from "@std/dotenv";
|
||||||
|
|
||||||
await load({ envPath: "./.env.development.local", export: true });
|
await load({ envPath: "./.env", export: true });
|
||||||
await ensureDatabases();
|
await ensureDatabases();
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
server: {
|
server: {
|
||||||
|
|||||||
+10
-4
@@ -3,8 +3,9 @@
|
|||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
import * as $_apps_layout from "./routes/(apps)/_layout.tsx";
|
import * as $_apps_layout from "./routes/(apps)/_layout.tsx";
|
||||||
import * as $_apps_middleware from "./routes/(apps)/_middleware.ts";
|
import * as $_apps_mobility_api_download from "./routes/(apps)/mobility/api/download.ts";
|
||||||
import * as $_apps_mobility_api_insert_mobility from "./routes/(apps)/mobility/api/insert_mobility.ts";
|
import * as $_apps_mobility_api_download_id_ from "./routes/(apps)/mobility/api/download/[id].ts";
|
||||||
|
import * as $_apps_mobility_api_insert_mobility from "./routes/(apps)/mobility/api/insert-mobility.ts";
|
||||||
import * as $_apps_mobility_index from "./routes/(apps)/mobility/index.tsx";
|
import * as $_apps_mobility_index from "./routes/(apps)/mobility/index.tsx";
|
||||||
import * as $_apps_mobility_partials_admin_edit_mobility from "./routes/(apps)/mobility/partials/(admin)/edit_mobility.tsx";
|
import * as $_apps_mobility_partials_admin_edit_mobility from "./routes/(apps)/mobility/partials/(admin)/edit_mobility.tsx";
|
||||||
import * as $_apps_mobility_partials_index from "./routes/(apps)/mobility/partials/index.tsx";
|
import * as $_apps_mobility_partials_index from "./routes/(apps)/mobility/partials/index.tsx";
|
||||||
@@ -19,7 +20,6 @@ import * as $_apps_students_partials_admin_consult from "./routes/(apps)/student
|
|||||||
import * as $_apps_students_partials_admin_upload from "./routes/(apps)/students/partials/(admin)/upload.tsx";
|
import * as $_apps_students_partials_admin_upload from "./routes/(apps)/students/partials/(admin)/upload.tsx";
|
||||||
import * as $_apps_students_partials_index from "./routes/(apps)/students/partials/index.tsx";
|
import * as $_apps_students_partials_index from "./routes/(apps)/students/partials/index.tsx";
|
||||||
import * as $_apps_students_types_d from "./routes/(apps)/students/types.d.ts";
|
import * as $_apps_students_types_d from "./routes/(apps)/students/types.d.ts";
|
||||||
import * as $_403 from "./routes/_403.tsx";
|
|
||||||
import * as $_404 from "./routes/_404.tsx";
|
import * as $_404 from "./routes/_404.tsx";
|
||||||
import * as $_app from "./routes/_app.tsx";
|
import * as $_app from "./routes/_app.tsx";
|
||||||
import * as $_middleware from "./routes/_middleware.ts";
|
import * as $_middleware from "./routes/_middleware.ts";
|
||||||
@@ -41,8 +41,15 @@ import type { Manifest } from "$fresh/server.ts";
|
|||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
"./routes/(apps)/_layout.tsx": $_apps_layout,
|
"./routes/(apps)/_layout.tsx": $_apps_layout,
|
||||||
|
<<<<<<< HEAD
|
||||||
"./routes/(apps)/_middleware.ts": $_apps_middleware,
|
"./routes/(apps)/_middleware.ts": $_apps_middleware,
|
||||||
"./routes/(apps)/mobility/api/insert_mobility.ts":
|
"./routes/(apps)/mobility/api/insert_mobility.ts":
|
||||||
|
=======
|
||||||
|
"./routes/(apps)/mobility/api/download.ts": $_apps_mobility_api_download,
|
||||||
|
"./routes/(apps)/mobility/api/download/[id].ts":
|
||||||
|
$_apps_mobility_api_download_id_,
|
||||||
|
"./routes/(apps)/mobility/api/insert-mobility.ts":
|
||||||
|
>>>>>>> 4f1011d (Ultimate fix and tested ! You can download contract now.)
|
||||||
$_apps_mobility_api_insert_mobility,
|
$_apps_mobility_api_insert_mobility,
|
||||||
"./routes/(apps)/mobility/index.tsx": $_apps_mobility_index,
|
"./routes/(apps)/mobility/index.tsx": $_apps_mobility_index,
|
||||||
"./routes/(apps)/mobility/partials/(admin)/edit_mobility.tsx":
|
"./routes/(apps)/mobility/partials/(admin)/edit_mobility.tsx":
|
||||||
@@ -65,7 +72,6 @@ const manifest = {
|
|||||||
"./routes/(apps)/students/partials/index.tsx":
|
"./routes/(apps)/students/partials/index.tsx":
|
||||||
$_apps_students_partials_index,
|
$_apps_students_partials_index,
|
||||||
"./routes/(apps)/students/types.d.ts": $_apps_students_types_d,
|
"./routes/(apps)/students/types.d.ts": $_apps_students_types_d,
|
||||||
"./routes/_403.tsx": $_403,
|
|
||||||
"./routes/_404.tsx": $_404,
|
"./routes/_404.tsx": $_404,
|
||||||
"./routes/_app.tsx": $_app,
|
"./routes/_app.tsx": $_app,
|
||||||
"./routes/_middleware.ts": $_middleware,
|
"./routes/_middleware.ts": $_middleware,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const handler: MiddlewareHandler<AuthenticatedState>[] = [
|
|||||||
|
|
||||||
context.state.availablePages = properties.pages;
|
context.state.availablePages = properties.pages;
|
||||||
if (
|
if (
|
||||||
context.state.role == "etudiant" &&
|
context.state.session.eduPersonPrimaryAffiliation == "student" &&
|
||||||
Deno.env.get("LOCAL") != "true"
|
Deno.env.get("LOCAL") != "true"
|
||||||
) {
|
) {
|
||||||
properties.adminOnly.forEach((page) =>
|
properties.adminOnly.forEach((page) =>
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ export default function EditMobility() {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<button onClick={handleSave} disabled={isSaving}>
|
<button type="button" onClick={handleSave} disabled={isSaving}>
|
||||||
{isSaving ? "Saving..." : "Confirm"}
|
{isSaving ? "Saving..." : "Confirm"}
|
||||||
</button>
|
</button>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { Handlers } from "$fresh/server.ts";
|
||||||
|
import connect from "$root/databases/connect.ts";
|
||||||
|
|
||||||
|
export const handler: Handlers = {
|
||||||
|
async GET(_request, ctx) {
|
||||||
|
try {
|
||||||
|
const { id } = ctx.params;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return new Response("Invalid request: Missing ID", { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
using connection = connect("mobility");
|
||||||
|
|
||||||
|
const query = connection.database.prepare(
|
||||||
|
"SELECT attestationFile FROM mobility WHERE id = ?",
|
||||||
|
);
|
||||||
|
const result = query.get(id);
|
||||||
|
|
||||||
|
if (!result || !result.attestationFile) {
|
||||||
|
return new Response("No file found for the given ID", { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(result.attestationFile, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/pdf",
|
||||||
|
"Content-Disposition": `attachment; filename="attestation_${id}.pdf"`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching file:", error);
|
||||||
|
return new Response("Failed to fetch file", { status: 500 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
import { Handlers } from "$fresh/server.ts";
|
||||||
|
import connect from "$root/databases/connect.ts";
|
||||||
|
|
||||||
|
export const handler: Handlers = {
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
async GET() {
|
||||||
|
try {
|
||||||
|
using connection = connect("mobility");
|
||||||
|
|
||||||
|
const mobilities = connection.database.prepare(
|
||||||
|
`SELECT
|
||||||
|
mobility.id,
|
||||||
|
mobility.studentId,
|
||||||
|
mobility.startDate,
|
||||||
|
mobility.endDate,
|
||||||
|
mobility.weeksCount,
|
||||||
|
mobility.destinationCountry,
|
||||||
|
mobility.destinationName,
|
||||||
|
mobility.mobilityStatus,
|
||||||
|
mobility.attestationFile -- Inclure le fichier
|
||||||
|
FROM mobility`
|
||||||
|
).all();
|
||||||
|
|
||||||
|
const students = connection.database.prepare(
|
||||||
|
`SELECT
|
||||||
|
students.userId AS id,
|
||||||
|
students.firstName,
|
||||||
|
students.lastName,
|
||||||
|
students.promotionId AS promotionId,
|
||||||
|
promotions.name AS promotionName
|
||||||
|
FROM students.students
|
||||||
|
LEFT JOIN students.promotions ON students.promotionId = promotions.id`
|
||||||
|
).all();
|
||||||
|
|
||||||
|
const promotions = connection.database.prepare(
|
||||||
|
`SELECT id, name FROM students.promotions`
|
||||||
|
).all();
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ mobilities, students, promotions }),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching mobility data:", error);
|
||||||
|
return new Response("Failed to fetch data", { status: 500 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async POST(request) {
|
||||||
|
console.log("API /mobility/api/insert-mobility POST called");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formData = await request.formData();
|
||||||
|
const dataEntries = formData.getAll("data").map((item) => JSON.parse(item as string));
|
||||||
|
console.log("Parsed data entries:", dataEntries);
|
||||||
|
|
||||||
|
const fileMap: Record<string, Uint8Array> = {};
|
||||||
|
for (const [key, value] of formData.entries()) {
|
||||||
|
if (key.startsWith("file_") && value instanceof File) {
|
||||||
|
const studentId = key.split("_")[1];
|
||||||
|
const file = value as File;
|
||||||
|
fileMap[studentId] = new Uint8Array(await file.arrayBuffer());
|
||||||
|
console.log(`File processed for studentId ${studentId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using connection = connect("mobility");
|
||||||
|
const insertQuery = connection.database.prepare(
|
||||||
|
`INSERT INTO mobility (
|
||||||
|
id, studentId, startDate, endDate, weeksCount, destinationCountry, destinationName, mobilityStatus, attestationFile
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
|
startDate = excluded.startDate,
|
||||||
|
endDate = excluded.endDate,
|
||||||
|
weeksCount = excluded.weeksCount,
|
||||||
|
destinationCountry = excluded.destinationCountry,
|
||||||
|
destinationName = excluded.destinationName,
|
||||||
|
mobilityStatus = excluded.mobilityStatus,
|
||||||
|
attestationFile = COALESCE(excluded.attestationFile, mobility.attestationFile)`
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const mobility of dataEntries) {
|
||||||
|
const {
|
||||||
|
id = null,
|
||||||
|
studentId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
destinationCountry,
|
||||||
|
destinationName,
|
||||||
|
mobilityStatus = "N/A",
|
||||||
|
} = mobility;
|
||||||
|
|
||||||
|
let calculatedWeeksCount = null;
|
||||||
|
if (startDate && endDate) {
|
||||||
|
const start = new Date(startDate);
|
||||||
|
const end = new Date(endDate);
|
||||||
|
if (start <= end) {
|
||||||
|
const differenceInDays = Math.ceil(
|
||||||
|
(end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000)
|
||||||
|
);
|
||||||
|
calculatedWeeksCount = Math.floor(differenceInDays / 7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const attestationFile = fileMap[studentId] ?? null;
|
||||||
|
|
||||||
|
console.log(`Inserting/Updating mobility for studentId: ${studentId}`);
|
||||||
|
insertQuery.run(
|
||||||
|
id,
|
||||||
|
studentId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
calculatedWeeksCount,
|
||||||
|
destinationCountry,
|
||||||
|
destinationName,
|
||||||
|
mobilityStatus,
|
||||||
|
attestationFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Mobility data inserted/updated successfully.");
|
||||||
|
return new Response("Data inserted/updated successfully", { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error inserting mobility data:", error);
|
||||||
|
return new Response("Failed to insert/update data", { status: 500 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
export async function Index(_request: Request, context: FreshContext<State>) {
|
export async function Index(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async function Courses(_request: Request, context: FreshContext<State>) {
|
async function Courses(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
export async function Index(_request: Request, context: FreshContext<State>) {
|
export async function Index(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async function Notes(_request: Request, context: FreshContext<State>) {
|
async function Notes(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default function Promotion(props: PromotionProps) {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{props.students
|
{props.students
|
||||||
.filter((student) => student.promotionId === props.promo.id)
|
.filter((student) => student.promotionId === props.promo.id)
|
||||||
.map((student) => <Student student={student} />)}
|
.map((student) => <Student key={student.id} student={student} />)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export default function UploadStudents() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<input type="file" accept=".xlsx, .xls" onChange={handleFileChange} />
|
<input type="file" accept=".xlsx, .xls" onChange={handleFileChange} />
|
||||||
<button onClick={confirmUpload}>Confirm Upload</button>
|
<button type="button" onClick={confirmUpload}>Confirm Upload</button>
|
||||||
<p>{statusMessage.value}</p>
|
<p>{statusMessage.value}</p>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { Handlers } from "$fresh/server.ts";
|
||||||
|
import connect from "$root/databases/connect.ts";
|
||||||
|
|
||||||
|
// Rendre l'API plus simple car xlsx pour l'import c'est nul :/
|
||||||
|
export const handler: Handlers = {
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
async GET() {
|
||||||
|
try {
|
||||||
|
using connection = connect("students");
|
||||||
|
|
||||||
|
const promotions = connection.database.prepare(
|
||||||
|
"select id, name from promotions",
|
||||||
|
).all();
|
||||||
|
|
||||||
|
const students = connection.database
|
||||||
|
.prepare(
|
||||||
|
`select userId, firstName, lastName, mail, promotionId from students`,
|
||||||
|
)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ promotions, students }),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching data:", error);
|
||||||
|
return new Response("Failed to fetch data", { status: 500 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async POST(request) {
|
||||||
|
console.log("API /students/api/insert_students called");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const body = await request.json();
|
||||||
|
const { data, promoName } = body;
|
||||||
|
|
||||||
|
console.log("Received data:", { promoName, data });
|
||||||
|
|
||||||
|
if (!promoName || !Array.isArray(data)) {
|
||||||
|
throw new Error("Invalid request body");
|
||||||
|
}
|
||||||
|
|
||||||
|
using connection = connect("students");
|
||||||
|
|
||||||
|
connection.database.prepare(
|
||||||
|
"INSERT OR IGNORE INTO promotions (name) VALUES (?)",
|
||||||
|
).run(promoName);
|
||||||
|
|
||||||
|
const promoIdRow: { id: number } = connection.database
|
||||||
|
.prepare("SELECT id FROM promotions WHERE name = ?")
|
||||||
|
.get(promoName)!;
|
||||||
|
const promoId = promoIdRow.id;
|
||||||
|
|
||||||
|
console.log(`Promotion ID for "${promoName}":`, promoId);
|
||||||
|
|
||||||
|
const insertQuery = connection.database.prepare(
|
||||||
|
`INSERT INTO students
|
||||||
|
(userId, firstName, lastName, mail, promotionId)
|
||||||
|
VALUES (?, ?, ?, ?, ?)`,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const student of data) {
|
||||||
|
console.log("Inserting student:", student);
|
||||||
|
insertQuery.run(
|
||||||
|
student.Identifiant,
|
||||||
|
student.Nom,
|
||||||
|
student["Prénom"],
|
||||||
|
student.Mail,
|
||||||
|
promoId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("All data inserted successfully");
|
||||||
|
return new Response("Data inserted successfully", { status: 201 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error inserting data:", error);
|
||||||
|
return new Response("Failed to insert data", { status: 500 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -92,9 +92,9 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
using connection = connect("students");
|
using connection = connect("students");
|
||||||
const database = connection.database;
|
const database = connection.database;
|
||||||
|
|
||||||
if (context.state.role == "etudiant") {
|
if (context.state.session.eduPersonPrimaryAffiliation == "student") {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify(getItself(database, context.state.uid)),
|
JSON.stringify(getItself(database, context.state.session.uid)),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
|||||||
@@ -8,7 +8,13 @@ import SelfPortrait from "$root/routes/(apps)/students/(_components)/SelfPortrai
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
export async function Index(_request: Request, context: FreshContext<State>) {
|
export async function Index(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome {context.state.displayName || 'Guest'}!</h2>;
|
return (
|
||||||
|
<>
|
||||||
|
<h2>Welcome {context.state.session?.givenName}!</h2>
|
||||||
|
<h3>Your amU identity</h3>
|
||||||
|
<SelfPortrait self={context.state.session!} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import { Head } from "$fresh/runtime.ts";
|
|
||||||
|
|
||||||
export default function Error403() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>403 - Forbidden</title>
|
|
||||||
</Head>
|
|
||||||
<p>403</p>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+2
-33
@@ -44,7 +44,6 @@ export function getKey(user: string): string {
|
|||||||
export const handler: MiddlewareHandler<State>[] = [
|
export const handler: MiddlewareHandler<State>[] = [
|
||||||
/**
|
/**
|
||||||
* Check if user is authenticated and add session to context accordingly.
|
* Check if user is authenticated and add session to context accordingly.
|
||||||
* Only authenticated users who are members of Polytech are allowed.
|
|
||||||
* @param request The HTTP incomming request.
|
* @param request The HTTP incomming request.
|
||||||
* @param context The Fresh context object with custom `State`.
|
* @param context The Fresh context object with custom `State`.
|
||||||
* @returns The response from the next middleware.
|
* @returns The response from the next middleware.
|
||||||
@@ -56,7 +55,6 @@ export const handler: MiddlewareHandler<State>[] = [
|
|||||||
const cookies = getCookies(request.headers);
|
const cookies = getCookies(request.headers);
|
||||||
if (!cookies["sessionToken"]) {
|
if (!cookies["sessionToken"]) {
|
||||||
context.state.isAuthenticated = false;
|
context.state.isAuthenticated = false;
|
||||||
context.state.isFromPolytech = false;
|
|
||||||
return await context.next();
|
return await context.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,27 +67,9 @@ export const handler: MiddlewareHandler<State>[] = [
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (context.state.isAuthenticated) {
|
if (context.state.isAuthenticated) {
|
||||||
|
|
||||||
const session: CasContent =
|
const session: CasContent =
|
||||||
(getJwtPayload(cookies["sessionToken"]) as LoginJWT).user;
|
(getJwtPayload(cookies["sessionToken"]) as LoginJWT).user;
|
||||||
|
context.state.session = session;
|
||||||
const isFromPolytech = session.amuComposante.includes("polytech");
|
|
||||||
context.state.isFromPolytech = isFromPolytech;
|
|
||||||
|
|
||||||
if (isFromPolytech) {
|
|
||||||
context.state.displayName = session.displayName;
|
|
||||||
context.state.uid = session.uid;
|
|
||||||
|
|
||||||
if (session.eduPersonPrimaryAffiliation == "faculty") {
|
|
||||||
context.state.role = "professeur"
|
|
||||||
} else if (session.eduPersonPrimaryAffiliation == "employee") {
|
|
||||||
context.state.role = "administration"
|
|
||||||
} else if (session.eduPersonPrimaryAffiliation == "student") {
|
|
||||||
context.state.role = "etudiant";
|
|
||||||
} else {
|
|
||||||
context.state.role = "autre";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await context.next();
|
return await context.next();
|
||||||
@@ -107,8 +87,7 @@ export const handler: MiddlewareHandler<State>[] = [
|
|||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
|
|
||||||
if (!isRoutePublic(url.pathname)) {
|
if (!isRoutePublic(url.pathname) && !context.state.isAuthenticated) {
|
||||||
if (!context.state.isAuthenticated) {
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 302,
|
status: 302,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -117,16 +96,6 @@ export const handler: MiddlewareHandler<State>[] = [
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.state.isFromPolytech) {
|
|
||||||
return new Response(null, {
|
|
||||||
status: 403,
|
|
||||||
headers: {
|
|
||||||
Location: "/403",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return await context.next();
|
return await context.next();
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user