From df0b9ffbe7d69025d8326bcea765cdfc4860a77a Mon Sep 17 00:00:00 2001 From: survellow <59056368+survellow@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:43:39 +0100 Subject: [PATCH 1/3] 36 add token regex --- frontend/src/view/editCalendarView.vue | 32 +++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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); From 9ff4cd3af7f2c90e02994d463dd6f7107fc571d6 Mon Sep 17 00:00:00 2001 From: Christoph Walther <59056368+survellow@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:21:48 +0100 Subject: [PATCH 2/3] 36 regex recognize token if not first URI parameter --- frontend/src/view/editCalendarView.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/view/editCalendarView.vue b/frontend/src/view/editCalendarView.vue index fa2bfad..838fe93 100644 --- a/frontend/src/view/editCalendarView.vue +++ b/frontend/src/view/editCalendarView.vue @@ -13,7 +13,7 @@ const modules: Ref = ref(moduleStore().modules); function extractToken(token: string): string { const tokenRegex = /^[a-z0-9]{15}$/; - const tokenUriRegex = /\?token=([a-z0-9]{15})(?:&|$)/; + const tokenUriRegex = /(?:\?|&)token=([a-z0-9]{15})(?:&|$)/; if (tokenRegex.test(token)) { return token; From 0aeddf76bd06d4eb238aef54b271ed306a312d13 Mon Sep 17 00:00:00 2001 From: survellow <59056368+survellow@users.noreply.github.com> Date: Sat, 4 Nov 2023 17:18:56 +0100 Subject: [PATCH 3/3] 36 add toast comp. for invalid token notification --- frontend/src/view/editCalendarView.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/view/editCalendarView.vue b/frontend/src/view/editCalendarView.vue index 838fe93..cd848d8 100644 --- a/frontend/src/view/editCalendarView.vue +++ b/frontend/src/view/editCalendarView.vue @@ -55,6 +55,7 @@ function loadCalendar(): void {