diff --git a/frontend/src/view/editCalendarView.vue b/frontend/src/view/editCalendarView.vue index f68d879..fa2bfad 100644 --- a/frontend/src/view/editCalendarView.vue +++ b/frontend/src/view/editCalendarView.vue @@ -5,11 +5,41 @@ import moduleStore from "../store/moduleStore"; import { getCalender } from "../api/loadCalendar"; import router from "../router"; import tokenStore from "../store/tokenStore"; +import { useToast } from "primevue/usetoast"; +const toast = useToast(); const token: Ref = ref(""); const modules: Ref = ref(moduleStore().modules); -function loadCalendar() { +function extractToken(token: string): string { + const tokenRegex = /^[a-z0-9]{15}$/; + const tokenUriRegex = /\?token=([a-z0-9]{15})(?:&|$)/; + + if (tokenRegex.test(token)) { + return token; + } + + const match = tokenUriRegex.exec(token); + if (match) { + return match[1]; + } + + throw new Error("Invalid token"); +} + +function loadCalendar(): void { + try { + token.value = extractToken(token.value); + } catch (e) { + toast.add({ + severity: "error", + summary: "Error", + detail: "Invalid token", + life: 3000, + }); + return; + } + moduleStore().removeAllModules(); tokenStore().setToken(token.value);