diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-11-06 17:42:02 -0500 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-11-07 19:09:36 -0500 |
| commit | 9f0ba2e243be772a7677f8250893f5da7b2acbfe (patch) | |
| tree | 3996d527e06a525a1531c095478cd3c02bbae3bb /ui/lib/components/ChangePassword.svelte | |
| parent | b89ffe00fbb28fac3daafb1f7adc71be72b59433 (diff) | |
Factor out the elements of the `/me` page, and style them a little.
Diffstat (limited to 'ui/lib/components/ChangePassword.svelte')
| -rw-r--r-- | ui/lib/components/ChangePassword.svelte | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/ui/lib/components/ChangePassword.svelte b/ui/lib/components/ChangePassword.svelte new file mode 100644 index 0000000..1e48bee --- /dev/null +++ b/ui/lib/components/ChangePassword.svelte @@ -0,0 +1,60 @@ +<script> + import { changePassword } from '$lib/apiServer.js'; + + let currentPassword = $state(''), + newPassword = $state(''), + confirmPassword = $state(''), + pending = $state(false), + form; + let valid = $derived(newPassword === confirmPassword && newPassword !== currentPassword); + let disabled = $derived(pending || !valid); + + async function onsubmit(event) { + event.preventDefault(); + pending = true; + let response = await changePassword(currentPassword, newPassword); + switch (response.status) { + case 200: + form.reset(); + break; + } + pending = false; + } +</script> + +<form {onsubmit} bind:this={form}> + <label + >current password + <input + class="input" + name="currentPassword" + type="password" + placeholder="password" + bind:value={currentPassword} + /> + </label> + + <label + >new password + <input + class="input" + name="newPassword" + type="password" + placeholder="password" + bind:value={newPassword} + /> + </label> + + <label + >confirm new password + <input + class="input" + name="confirmPassword" + type="password" + placeholder="password" + bind:value={confirmPassword} + /> + </label> + + <button class="btn bg-orange-500 mt-4" type="submit" {disabled}>change password</button> +</form> |
