2022-05-21 02:23:55 -05:00
|
|
|
<script lang="ts">
|
2024-09-19 18:20:09 -04:00
|
|
|
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
|
|
|
|
|
import { featureFlags } from '$lib/stores/server-config.store';
|
2024-12-16 15:45:01 +01:00
|
|
|
import { userInteraction } from '$lib/stores/user.svelte';
|
2024-09-19 18:20:09 -04:00
|
|
|
import { ByteUnit, convertToBytes } from '$lib/utils/byte-units';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2024-05-26 18:15:52 -04:00
|
|
|
import { createUserAdmin } from '@immich/sdk';
|
2024-09-19 18:20:09 -04:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-07-01 00:50:47 -04:00
|
|
|
import Button from '../elements/buttons/button.svelte';
|
2024-03-04 00:40:03 -05:00
|
|
|
import Slider from '../elements/slider.svelte';
|
2024-09-19 18:20:09 -04:00
|
|
|
import PasswordField from '../shared-components/password-field.svelte';
|
2024-04-16 05:06:15 +00:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
onSubmit: () => void;
|
|
|
|
|
onCancel: () => void;
|
|
|
|
|
oauthEnabled?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { onClose, onSubmit, onCancel, oauthEnabled = false }: Props = $props();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let error = $state('');
|
|
|
|
|
let success = $state('');
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let email = $state('');
|
|
|
|
|
let password = $state('');
|
|
|
|
|
let confirmPassword = $state('');
|
|
|
|
|
let name = $state('');
|
|
|
|
|
let shouldChangePassword = $state(true);
|
|
|
|
|
let notify = $state(true);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let canCreateUser = $state(false);
|
|
|
|
|
let quotaSize: number | undefined = $state();
|
|
|
|
|
let isCreatingUser = $state(false);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let quotaSizeInBytes = $derived(quotaSize ? convertToBytes(quotaSize, ByteUnit.GiB) : null);
|
2024-12-16 15:45:01 +01:00
|
|
|
let quotaSizeWarning = $derived(
|
|
|
|
|
quotaSizeInBytes && userInteraction.serverInfo && quotaSizeInBytes > userInteraction.serverInfo.diskSizeRaw,
|
|
|
|
|
);
|
2024-01-30 18:21:45 +01:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
$effect(() => {
|
2024-02-24 21:28:56 +01:00
|
|
|
if (password !== confirmPassword && confirmPassword.length > 0) {
|
2024-06-04 21:53:00 +02:00
|
|
|
error = $t('password_does_not_match');
|
2023-07-01 00:50:47 -04:00
|
|
|
canCreateUser = false;
|
|
|
|
|
} else {
|
|
|
|
|
error = '';
|
|
|
|
|
canCreateUser = true;
|
|
|
|
|
}
|
2024-11-14 08:43:25 -06:00
|
|
|
});
|
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-05-26 18:15:52 -04:00
|
|
|
await createUserAdmin({
|
|
|
|
|
userAdminCreateDto: {
|
2024-03-08 14:45:41 +01:00
|
|
|
email,
|
|
|
|
|
password,
|
|
|
|
|
shouldChangePassword,
|
|
|
|
|
name,
|
|
|
|
|
quotaSizeInBytes,
|
2024-05-02 16:43:18 +02:00
|
|
|
notify,
|
2023-07-01 00:50:47 -04:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-04 21:53:00 +02:00
|
|
|
success = $t('new_user_created');
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-09-20 23:02:58 +02:00
|
|
|
onSubmit();
|
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-06-04 21:53:00 +02:00
|
|
|
handleError(error, $t('errors.unable_to_create_user'));
|
2024-02-13 17:07:37 -05:00
|
|
|
} finally {
|
2023-07-01 00:50:47 -04:00
|
|
|
isCreatingUser = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-14 08:43:25 -06:00
|
|
|
|
|
|
|
|
const onsubmit = async (event: Event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
await registerUser();
|
|
|
|
|
};
|
2022-05-21 02:23:55 -05:00
|
|
|
</script>
|
|
|
|
|
|
2024-06-04 21:53:00 +02:00
|
|
|
<FullScreenModal title={$t('create_new_user')} showLogo {onClose}>
|
2024-11-14 08:43:25 -06:00
|
|
|
<form {onsubmit} autocomplete="off" id="create-new-user-form">
|
2024-04-16 05:06:15 +00:00
|
|
|
<div class="my-4 flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="email">{$t('email')}</label>
|
2024-04-16 05:06:15 +00:00
|
|
|
<input class="immich-form-input" id="email" bind:value={email} type="email" required />
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-05-02 16:43:18 +02:00
|
|
|
{#if $featureFlags.email}
|
|
|
|
|
<div class="my-4 flex place-items-center justify-between gap-2">
|
2024-06-12 12:54:40 +02:00
|
|
|
<label class="text-sm dark:text-immich-dark-fg" for="send-welcome-email">
|
|
|
|
|
{$t('admin.send_welcome_email')}
|
|
|
|
|
</label>
|
2024-05-02 16:43:18 +02:00
|
|
|
<Slider id="send-welcome-email" bind:checked={notify} />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2024-04-16 05:06:15 +00:00
|
|
|
<div class="my-4 flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="password">{$t('password')}</label>
|
2024-10-17 21:54:50 +05:30
|
|
|
<PasswordField id="password" bind:password autocomplete="new-password" required={!oauthEnabled} />
|
2024-04-16 05:06:15 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="confirmPassword">{$t('confirm_password')}</label>
|
2024-10-17 21:54:50 +05:30
|
|
|
<PasswordField
|
|
|
|
|
id="confirmPassword"
|
|
|
|
|
bind:password={confirmPassword}
|
|
|
|
|
autocomplete="new-password"
|
|
|
|
|
required={!oauthEnabled}
|
|
|
|
|
/>
|
2024-04-16 05:06:15 +00:00
|
|
|
</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">
|
2024-06-12 12:54:40 +02:00
|
|
|
{$t('admin.require_password_change_on_login')}
|
2024-04-16 05:06:15 +00:00
|
|
|
</label>
|
|
|
|
|
<Slider id="require-password-change" bind:checked={shouldChangePassword} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="name">{$t('name')}</label>
|
2024-04-16 05:06:15 +00:00
|
|
|
<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">
|
2024-06-12 12:54:40 +02:00
|
|
|
{$t('admin.quota_size_gib')}
|
2024-04-16 05:06:15 +00:00
|
|
|
{#if quotaSizeWarning}
|
2024-06-21 22:09:10 +02:00
|
|
|
<p class="text-red-400 text-sm">{$t('errors.quota_higher_than_disk_size')}</p>
|
2024-04-16 05:06:15 +00:00
|
|
|
{/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}
|
|
|
|
|
</form>
|
2024-11-14 08:43:25 -06:00
|
|
|
|
|
|
|
|
{#snippet stickyBottom()}
|
|
|
|
|
<Button color="gray" fullwidth onclick={onCancel}>{$t('cancel')}</Button>
|
2024-06-04 21:53:00 +02:00
|
|
|
<Button type="submit" disabled={isCreatingUser} fullwidth form="create-new-user-form">{$t('create')}</Button>
|
2024-11-14 08:43:25 -06:00
|
|
|
{/snippet}
|
2024-04-16 05:06:15 +00:00
|
|
|
</FullScreenModal>
|