Skip to content

Commit

Permalink
Merge pull request #67 from greybaron/fix/small-login-and-dash-improv…
Browse files Browse the repository at this point in the history
…ements

Fix login page, fix reminders not getting updated; other small improvements
  • Loading branch information
fnschmidt authored Aug 12, 2024
2 parents f35feb0 + 009df62 commit b8adde9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
22 changes: 18 additions & 4 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
// Defines which side of your trigger the popup will appear
placement: 'bottom'
};
function doesHttpOnlyCookieExist(name: string) {
var d = new Date();
d.setTime(d.getTime() + 1000);
var expires = 'expires=' + d.toUTCString();
document.cookie = name + '=new_value;path=/;' + expires;
const exists = document.cookie.indexOf(name + '=') == -1;
console.log('cookie exists:', exists);
return exists;
}
</script>

<div
Expand Down Expand Up @@ -146,10 +158,12 @@
{#if $page.url.pathname == '/impressum' || $page.url.pathname == '/datenschutz'}
<button
on:click={async () => {
const response = await fetch('/');

if (response.redirected) {
window.location.href = response.url;
if (process.env.NODE_ENV === 'production') {
if (doesHttpOnlyCookieExist('jwt')) {
goto('/dashboard');
} else {
goto('/');
}
} else {
goto('/');
}
Expand Down
5 changes: 2 additions & 3 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { env } from '$env/dynamic/private';

export const actions: Actions = {
login: async ({ cookies, request }) => {
console.log(`fetch ${env.CD_API_URL}/signin`);
const form = await request.formData();
const username = form.get('username');
const password = form.get('password');
Expand All @@ -23,8 +22,8 @@ export const actions: Actions = {

if (!response.ok) {
let message;
if (response.status === 418) {
message = 'CD-API: SSL-Fehler (Wahrscheinlich fehlt GEANT CA)';
if (response.status === 429) {
message = 'Zu viele Anfragen';
} else {
message = 'Nutzer/Passwort ungültig';
}
Expand Down
14 changes: 7 additions & 7 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
}}
action="?/login"
method="POST"
class="bg-surface-100-800-token dark:bg-gray-800 shadow-md rounded-token p-6 pb-4"
class="bg-surface-100-800-token dark:bg-gray-800 shadow-md rounded-token p-6 pb-4 space-y-4"
>
<div class="mb-4">
<div>
<label class="block text-token text-sm font-bold mb-2" for="username">
CampusDual-Benutzername
</label>
Expand All @@ -47,15 +47,15 @@
required
placeholder="das normale, nicht den Hash"
/>
<div class="h-4">
<div class="h-6 -mb-3">
{#if form?.message}
<small class="text-red-500">{form.message}</small>
{/if}
</div>
</div>

<div class="bg-surface-200-700-token p-2 rounded-md space-y-2 outline-dashed outline-1">
<div class="flex items-center space-x-2">
<label class="flex items-center space-x-2">
<input
type="checkbox"
class="checkbox outline variant-outline-surface outline-2"
Expand All @@ -72,22 +72,22 @@
<br />
Daten werden nur lokal gespeichert.
</p>
</div>
</label>

<div class="flex justify-center space-x-2">
<button
on:click={() => {
goto('/impressum');
}}
type="button"
class="transition-none variant-filled btn text-sm h-7">Impressum</button
class="variant-filled btn text-sm h-7 transition-transform">Impressum</button
>
<button
on:click={() => {
goto('/datenschutz');
}}
type="button"
class="transition-none variant-filled btn text-sm h-7">Datenschutzerklärung</button
class="variant-filled btn text-sm h-7 transition-transform">Datenschutzerklärung</button
>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/routes/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@
component: modalComponent
};
remindersSignalStore = persistentStore('updateRemindersSignal', false);
componentProps = {
BasicInfoTile: { basicUserData },
ExamSignupTile: { remindersSignalStore }
};
remindersSignalStore = persistentStore('updateRemindersSignal', false);
fetchReminders();
});
Expand Down Expand Up @@ -194,7 +195,7 @@
</div>
</div>
{/if}
{#if componentOrder}
{#if componentOrder && componentProps}
<div class="w-[98%] sm:w-auto grid grid-cols-1 lg:grid-cols-2 gap-4 mx-auto">
<!-- create portals -->
{#each components as _, idx}
Expand Down

0 comments on commit b8adde9

Please sign in to comment.