2022-12-26 10:35:52 -05:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import {
|
|
|
|
|
notificationController,
|
|
|
|
|
NotificationType,
|
|
|
|
|
} from '$lib/components/shared-components/notification/notification';
|
2025-03-12 16:56:55 -04:00
|
|
|
import SettingInputField from '$lib/components/shared-components/settings/setting-input-field.svelte';
|
|
|
|
|
import { SettingInputFieldType } from '$lib/constants';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { changePassword } from '@immich/sdk';
|
2025-03-12 16:56:55 -04:00
|
|
|
import { Button } from '@immich/ui';
|
2024-02-14 07:25:15 -08:00
|
|
|
import type { HttpError } from '@sveltejs/kit';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2025-03-12 16:56:55 -04:00
|
|
|
import { fade } from 'svelte/transition';
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let password = $state('');
|
|
|
|
|
let newPassword = $state('');
|
|
|
|
|
let confirmPassword = $state('');
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleChangePassword = async () => {
|
|
|
|
|
try {
|
2024-02-13 17:07:37 -05:00
|
|
|
await changePassword({ changePasswordDto: { password, newPassword } });
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({
|
2024-06-04 21:53:00 +02:00
|
|
|
message: $t('updated_password'),
|
2023-07-01 00:50:47 -04:00
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
password = '';
|
|
|
|
|
newPassword = '';
|
|
|
|
|
confirmPassword = '';
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error [user-profile] [changePassword]', error);
|
|
|
|
|
notificationController.show({
|
2024-06-12 12:54:40 +02:00
|
|
|
message: (error as HttpError)?.body?.message || $t('errors.unable_to_change_password'),
|
2023-07-01 00:50:47 -04:00
|
|
|
type: NotificationType.Error,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-11-14 08:43:25 -06:00
|
|
|
|
|
|
|
|
const onsubmit = (event: Event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
};
|
2022-12-26 10:35:52 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<section class="my-4">
|
2023-07-01 00:50:47 -04:00
|
|
|
<div in:fade={{ duration: 500 }}>
|
2024-11-14 08:43:25 -06:00
|
|
|
<form autocomplete="off" {onsubmit}>
|
2025-04-28 09:53:53 -04:00
|
|
|
<div class="ms-4 mt-4 flex flex-col gap-4">
|
2023-07-01 00:50:47 -04:00
|
|
|
<SettingInputField
|
|
|
|
|
inputType={SettingInputFieldType.PASSWORD}
|
2024-06-14 07:32:41 +00:00
|
|
|
label={$t('password')}
|
2023-07-01 00:50:47 -04:00
|
|
|
bind:value={password}
|
|
|
|
|
required={true}
|
2024-02-24 21:28:56 +01:00
|
|
|
passwordAutocomplete="current-password"
|
2023-07-01 00:50:47 -04:00
|
|
|
/>
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<SettingInputField
|
|
|
|
|
inputType={SettingInputFieldType.PASSWORD}
|
2024-06-14 07:32:41 +00:00
|
|
|
label={$t('new_password')}
|
2023-07-01 00:50:47 -04:00
|
|
|
bind:value={newPassword}
|
|
|
|
|
required={true}
|
2024-02-24 21:28:56 +01:00
|
|
|
passwordAutocomplete="new-password"
|
2023-07-01 00:50:47 -04:00
|
|
|
/>
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<SettingInputField
|
|
|
|
|
inputType={SettingInputFieldType.PASSWORD}
|
2024-06-14 07:32:41 +00:00
|
|
|
label={$t('confirm_password')}
|
2023-07-01 00:50:47 -04:00
|
|
|
bind:value={confirmPassword}
|
|
|
|
|
required={true}
|
2024-02-24 21:28:56 +01:00
|
|
|
passwordAutocomplete="new-password"
|
2023-07-01 00:50:47 -04:00
|
|
|
/>
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex justify-end">
|
|
|
|
|
<Button
|
2025-03-12 16:56:55 -04:00
|
|
|
shape="round"
|
2023-07-01 00:50:47 -04:00
|
|
|
type="submit"
|
2025-03-12 16:56:55 -04:00
|
|
|
size="small"
|
2023-07-01 00:50:47 -04:00
|
|
|
disabled={!(password && newPassword && newPassword === confirmPassword)}
|
2024-11-14 08:43:25 -06:00
|
|
|
onclick={() => handleChangePassword()}>{$t('save')}</Button
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
2022-12-26 10:35:52 -05:00
|
|
|
</section>
|