feat: add password resets
This commit is contained in:
1 parent
f50260c197
commit
505175277c
5 files changed
+177
-1
No files matched your search
@@ -6,7 +6,12 @@
|
|||||||
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||||
import { getClient, validateInstance } from '$lib/lemmy.js'
|
import { getClient, validateInstance } from '$lib/lemmy.js'
|
||||||
import { Button, TextInput } from 'mono-svelte'
|
import { Button, TextInput } from 'mono-svelte'
|
||||||
import { AtSymbol, Icon, Identification } from 'svelte-hero-icons'
|
import {
|
||||||
|
AtSymbol,
|
||||||
|
Icon,
|
||||||
|
Identification,
|
||||||
|
QuestionMarkCircle,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
instance: DEFAULT_INSTANCE_URL,
|
instance: DEFAULT_INSTANCE_URL,
|
||||||
@@ -116,6 +121,10 @@
|
|||||||
<Icon src={Identification} mini size="16" />
|
<Icon src={Identification} mini size="16" />
|
||||||
Sign Up
|
Sign Up
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button color="tertiary" href="/login_reset">
|
||||||
|
<Icon src={QuestionMarkCircle} mini size="16" />
|
||||||
|
Forgot Password
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
DEFAULT_INSTANCE_URL,
|
||||||
|
LINKED_INSTANCE_URL,
|
||||||
|
instance as currentInstance,
|
||||||
|
} from '$lib/instance.js'
|
||||||
|
import { getClient, validateInstance } from '$lib/lemmy.js'
|
||||||
|
import { Button, TextInput, toast } from 'mono-svelte'
|
||||||
|
|
||||||
|
let instance = LINKED_INSTANCE_URL || $currentInstance || ''
|
||||||
|
let email = ''
|
||||||
|
let loading = false
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
loading = true
|
||||||
|
try {
|
||||||
|
if (!(await validateInstance(instance)))
|
||||||
|
throw new Error('Failed to contact instance url')
|
||||||
|
|
||||||
|
await getClient(instance).passwordReset({
|
||||||
|
email: email,
|
||||||
|
})
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: 'A password reset link was sent to your email.',
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: err as any,
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="my-auto max-w-xl mx-auto flex flex-col gap-2">
|
||||||
|
<h1 class="font-bold text-3xl">Reset Password</h1>
|
||||||
|
<p>
|
||||||
|
Enter the email of your account, and a password reset link will be sent. If
|
||||||
|
you did not have an email set up, contact your instance admins.
|
||||||
|
</p>
|
||||||
|
<form class="mt-2 flex flex-col gap-4" on:submit|preventDefault={submit}>
|
||||||
|
{#if !LINKED_INSTANCE_URL}
|
||||||
|
<TextInput
|
||||||
|
bind:value={instance}
|
||||||
|
label="Instance URL"
|
||||||
|
placeholder={DEFAULT_INSTANCE_URL}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
<TextInput
|
||||||
|
bind:value={email}
|
||||||
|
label="Email"
|
||||||
|
type="email"
|
||||||
|
required
|
||||||
|
placeholder="example@example.com"
|
||||||
|
/>
|
||||||
|
<Button color="primary" size="lg" {loading} disabled={loading} submit>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<script>
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
import { XMark, Icon } from 'svelte-hero-icons'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-col items-center h-max my-auto gap-2">
|
||||||
|
<div
|
||||||
|
class="rounded-full bg-red-200 dark:bg-red-900 text-red-600 dark:text-red-300 p-3"
|
||||||
|
>
|
||||||
|
<Icon src={XMark} size="32" mini />
|
||||||
|
</div>
|
||||||
|
<h1 class="text-red-800 dark:text-red-300 text-2xl font-semibold">Error</h1>
|
||||||
|
<p class="text-red-800 dark:text-red-300">
|
||||||
|
That password reset token doesn't exist.
|
||||||
|
</p>
|
||||||
|
<code>{$page.error?.message}</code>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import {
|
||||||
|
DEFAULT_INSTANCE_URL,
|
||||||
|
LINKED_INSTANCE_URL,
|
||||||
|
instance as currentInstance,
|
||||||
|
} from '$lib/instance.js'
|
||||||
|
import { getClient, validateInstance } from '$lib/lemmy.js'
|
||||||
|
import { Button, TextInput, toast } from 'mono-svelte'
|
||||||
|
|
||||||
|
export let data: {
|
||||||
|
token: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let instance = LINKED_INSTANCE_URL || $currentInstance || ''
|
||||||
|
let password = '',
|
||||||
|
password_verify = ''
|
||||||
|
let loading = false
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
loading = true
|
||||||
|
try {
|
||||||
|
if (!(await validateInstance(instance)))
|
||||||
|
throw new Error('Failed to contact instance url')
|
||||||
|
|
||||||
|
await getClient(instance).passwordChangeAfterReset({
|
||||||
|
password: password,
|
||||||
|
password_verify: password_verify,
|
||||||
|
token: data.token,
|
||||||
|
})
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: 'Your password was reset.',
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
|
||||||
|
goto('/login')
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: err as any,
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="my-auto max-w-xl mx-auto flex flex-col gap-2">
|
||||||
|
<h1 class="font-bold text-3xl">Reset Password</h1>
|
||||||
|
<p>
|
||||||
|
You've clicked an email with the password reset link in it. Now, choose your
|
||||||
|
new password.
|
||||||
|
</p>
|
||||||
|
<form class="mt-2 flex flex-col gap-4" on:submit|preventDefault={submit}>
|
||||||
|
{#if !LINKED_INSTANCE_URL}
|
||||||
|
<TextInput
|
||||||
|
bind:value={instance}
|
||||||
|
label="Instance URL"
|
||||||
|
placeholder={DEFAULT_INSTANCE_URL}
|
||||||
|
required
|
||||||
|
>
|
||||||
|
<span class="font-normal text-xs">
|
||||||
|
What instance did you reset your password for?
|
||||||
|
</span>
|
||||||
|
</TextInput>
|
||||||
|
{/if}
|
||||||
|
<TextInput
|
||||||
|
bind:value={password}
|
||||||
|
label="New Password"
|
||||||
|
type="password"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
bind:value={password_verify}
|
||||||
|
label="New Password (Verify)"
|
||||||
|
type="password"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<Button color="primary" size="lg" {loading} disabled={loading} submit>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export const load = ({ params }) => ({
|
||||||
|
token: params.token,
|
||||||
|
})
|
||||||
Reference in new issue
Block a user