2022-05-21 02:23:55 -05:00
|
|
|
<script lang="ts">
|
2024-02-13 17:07:37 -05:00
|
|
|
import { serverInfo } from '$lib/stores/server-info.store';
|
|
|
|
|
import { convertToBytes } from '$lib/utils/byte-converter';
|
|
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
|
import { createUser } from '@immich/sdk';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
2024-02-24 21:28:56 +01:00
|
|
|
import PasswordField from '../shared-components/password-field.svelte';
|
2024-03-04 00:40:03 -05:00
|
|
|
import Slider from '../elements/slider.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
let error: string;
|
|
|
|
|
let success: string;
|
|
|
|
|
|
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 = '';
|
2024-03-04 00:40:03 -05:00
|
|
|
let shouldChangePassword = true;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
let canCreateUser = false;
|
2024-02-02 04:18:00 +01:00
|
|
|
let quotaSize: number | undefined;
|
2023-07-01 00:50:47 -04:00
|
|
|
let isCreatingUser = false;
|
|
|
|
|
|
2024-03-08 14:45:41 +01:00
|
|
|
$: quotaSizeInBytes = quotaSize ? convertToBytes(quotaSize, 'GiB') : null;
|
|
|
|
|
$: quotaSizeWarning = quotaSizeInBytes && quotaSizeInBytes > $serverInfo.diskSizeRaw;
|
2024-01-30 18:21:45 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
$: {
|
2024-02-24 21:28:56 +01:00
|
|
|
if (password !== confirmPassword && confirmPassword.length > 0) {
|
2023-07-01 00:50:47 -04:00
|
|
|
error = 'Password does not match';
|
|
|
|
|
canCreateUser = false;
|
|
|
|
|
} else {
|
|
|
|
|
error = '';
|
|
|
|
|
canCreateUser = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-15 03:54:21 +01:00
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
submit: void;
|
|
|
|
|
cancel: void;
|
|
|
|
|
}>();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-03-08 14:45:41 +01:00
|
|
|
async function registerUser() {
|
2023-07-01 00:50:47 -04:00
|
|
|
if (canCreateUser && !isCreatingUser) {
|
|
|
|
|
isCreatingUser = true;
|
|
|
|
|
error = '';
|
|
|
|
|
|
|
|
|
|
try {
|
2024-02-13 17:07:37 -05:00
|
|
|
await createUser({
|
2023-07-01 00:50:47 -04:00
|
|
|
createUserDto: {
|
2024-03-08 14:45:41 +01:00
|
|
|
email,
|
|
|
|
|
password,
|
|
|
|
|
shouldChangePassword,
|
|
|
|
|
name,
|
|
|
|
|
quotaSizeInBytes,
|
2023-07-01 00:50:47 -04:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
success = 'New user created';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
dispatch('submit');
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
return;
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-02-13 17:07:37 -05:00
|
|
|
handleError(error, 'Unable to create user');
|
|
|
|
|
} finally {
|
2023-07-01 00:50:47 -04:00
|
|
|
isCreatingUser = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-21 02:23:55 -05:00
|
|
|
</script>
|
|
|
|
|
|
2024-04-08 21:02:09 +00:00
|
|
|
<form on:submit|preventDefault={registerUser} autocomplete="off">
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="email">Email</label>
|
|
|
|
|
<input class="immich-form-input" id="email" bind:value={email} type="email" required />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
2024-04-08 21:02:09 +00:00
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="password">Password</label>
|
|
|
|
|
<PasswordField id="password" bind:password autocomplete="new-password" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="confirmPassword">Confirm Password</label>
|
|
|
|
|
<PasswordField id="confirmPassword" bind:password={confirmPassword} autocomplete="new-password" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex place-items-center justify-between gap-2">
|
|
|
|
|
<label class="text-sm dark:text-immich-dark-fg" for="require-password-change">
|
|
|
|
|
Require user to change password on first login
|
|
|
|
|
</label>
|
|
|
|
|
<Slider id="require-password-change" bind:checked={shouldChangePassword} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="name">Name</label>
|
|
|
|
|
<input class="immich-form-input" id="name" bind:value={name} type="text" required />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="flex items-center gap-2 immich-form-label" for="quotaSize">
|
|
|
|
|
Quota Size (GiB)
|
|
|
|
|
{#if quotaSizeWarning}
|
|
|
|
|
<p class="text-red-400 text-sm">You set a quota higher than the disk size</p>
|
|
|
|
|
{/if}
|
|
|
|
|
</label>
|
|
|
|
|
<input class="immich-form-input" id="quotaSize" type="number" min="0" bind:value={quotaSize} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if error}
|
|
|
|
|
<p class="text-sm text-red-400">{error}</p>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if success}
|
|
|
|
|
<p class="text-sm text-immich-primary">{success}</p>
|
|
|
|
|
{/if}
|
|
|
|
|
<div class="flex w-full gap-4 pt-4">
|
|
|
|
|
<Button color="gray" fullwidth on:click={() => dispatch('cancel')}>Cancel</Button>
|
|
|
|
|
<Button type="submit" disabled={isCreatingUser} fullwidth>Create</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|