2022-08-24 21:10:48 -07:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { goto } from '$app/navigation';
|
2025-01-14 09:14:28 -05:00
|
|
|
import Button from '$lib/components/elements/buttons/button.svelte';
|
|
|
|
|
import AuthPageLayout from '$lib/components/layouts/AuthPageLayout.svelte';
|
|
|
|
|
import PasswordField from '$lib/components/shared-components/password-field.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2024-02-27 08:37:37 -08:00
|
|
|
import { resetSavedUser, user } from '$lib/stores/user.store';
|
2025-01-14 09:14:28 -05:00
|
|
|
import { logout, updateMyUser } from '@immich/sdk';
|
2024-06-24 15:50:01 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2025-01-14 09:14:28 -05:00
|
|
|
import type { PageData } from './$types';
|
2022-08-24 21:10:48 -07:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
data: PageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { data }: Props = $props();
|
2024-02-27 08:37:37 -08:00
|
|
|
|
2025-01-14 09:14:28 -05:00
|
|
|
let password = $state('');
|
|
|
|
|
let passwordConfirm = $state('');
|
|
|
|
|
const valid = $derived(password === passwordConfirm && passwordConfirm.length > 0);
|
|
|
|
|
const errorMessage = $derived(passwordConfirm.length === 0 || valid ? '' : $t('password_does_not_match'));
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (event: Event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (!valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await updateMyUser({ userUpdateMeDto: { password: String(password) } });
|
2024-02-27 08:37:37 -08:00
|
|
|
await goto(AppRoute.AUTH_LOGIN);
|
|
|
|
|
resetSavedUser();
|
|
|
|
|
await logout();
|
|
|
|
|
};
|
2022-08-24 21:10:48 -07:00
|
|
|
</script>
|
|
|
|
|
|
2025-01-14 09:14:28 -05:00
|
|
|
<AuthPageLayout title={data.meta.title}>
|
2024-11-14 08:43:25 -06:00
|
|
|
{#snippet message()}
|
|
|
|
|
<p>
|
|
|
|
|
{$t('hi_user', { values: { name: $user.name, email: $user.email } })}
|
|
|
|
|
<br />
|
|
|
|
|
<br />
|
|
|
|
|
{$t('change_password_description')}
|
|
|
|
|
</p>
|
|
|
|
|
{/snippet}
|
2023-03-15 22:38:29 +01:00
|
|
|
|
2025-01-14 09:14:28 -05:00
|
|
|
<form onsubmit={onSubmit} method="post" class="mt-5 flex flex-col gap-5">
|
|
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="password">{$t('new_password')}</label>
|
|
|
|
|
<PasswordField id="password" bind:password autocomplete="new-password" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="confirmPassword">{$t('confirm_password')}</label>
|
|
|
|
|
<PasswordField id="confirmPassword" bind:password={passwordConfirm} autocomplete="new-password" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if errorMessage}
|
|
|
|
|
<p class="text-sm text-red-400">{errorMessage}</p>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<div class="my-5 flex w-full">
|
|
|
|
|
<Button type="submit" size="lg" fullwidth disabled={!valid}>{$t('to_change_password')}</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</AuthPageLayout>
|