2022-06-27 15:13:07 -05:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
2024-02-24 21:28:56 +01:00
|
|
|
import PasswordField from '../shared-components/password-field.svelte';
|
2024-05-26 18:15:52 -04:00
|
|
|
import { updateMyUser } from '@immich/sdk';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
let errorMessage: string;
|
2023-07-01 00:50:47 -04:00
|
|
|
let success: string;
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let password = '';
|
2024-02-13 17:07:37 -05:00
|
|
|
let passwordConfirm = '';
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
let valid = false;
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
$: {
|
2024-02-13 17:07:37 -05:00
|
|
|
if (password !== passwordConfirm && passwordConfirm.length > 0) {
|
2024-06-04 21:53:00 +02:00
|
|
|
errorMessage = $t('password_does_not_match');
|
2024-02-13 17:07:37 -05:00
|
|
|
valid = false;
|
2023-07-01 00:50:47 -04:00
|
|
|
} else {
|
2024-02-13 17:07:37 -05:00
|
|
|
errorMessage = '';
|
|
|
|
|
valid = true;
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 12:28:07 -05:00
|
|
|
|
2023-12-15 03:54:21 +01:00
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
success: void;
|
|
|
|
|
}>();
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
async function changePassword() {
|
2024-02-13 17:07:37 -05:00
|
|
|
if (valid) {
|
|
|
|
|
errorMessage = '';
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2024-05-26 18:15:52 -04:00
|
|
|
await updateMyUser({ userUpdateMeDto: { password: String(password) } });
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
dispatch('success');
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-27 15:13:07 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-07-18 13:19:39 -05:00
|
|
|
<form on:submit|preventDefault={changePassword} method="post" class="mt-5 flex flex-col gap-5">
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="password">{$t('new_password')}</label>
|
2024-02-24 21:28:56 +01:00
|
|
|
<PasswordField id="password" bind:password autocomplete="new-password" />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="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-02-24 21:28:56 +01:00
|
|
|
<PasswordField id="confirmPassword" bind:password={passwordConfirm} autocomplete="new-password" />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
{#if errorMessage}
|
|
|
|
|
<p class="text-sm text-red-400">{errorMessage}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if success}
|
2023-07-18 13:19:39 -05:00
|
|
|
<p class="text-sm text-immich-primary">{success}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
|
|
|
|
<div class="my-5 flex w-full">
|
2024-06-04 21:53:00 +02:00
|
|
|
<Button type="submit" size="lg" fullwidth>{$t('change_password')}</Button>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2023-03-15 22:38:29 +01:00
|
|
|
</form>
|