Compare commits

...

6 Commits

5 changed files with 87 additions and 8 deletions

View File

@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" />
%sveltekit.head% %sveltekit.head%
</head> </head>
<body data-sveltekit-preload-data="hover"> <body data-sveltekit-preload-data="hover">

72
src/lib/libauth.ts Normal file
View File

@ -0,0 +1,72 @@
import { uuid } from "./stores/uuid"
export interface libauthResponse {
uuidPresent?: boolean;
serverAuthCheck?: boolean;
uuidValue?: string;
serverAuthCheckResponseCode?: number;
}
interface uuidCheckRes {
uuidValue?: string;
uuidPresent?: boolean;
}
export async function checkAuth(): Promise<libauthResponse> {
let result: libauthResponse = {};
const uuidCheck = await checkUuid();
result.uuidPresent = uuidCheck?.uuidPresent;
result.uuidValue = uuidCheck?.uuidValue;
const serverCheck = await checkServerAuth();
result.serverAuthCheck = serverCheck.authOk;
result.serverAuthCheckResponseCode = serverCheck.status;
return result
}
export async function checkUuid(): Promise<uuidCheckRes> {
let uuid_value: string = '';
const unsubscribe = uuid.subscribe(value => {
uuid_value = value;
});
let res: uuidCheckRes = {
uuidValue: uuid_value
}
console.log("uuid-value is: ", uuid_value)
if (uuid_value && uuid_value != 'null') {
res = {
uuidPresent: true,
uuidValue: uuid_value,
}
} else {
res = {
uuidPresent: false,
uuidValue: uuid_value,
}
}unsubscribe()
return res;}
export async function checkServerAuth() {
let uuid_value: string = '';
uuid.subscribe((value => uuid_value = value))
const url = "https://owlboard.info/api/v2/user/checkAuth"
const options = {
method: 'GET',
headers: {
uuid: uuid_value,
}
};
const res = await fetch(url, options)
let ok: boolean;
if (res.status !== 401) {
ok = true;
} else {
ok = false;
}
return {
authOk: ok,
status: res.status,
}
}

View File

@ -11,7 +11,7 @@
svgPath: '/images/navigation/info.svg' svgPath: '/images/navigation/info.svg'
}, },
{ {
title: 'More', title: 'Menu',
path: '/more', path: '/more',
svgPath: '/images/navigation/more.svg' svgPath: '/images/navigation/more.svg'
} }

View File

@ -5,10 +5,9 @@
</script> </script>
<svelte:head> <svelte:head>
<meta charset="utf-8" />
<meta name="application-name" content="OwlBoard" /> <meta name="application-name" content="OwlBoard" />
<meta name="author" content="Frederick Boniface" /> <meta name="author" content="Frederick Boniface" />
<meta name="description" content="Live train data, PIS Codes & reference data. Built by railway staff, for railway staff." /> <meta name="description" content="Get instant access to live train data, PIS codes, and location reference codes. Built by railway staff, for railway staff your fastest route to accurate information." />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<meta name="theme-color" content="#00b7b7" /> <meta name="theme-color" content="#00b7b7" />
<link rel="icon" href="/images/icon.svg" type="image/svg+xml" /> <link rel="icon" href="/images/icon.svg" type="image/svg+xml" />

View File

@ -4,11 +4,12 @@
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { uuid } from '$lib/stores/uuid.js'; import { uuid } from '$lib/stores/uuid.js';
import { checkAuth } from '$lib/libauth';
const title = 'Register'; const title = 'Register';
let state = 'unreg'; let state = 'unreg';
let isLoading = false; let isLoading = true;
let inputValue = ''; let inputValue = '';
function handleInput(event) { function handleInput(event) {
@ -39,17 +40,22 @@
} }
onMount(async () => { onMount(async () => {
if ($uuid != 'null') { const auth = await checkAuth();
if (auth.uuidPresent === false) {
state = 'unreg';
} else if (auth.uuidPresent === true) {
state = 'reg'; state = 'reg';
} }
isLoading = false;
}); });
</script> </script>
{#if isLoading}
<Loading />
{/if}
<Header {title} /> <Header {title} />
{#if isLoading}
<Loading />
{:else}
{#if state == 'unreg'} {#if state == 'unreg'}
<p>The staff version of OwlBoard offers several extra features:</p> <p>The staff version of OwlBoard offers several extra features:</p>
<ul> <ul>
@ -88,6 +94,7 @@
browser. browser.
</p> </p>
{/if} {/if}
{/if}
<Nav /> <Nav />
<style> <style>