From b6ef022f151c0c76017aecda14c5871078293dcd Mon Sep 17 00:00:00 2001 From: Mariano Riefolo Date: Tue, 3 Sep 2024 16:42:59 +0200 Subject: [PATCH] feat(frontend): check that the teacher is valid before setting the cookie --- static/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/static/index.js b/static/index.js index 1bfd103..09acbcb 100644 --- a/static/index.js +++ b/static/index.js @@ -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() {