Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
probablyjassin committed Nov 13, 2024
1 parent 0abf6b7 commit e0ac1b2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 66 deletions.
41 changes: 21 additions & 20 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@
</template>

<script setup>
useHead
({
title: 'Stundenplan',
meta: [{
name: 'description',
content: 'Einfache, mobile-first WebApp für den CampusDual-Stundenplan. Support für Firefox und Chromium.'
}],
})
useHead({
title: "Stundenplan",
meta: [
{
name: "description",
content: "Einfache, mobile-first WebApp für den CampusDual-Stundenplan. Support für Firefox und Chromium.",
},
],
});
const username = useCookie("username")
const password = useCookie("password")
const isLoggedIn = useState("isLoggedIn", (() => false))
const username = useCookie("username");
const password = useCookie("password");
const isLoggedIn = useState("isLoggedIn", () => false);
onMounted(async () => {
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 = !!(response == 0)
} catch (error) {
isLoggedIn.value = false
}
})
onMounted(async () => {
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 = !!(response == 0);
} catch (error) {
isLoggedIn.value = false;
}
});
</script>
102 changes: 56 additions & 46 deletions pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,74 +1,84 @@
<template>
<div class="container mx-auto p-4">
<div class="flex flex-col justify-center container p-4">
<p class="text-3xl">Login</p>
<p>
<span class="text-primary">Benutzername:</span> Matrikelnummer (500xxx)
</p>
<p><span class="text-primary">Benutzername:</span> Matrikelnummer (500xxx)</p>
<div>
<span>
<span class="text-primary">Passwort:</span> Hash von der Campus-Dual API
</span>
<span> <span class="text-primary">Passwort:</span> Hash von der Campus-Dual API </span>
<NuxtLink to="/hash" class="text-accent underline">(Wie bekomme ich den?)</NuxtLink>
</div>
</div>
<div class="flex flex-col space-y-5 max-w-md mx-auto">
<input type="text" name="username" id="username" placeholder="Username" v-model="username"
:class="{ 'border-red-500': !usernameValid }" class="p-2 border rounded" />
<div class="flex flex-col space-y-5 max-w-md p-4">
<input
type="text"
name="username"
id="username"
placeholder="Username"
v-model="username"
:class="{ 'border-red-500': !usernameValid }"
class="p-2 border rounded" />
<p v-if="!usernameValid" class="text-red-500 text-sm">Bitte geben Sie einen Benutzernamen ein.</p>

<input type="password" name="Hash" id="hash" placeholder="Passwort (Hash)" v-model="password"
:class="{ 'border-red-500': !passwordValid }" class="p-2 border rounded" />
<input
type="password"
name="Hash"
id="hash"
placeholder="Passwort (Hash)"
v-model="password"
:class="{ 'border-red-500': !passwordValid }"
class="p-2 border rounded" />
<p v-if="!passwordValid" class="text-red-500 text-sm">Bitte geben Sie ein Passwort ein.</p>

<UButton @click="login" :loading="isLoading && !error" class="p-3 bg-primary text-text rounded">Login</UButton>
<p v-if="error" class="text-red-500 text-sm">Der Login ist fehlgeschlagen. Überprüfe ob du tatsächlich deinen
aktuellen Hash von der CampusDual API hast.</p>
<UButton @click="login" :loading="isLoading && !error" class="p-3 bg-primary text-text rounded block">Login</UButton>

<p v-if="error" class="text-red-500 text-sm">
Der Login ist fehlgeschlagen. Überprüfe ob du tatsächlich deinen aktuellen Hash von der CampusDual API hast.
</p>
</div>
</template>

<script setup>
const router = useRouter();
const router = useRouter();
const username = ref("");
const password = ref("");
const usernameValid = ref(true);
const passwordValid = ref(true);
const username = ref("");
const password = ref("");
const usernameValid = ref(true);
const passwordValid = ref(true);
const isLoading = ref(false);
const error = ref(false);
const isLoading = ref(false);
const error = ref(false);
const usernameCookie = useCookie("username", { expires: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000) });
const passwordCookie = useCookie("password", { expires: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000) });
const usernameCookie = useCookie("username", { expires: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000) });
const passwordCookie = useCookie("password", { expires: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000) });
async function login() {
isLoading.value = true;
async function login() {
isLoading.value = true;
usernameValid.value = username.value !== "";
passwordValid.value = password.value !== "";
usernameValid.value = username.value !== "";
passwordValid.value = password.value !== "";
if (!usernameValid.value || !passwordValid.value) {
return;
}
if (!usernameValid.value || !passwordValid.value) {
return;
}
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);
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);
if (response == 0) {
usernameCookie.value = username.value;
passwordCookie.value = password.value;
return router.push("/dash/stundenplan");
if (response == 0) {
usernameCookie.value = username.value;
passwordCookie.value = password.value;
return router.push("/dash/stundenplan");
}
error.value = true;
isLoading.value = false;
}
error.value = true;
isLoading.value = false;
}
</script>

<style scoped>
.border-red-500 {
border-color: #f56565;
}
.border-red-500 {
border-color: #f56565;
}
.text-red-500 {
color: #f56565;
}
.text-red-500 {
color: #f56565;
}
</style>

0 comments on commit e0ac1b2

Please sign in to comment.