Added login
This commit is contained in:
parent
7833f5326e
commit
13ca1d1432
14
src/app.html
14
src/app.html
@ -1,12 +1,12 @@
|
|||||||
<!DOCTYPE html >
|
<!DOCTYPE html>
|
||||||
<html lang="en" class="dark">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body data-theme="skeleton">
|
<body data-sveltekit-preload-data="hover" data-theme="skeleton">
|
||||||
<div style="display: contents" class="h-full overflow-hidden">%sveltekit.body%</div>
|
<div style="display: contents">%sveltekit.body%</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,11 +1,44 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '../app.pcss';
|
|
||||||
// The ordering of these imports is critical to your app working properly
|
// The ordering of these imports is critical to your app working properly
|
||||||
import '@skeletonlabs/skeleton/themes/theme-skeleton.css';
|
import '@skeletonlabs/skeleton/themes/theme-skeleton.css';
|
||||||
// If you have source.organizeImports set to true in VSCode, then it will auto change this ordering
|
// If you have source.organizeImports set to true in VSCode, then it will auto change this ordering
|
||||||
import '@skeletonlabs/skeleton/styles/all.css';
|
import '@skeletonlabs/skeleton/styles/all.css';
|
||||||
// Most of your app wide CSS should be put in this file
|
// Most of your app wide CSS should be put in this file
|
||||||
import '../app.pcss';
|
import '../app.postcss';
|
||||||
|
|
||||||
|
import {alerts, globals} from "$lib/stores.js";
|
||||||
|
|
||||||
|
let alertsvar;
|
||||||
|
let globalvars;
|
||||||
|
|
||||||
|
function closeWarning(e) {
|
||||||
|
let index = e.target.dataset.index;
|
||||||
|
alerts.update(function (data) {
|
||||||
|
data.splice(index, 1)
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
alerts.subscribe((value) => {
|
||||||
|
alertsvar = value;
|
||||||
|
});
|
||||||
|
globals.subscribe(value => {
|
||||||
|
globalvars = value;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if typeof globalvars.user !== 'undefined' }
|
||||||
|
{#each alertsvar as alert, i}
|
||||||
|
<aside class="alert variant-filled-{alert.class}">
|
||||||
|
<!-- Icon -->
|
||||||
|
<div><i class="text-2xl icon icon-exclamation-triangle"></i></div>
|
||||||
|
<!-- Message -->
|
||||||
|
<p class="alert-message">{alert.text}</p>
|
||||||
|
<!-- Actions -->
|
||||||
|
<div class="alert-actions">
|
||||||
|
<i on:click={closeWarning} data-index={i} class="icon icon-close"></i>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
|
||||||
<slot />
|
<slot />
|
||||||
|
@ -1,9 +1,22 @@
|
|||||||
<script>
|
<script>
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import {globals} from "$lib/stores.js";
|
||||||
|
|
||||||
|
let globalvars;
|
||||||
|
|
||||||
|
globals.subscribe(value => {
|
||||||
|
globalvars = value;
|
||||||
|
});
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
if(typeof globalvars.user === 'undefined') {
|
||||||
goto("/account/login");
|
goto("/account/login");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if typeof globalvars.user !== 'undefined'}
|
||||||
|
<h1>Welcome {globalvars.user.name}</h1>
|
||||||
|
{/if}
|
@ -1,8 +1,9 @@
|
|||||||
<div class="container h-full mx-auto flex justify-center items-center flex-col">
|
<div class="container h-full mx-auto flex justify-center items-center flex-col">
|
||||||
<h1 class="my-3">Blackbird Chess</h1>
|
<h1 class="my-3">Blackbird Chess</h1>
|
||||||
|
|
||||||
|
{#if typeof globalvars.user == 'undefined' }
|
||||||
{#each alertsvar as alert, i}
|
{#each alertsvar as alert, i}
|
||||||
<aside class="alert variant-filled-{alert.class}">
|
<aside class="alert variant-filled-{alert.class} mb-3">
|
||||||
<!-- Icon -->
|
<!-- Icon -->
|
||||||
<div><i class="text-2xl icon icon-exclamation-triangle"></i></div>
|
<div><i class="text-2xl icon icon-exclamation-triangle"></i></div>
|
||||||
<!-- Message -->
|
<!-- Message -->
|
||||||
@ -13,8 +14,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
{/each}
|
{/each}
|
||||||
|
{/if}
|
||||||
|
<div class="card p-4 w-50 text-token space-y-4">
|
||||||
<slot />
|
<slot />
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -23,9 +26,11 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script lang="js">
|
<script lang="js">
|
||||||
import {alerts} from "$lib/stores.js";
|
import {alerts, globals} from "$lib/stores.js";
|
||||||
|
|
||||||
let alertsvar;
|
let alertsvar;
|
||||||
|
let globalvars;
|
||||||
|
|
||||||
function closeWarning(e) {
|
function closeWarning(e) {
|
||||||
let index = e.target.dataset.index;
|
let index = e.target.dataset.index;
|
||||||
alerts.update(function (data) {
|
alerts.update(function (data) {
|
||||||
@ -36,4 +41,8 @@
|
|||||||
alerts.subscribe((value) => {
|
alerts.subscribe((value) => {
|
||||||
alertsvar = value;
|
alertsvar = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
globals.subscribe(value => {
|
||||||
|
globalvars = value;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
@ -3,7 +3,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<form name="login-server" class="flex flex-col">
|
<form name="login-server" class="flex flex-col">
|
||||||
<label class="label my-3">
|
<label class="label my-3">
|
||||||
<span>Username:</span>
|
<span>E-Mail:</span>
|
||||||
<input type="email" name="email" id="login-email" class="input" bind:value={email}>
|
<input type="email" name="email" id="login-email" class="input" bind:value={email}>
|
||||||
</label>
|
</label>
|
||||||
<label class="label my-3">
|
<label class="label my-3">
|
||||||
@ -31,6 +31,9 @@
|
|||||||
import { urls, alerts, globals } from "$lib/stores.js";
|
import { urls, alerts, globals } from "$lib/stores.js";
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import {browser} from "$app/environment";
|
import {browser} from "$app/environment";
|
||||||
|
import {requestor} from "../../../serverrequest.js";
|
||||||
|
import {throwError} from "svelte-preprocess/dist/modules/errors.js";
|
||||||
|
import {goto} from "$app/navigation";
|
||||||
|
|
||||||
var email = '';
|
var email = '';
|
||||||
var password = '';
|
var password = '';
|
||||||
@ -41,10 +44,23 @@
|
|||||||
globalvars = value;
|
globalvars = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
function handleLogin() {
|
async function handleLogin() {
|
||||||
alerts.update(data => [...data, {text: 'Not yet implemented', type: 'notimplemented', class: 'warning'}]);
|
try {
|
||||||
|
let postdata = {email: email, password: password}
|
||||||
|
let response = await requestor.post(urls.login, JSON.stringify(postdata));
|
||||||
|
let responsedata = JSON.parse(response.data);
|
||||||
|
if(response.status != 200) {
|
||||||
|
let message = 'Something went wrong during login'
|
||||||
|
if(typeof responsedata.message !== 'undefined') message = responsedata.message
|
||||||
|
throwError(message)
|
||||||
|
}
|
||||||
|
if(!responsedata.success) return alerts.update(data => [...data, {text: 'Login failed: ' + responsedata.message , class: 'error'}]);
|
||||||
|
globals.update((globalobj) => ({ ...globalobj, ...{user: responsedata.user }}));
|
||||||
|
goto('/')
|
||||||
|
} catch (error) {
|
||||||
|
return alerts.update(data => [...data, {text: error, class: 'error'}]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGoToServerSelect() {
|
function handleGoToServerSelect() {
|
||||||
|
@ -166,11 +166,11 @@
|
|||||||
let responsejson = JSON.parse(response.data);
|
let responsejson = JSON.parse(response.data);
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
alerts.update(data => data.filter(alert => alert.type !== 'register-errors'));
|
alerts.update(data => data.filter(alert => alert.type !== 'register-errors'));
|
||||||
alerts.update(data => [...data, {text: responsejson.message, type: 'register-errors', class: 'error'}]);
|
alerts.update(data => [...data, {text: responsejson.Message, type: 'register-errors', class: 'error'}]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
alerts.update(data => []);
|
alerts.update(data => []);
|
||||||
alerts.update(data => [...data, {text: responsejson.message, type: 'register-success', class: 'success'}]);
|
alerts.update(data => [...data, {text: responsejson.Message, type: 'register-success', class: 'success'}]);
|
||||||
return false;
|
return false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alerts.update(data => [...data, {text: 'Server unavailable', type: 'noserveravailable', class: 'error'}]);
|
alerts.update(data => [...data, {text: 'Server unavailable', type: 'noserveravailable', class: 'error'}]);
|
||||||
|
@ -3,7 +3,8 @@ import {Axios} from "axios";
|
|||||||
var options = {
|
var options = {
|
||||||
headers: {
|
headers: {
|
||||||
'X-BlackbirdChessClient': 'webclient',
|
'X-BlackbirdChessClient': 'webclient',
|
||||||
"Content-Type": "application/json",
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user