planetwars.dev/web/pw-server/src/routes/register.svelte

46 lines
1.1 KiB
Svelte
Raw Normal View History

2021-12-30 15:34:50 +00:00
<script lang="ts">
2021-12-31 10:38:06 +00:00
let username: string | undefined;
let password: string | undefined;
2021-12-30 15:34:50 +00:00
2021-12-31 10:38:06 +00:00
const onSubmit = () => {
if (username === undefined || username.trim() === "") {
return;
}
2021-12-30 15:34:50 +00:00
2021-12-31 10:38:06 +00:00
if (password === undefined || password.trim() === "") {
2021-12-30 15:34:50 +00:00
return;
}
2021-12-31 10:38:06 +00:00
fetch("/api/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username,
password,
}),
})
.then((resp) => resp.json())
.then((data) => {
console.log(data);
});
};
2021-12-30 15:34:50 +00:00
</script>
2022-03-18 18:43:41 +00:00
<div class="page-card">
<div class="page-card-content">
<h1 class="page-card-header">Create account</h1>
2022-03-19 20:33:52 +00:00
<form class="account-form" on:submit|preventDefault={onSubmit}>
2022-03-18 18:43:41 +00:00
<label for="username">Username</label>
<input name="username" bind:value={username} />
<label for="password">Password</label>
<input type="password" name="password" bind:value={password} />
2022-03-19 20:33:52 +00:00
<button type="submit">Submit</button>
2022-03-18 18:43:41 +00:00
</form>
</div>
</div>
<style lang="scss">
2022-03-19 20:33:52 +00:00
@import "src/styles/account_forms.scss";
2022-03-18 18:43:41 +00:00
</style>