feat(frontend): check that the teacher is valid before setting the cookie

This commit is contained in:
Mariano Riefolo 2024-09-03 16:42:59 +02:00
parent 99be91941a
commit b6ef022f15

View File

@ -18,6 +18,7 @@ function load_teachers(id) {
fetch(`/api/professori?id=${id}`)
.then((response) => response.json())
.then((data) => {
sessionStorage.setItem("teachers", JSON.stringify(data));
let i = 0;
data.forEach((el) => {
const select = document.getElementById("teachers");
@ -151,8 +152,13 @@ function load_major() {
}
function select_teacher() {
let teacher = document.getElementById("teacher").value;
let teachers = JSON.parse(sessionStorage.getItem("teachers"));
if (!teachers.includes(teacher)) {
return false;
}
Cookies.set("type", "teacher");
Cookies.set("teacher", document.getElementById("teacher").value);
Cookies.set("teacher", teacher);
}
function select_class() {