2022-05-21 02:23:55 -05:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { AppRoute } from '$lib/constants';
|
|
|
|
|
import { api } from '@api';
|
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
2023-02-10 23:01:35 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let error: string;
|
|
|
|
|
let password = '';
|
|
|
|
|
let confirmPassowrd = '';
|
|
|
|
|
let canRegister = false;
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
$: {
|
|
|
|
|
if (password !== confirmPassowrd && confirmPassowrd.length > 0) {
|
|
|
|
|
error = 'Password does not match';
|
|
|
|
|
canRegister = false;
|
|
|
|
|
} else {
|
|
|
|
|
error = '';
|
|
|
|
|
canRegister = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 12:28:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
async function registerAdmin(event: SubmitEvent & { currentTarget: HTMLFormElement }) {
|
|
|
|
|
if (canRegister) {
|
|
|
|
|
error = '';
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const form = new FormData(event.currentTarget);
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const email = form.get('email');
|
|
|
|
|
const password = form.get('password');
|
|
|
|
|
const firstName = form.get('firstName');
|
|
|
|
|
const lastName = form.get('lastName');
|
2022-07-26 12:28:07 -05:00
|
|
|
|
2023-11-03 21:33:15 -04:00
|
|
|
const { status } = await api.authenticationApi.signUpAdmin({
|
2023-07-01 00:50:47 -04:00
|
|
|
signUpDto: {
|
|
|
|
|
email: String(email),
|
|
|
|
|
password: String(password),
|
|
|
|
|
firstName: String(firstName),
|
|
|
|
|
lastName: String(lastName),
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
if (status === 201) {
|
2023-08-27 07:31:52 +03:00
|
|
|
await goto(AppRoute.AUTH_LOGIN);
|
2023-07-01 00:50:47 -04:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
error = 'Error create admin account';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-21 02:23:55 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-07-18 13:19:39 -05:00
|
|
|
<form on:submit|preventDefault={registerAdmin} method="post" class="mt-5 flex flex-col gap-5">
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="email">Admin Email</label>
|
|
|
|
|
<input class="immich-form-input" id="email" name="email" type="email" autocomplete="email" required />
|
|
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="password">Admin Password</label>
|
|
|
|
|
<input
|
|
|
|
|
class="immich-form-input"
|
|
|
|
|
id="password"
|
|
|
|
|
name="password"
|
|
|
|
|
type="password"
|
|
|
|
|
autocomplete="new-password"
|
|
|
|
|
required
|
|
|
|
|
bind:value={password}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="confirmPassword">Confirm Admin Password</label>
|
|
|
|
|
<input
|
|
|
|
|
class="immich-form-input"
|
|
|
|
|
id="confirmPassword"
|
|
|
|
|
name="password"
|
|
|
|
|
type="password"
|
|
|
|
|
autocomplete="new-password"
|
|
|
|
|
required
|
|
|
|
|
bind:value={confirmPassowrd}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="firstName">First Name</label>
|
|
|
|
|
<input class="immich-form-input" id="firstName" name="firstName" type="text" autocomplete="given-name" required />
|
|
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="lastName">Last Name</label>
|
|
|
|
|
<input class="immich-form-input" id="lastName" name="lastName" type="text" autocomplete="family-name" required />
|
|
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if error}
|
|
|
|
|
<p class="text-red-400">{error}</p>
|
|
|
|
|
{/if}
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="my-5 flex w-full">
|
|
|
|
|
<Button type="submit" size="lg" fullwidth>Sign up</Button>
|
|
|
|
|
</div>
|
2023-03-15 22:38:29 +01:00
|
|
|
</form>
|