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-13 17:07:37 -05:00
|
|
|
import { updateUser, type UserResponseDto } from '@immich/sdk';
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
export let user: UserResponseDto;
|
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) {
|
|
|
|
|
errorMessage = 'Password does not match';
|
|
|
|
|
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-02-13 17:07:37 -05:00
|
|
|
await updateUser({
|
2023-07-01 00:50:47 -04:00
|
|
|
updateUserDto: {
|
|
|
|
|
id: user.id,
|
|
|
|
|
password: String(password),
|
|
|
|
|
shouldChangePassword: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
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">
|
|
|
|
|
<label class="immich-form-label" for="password">New Password</label>
|
|
|
|
|
<input
|
|
|
|
|
class="immich-form-input"
|
|
|
|
|
id="password"
|
|
|
|
|
name="password"
|
|
|
|
|
type="password"
|
|
|
|
|
autocomplete="new-password"
|
|
|
|
|
required
|
|
|
|
|
bind:value={password}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2022-06-27 15:13:07 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="confirmPassword">Confirm Password</label>
|
|
|
|
|
<input
|
|
|
|
|
class="immich-form-input"
|
|
|
|
|
id="confirmPassword"
|
|
|
|
|
name="password"
|
|
|
|
|
type="password"
|
|
|
|
|
autocomplete="current-password"
|
|
|
|
|
required
|
2024-02-13 17:07:37 -05:00
|
|
|
bind:value={passwordConfirm}
|
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">
|
|
|
|
|
<Button type="submit" size="lg" fullwidth>Change password</Button>
|
|
|
|
|
</div>
|
2023-03-15 22:38:29 +01:00
|
|
|
</form>
|