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-13 17:07:37 -05:00
|
|
|
import ImmichLogo from '../shared-components/immich-logo.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>
|
|
|
|
|
|
2022-10-26 11:10:48 -05:00
|
|
|
<div
|
2024-02-19 02:57:56 +00:00
|
|
|
class="max-h-screen w-[500px] max-w-[95vw] overflow-y-auto immich-scrollbar rounded-3xl border bg-immich-bg p-4 py-8 shadow-sm dark:border-immich-dark-gray dark:bg-immich-dark-gray dark:text-immich-dark-fg"
|
2022-10-26 11:10:48 -05:00
|
|
|
>
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="flex flex-col place-content-center place-items-center gap-4 px-4">
|
2024-03-13 12:14:45 -05:00
|
|
|
<ImmichLogo noText class="text-center" height="75" width="75" />
|
2023-07-18 13:19:39 -05:00
|
|
|
<h1 class="text-2xl font-medium text-immich-primary dark:text-immich-dark-primary">Create new user</h1>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<form on:submit|preventDefault={registerUser} autocomplete="off">
|
|
|
|
|
<div class="m-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="email">Email</label>
|
2024-03-08 14:45:41 +01:00
|
|
|
<input class="immich-form-input" id="email" bind:value={email} type="email" required />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="m-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="password">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>
|
|
|
|
|
|
|
|
|
|
<div class="m-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="confirmPassword">Confirm 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>
|
|
|
|
|
|
2024-03-04 00:40:03 -05:00
|
|
|
<div class="m-4 flex place-items-center justify-between gap-2">
|
|
|
|
|
<label class="text-sm dark:text-immich-dark-fg" for="Require user to change password on first login">
|
|
|
|
|
Require user to change password on first login
|
|
|
|
|
</label>
|
|
|
|
|
<Slider bind:checked={shouldChangePassword} />
|
|
|
|
|
</div>
|
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="m-4 flex flex-col gap-2">
|
2023-11-11 20:03:32 -05:00
|
|
|
<label class="immich-form-label" for="name">Name</label>
|
2024-03-08 14:45:41 +01:00
|
|
|
<input class="immich-form-input" id="name" bind:value={name} type="text" required />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
2024-01-12 18:43:36 -06:00
|
|
|
<div class="m-4 flex flex-col gap-2">
|
2024-03-08 14:45:41 +01:00
|
|
|
<label class="flex items-center gap-2 immich-form-label" for="quotaSize">
|
|
|
|
|
Quota Size (GiB)
|
|
|
|
|
{#if quotaSizeWarning}
|
2024-01-30 18:21:45 +01:00
|
|
|
<p class="text-red-400 text-sm">You set a quota higher than the disk size</p>
|
2024-03-08 14:45:41 +01:00
|
|
|
{/if}
|
|
|
|
|
</label>
|
|
|
|
|
<input class="immich-form-input" id="quotaSize" type="number" min="0" bind:value={quotaSize} />
|
2024-01-12 18:43:36 -06:00
|
|
|
</div>
|
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if error}
|
2023-07-18 13:19:39 -05:00
|
|
|
<p class="ml-4 text-sm text-red-400">{error}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if success}
|
2023-07-18 13:19:39 -05:00
|
|
|
<p class="ml-4 text-sm text-immich-primary">{success}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
2023-07-25 16:29:40 +02:00
|
|
|
<div class="flex w-full gap-4 p-4">
|
|
|
|
|
<Button color="gray" fullwidth on:click={() => dispatch('cancel')}>Cancel</Button>
|
2023-07-01 00:50:47 -04:00
|
|
|
<Button type="submit" disabled={isCreatingUser} fullwidth>Create</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
2022-05-21 02:23:55 -05:00
|
|
|
</div>
|