mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-04 02:39:14 +02:00
36 add token regex
This commit is contained in:
@@ -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<string> = ref("");
|
||||
const modules: Ref<Module[]> = 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);
|
||||
|
||||
|
Reference in New Issue
Block a user