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';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { changePassword } from '@immich/sdk';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { fade } from 'svelte/transition';
|
2024-02-22 15:36:14 +01:00
|
|
|
|
|
|
|
|
import Button from '$lib/components/elements/buttons/button.svelte';
|
2024-02-14 07:25:15 -08:00
|
|
|
import type { HttpError } from '@sveltejs/kit';
|
2024-02-22 15:36:14 +01:00
|
|
|
import SettingInputField, {
|
|
|
|
|
SettingInputFieldType,
|
|
|
|
|
} from '$lib/components/shared-components/settings/setting-input-field.svelte';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let password = '';
|
|
|
|
|
let newPassword = '';
|
|
|
|
|
let confirmPassword = '';
|
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,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
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 }}>
|
|
|
|
|
<form autocomplete="off" on:submit|preventDefault>
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="ml-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
|
|
|
|
|
type="submit"
|
|
|
|
|
size="sm"
|
|
|
|
|
disabled={!(password && newPassword && newPassword === confirmPassword)}
|
2024-06-04 21:53:00 +02:00
|
|
|
on:click={() => 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>
|