-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
817c0c7
commit 7466ecd
Showing
3 changed files
with
102 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,41 @@ | ||
import { ref } from 'vue'; | ||
import { ref } from "vue"; | ||
|
||
const baseCampusURL = "https://selfservice.campus-dual.de" | ||
const baseCorsUrl = "https://corsproxy.io/?" | ||
const baseCampusURL = "https://selfservice.campus-dual.de"; | ||
const baseCorsUrl = "https://corsproxy.io/?"; | ||
|
||
export function useCampus() { | ||
const username = useCookie("username"); | ||
const password = useCookie("password"); | ||
|
||
async function getCampusData(type: 'room' | 'timeline' | 'credits' | 'semester') { | ||
|
||
const UrlParams = `?userid=${username.value}&hash=${password.value}&t=${Math.floor(Date.now() / 1000)}&_=${Date.now()}` | ||
|
||
switch (type) { | ||
|
||
case 'room': | ||
var urlPath = "/room/json" | ||
break; | ||
case 'timeline': | ||
var urlPath = "/dash/gettimeline" | ||
break; | ||
case 'credits': | ||
var urlPath = "/dash/getcp" | ||
break; | ||
case 'semester': | ||
var urlPath = "/dash/getfs" | ||
break; | ||
|
||
default: | ||
throw new Error('Invalid type'); | ||
} | ||
|
||
const url = baseCorsUrl + encodeURIComponent(baseCampusURL + urlPath + UrlParams) | ||
|
||
return await $fetch(url); | ||
} | ||
|
||
return { | ||
username, | ||
password, | ||
getCampusData | ||
}; | ||
} | ||
const username = useCookie("username"); | ||
const password = useCookie("password"); | ||
|
||
async function getCampusData(type: "room" | "timeline" | "credits" | "semester") { | ||
const UrlParams = `?userid=${username.value}&hash=${password.value}&t=${Math.floor(Date.now() / 1000)}&_=${Date.now()}`; | ||
|
||
switch (type) { | ||
case "room": | ||
var urlPath = "/room/json"; | ||
break; | ||
case "timeline": | ||
var urlPath = "/dash/gettimeline"; | ||
break; | ||
case "credits": | ||
var urlPath = "/dash/getcp"; | ||
break; | ||
case "semester": | ||
var urlPath = "/dash/getfs"; | ||
break; | ||
|
||
default: | ||
throw new Error("Invalid type"); | ||
} | ||
|
||
const url = baseCorsUrl + encodeURIComponent(baseCampusURL + urlPath + UrlParams); | ||
|
||
return await $fetch(url); | ||
} | ||
|
||
return { | ||
username, | ||
password, | ||
getCampusData, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
export default defineNuxtRouteMiddleware(async (to, from) => { | ||
if (to.fullPath == "/stundenplan") { | ||
return navigateTo("/dash/stundenplan") | ||
return navigateTo("/dash/stundenplan"); | ||
} | ||
if (import.meta.server) return true | ||
if (import.meta.server) return true; | ||
|
||
|
||
const isLoggedIn = useState("isLoggedIn", (() => false) as () => boolean) | ||
const { getCampusData } = useCampus(); | ||
const isLoggedIn = useState("isLoggedIn", (() => false) as () => boolean); | ||
|
||
if (!to.fullPath.includes("dash")) { | ||
return true | ||
return true; | ||
} | ||
const username = useCookie("username") | ||
const password = useCookie("password") | ||
|
||
if (!isLoggedIn.value) { | ||
try { | ||
const test_url = `https://corsproxy.io/?https%3A%2F%2Fselfservice.campus-dual.de%2Fdash%2Fgetcp%3Fuser%3D${username.value}%26hash%3D${password.value}` | ||
const response = await $fetch(test_url) | ||
isLoggedIn.value = !!(typeof response === 'number') | ||
const response = await getCampusData("timeline"); | ||
isLoggedIn.value = !!(typeof response != "string"); | ||
} catch (error) { | ||
isLoggedIn.value = false | ||
isLoggedIn.value = false; | ||
} | ||
} | ||
|
||
|
||
if (isLoggedIn.value) return true | ||
return navigateTo("/login") | ||
}) | ||
if (isLoggedIn.value) return true; | ||
return navigateTo("/login"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters