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';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { signUpAdmin } from '@immich/sdk';
|
|
|
|
|
import { handleError } from '../../utils/handle-error';
|
2023-07-01 00:50:47 -04:00
|
|
|
import Button from '../elements/buttons/button.svelte';
|
2024-02-24 21:28:56 +01:00
|
|
|
import PasswordField from '../shared-components/password-field.svelte';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-02-10 23:01:35 +01:00
|
|
|
|
2024-03-08 14:45:41 +01:00
|
|
|
let email = '';
|
2023-07-01 00:50:47 -04:00
|
|
|
let password = '';
|
2024-02-24 21:28:56 +01:00
|
|
|
let confirmPassword = '';
|
2024-03-08 14:45:41 +01:00
|
|
|
let name = '';
|
|
|
|
|
|
|
|
|
|
let errorMessage: string;
|
2023-07-01 00:50:47 -04:00
|
|
|
let canRegister = false;
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
$: {
|
2024-02-24 21:28:56 +01:00
|
|
|
if (password !== confirmPassword && confirmPassword.length > 0) {
|
2024-06-04 21:53:00 +02:00
|
|
|
errorMessage = $t('password_does_not_match');
|
2023-07-01 00:50:47 -04:00
|
|
|
canRegister = false;
|
|
|
|
|
} else {
|
2024-02-13 17:07:37 -05:00
|
|
|
errorMessage = '';
|
2023-07-01 00:50:47 -04:00
|
|
|
canRegister = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 12:28:07 -05:00
|
|
|
|
2024-03-08 14:45:41 +01:00
|
|
|
async function registerAdmin() {
|
2023-07-01 00:50:47 -04:00
|
|
|
if (canRegister) {
|
2024-02-13 17:07:37 -05:00
|
|
|
errorMessage = '';
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
try {
|
2024-03-08 14:45:41 +01:00
|
|
|
await signUpAdmin({ signUpDto: { email, password, name } });
|
2023-08-27 07:31:52 +03:00
|
|
|
await goto(AppRoute.AUTH_LOGIN);
|
2024-02-13 17:07:37 -05:00
|
|
|
} catch (error) {
|
2024-06-12 13:13:10 +02:00
|
|
|
handleError(error, 'errors.unable_to_create_admin_account');
|
|
|
|
|
errorMessage = $t('errors.unable_to_create_admin_account');
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="email">{$t('admin_email')}</label>
|
2024-03-08 14:45:41 +01:00
|
|
|
<input class="immich-form-input" id="email" bind:value={email} type="email" autocomplete="email" required />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="password">{$t('admin_password')}</label>
|
2024-03-08 14:45:41 +01:00
|
|
|
<PasswordField id="password" bind:password autocomplete="new-password" />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="confirmPassword">{$t('confirm_admin_password')}</label>
|
2024-02-24 21:28:56 +01:00
|
|
|
<PasswordField id="confirmPassword" bind:password={confirmPassword} autocomplete="new-password" />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="name">{$t('name')}</label>
|
2024-03-08 14:45:41 +01:00
|
|
|
<input class="immich-form-input" id="name" bind:value={name} type="text" autocomplete="name" required />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
{#if errorMessage}
|
|
|
|
|
<p class="text-red-400">{errorMessage}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="my-5 flex w-full">
|
2024-06-04 21:53:00 +02:00
|
|
|
<Button type="submit" size="lg" fullwidth>{$t('sign_up')}</Button>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2023-03-15 22:38:29 +01:00
|
|
|
</form>
|