-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from Xyphyn/drop_in
v2: Make photon a drop in replacement
- Loading branch information
Showing
24 changed files
with
458 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="[email protected]" | ||
/> | ||
<Button color="primary" size="lg" {loading} disabled={loading} submit> | ||
Submit | ||
</Button> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const load = ({ params }) => ({ | ||
token: params.token, | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<script lang="ts"> | ||
import { deleteProfile, profile, setUser } from '$lib/auth.js' | ||
import { getClient } from '$lib/lemmy.js' | ||
import { trycatch } from '$lib/util.js' | ||
import { Button, TextInput, toast } from 'mono-svelte' | ||
import { instance as currentInstance } from '$lib/instance.js' | ||
let oldPassword = '', | ||
newPassword = '', | ||
newPasswordVerify = '' | ||
let loading = false | ||
async function submit() { | ||
loading = true | ||
const res = await trycatch(async () => { | ||
if (!$profile?.jwt) return | ||
const res = await getClient().changePassword({ | ||
auth: $profile?.jwt, | ||
new_password: newPassword, | ||
new_password_verify: newPasswordVerify, | ||
old_password: oldPassword, | ||
}) | ||
if (res?.jwt) { | ||
const { instance, username } = $profile | ||
deleteProfile($profile.id) | ||
await setUser(res.jwt, instance, username!) | ||
$currentInstance = instance | ||
toast({ content: 'Your login was refreshed.', type: 'success' }) | ||
} else { | ||
throw new Error('Invalid credentials') | ||
} | ||
}) | ||
if (res) toast({ content: 'Successfully changed your password. ' }) | ||
loading = false | ||
} | ||
</script> | ||
|
||
<h1 class="font-bold text-3xl">Change Password</h1> | ||
<form on:submit|preventDefault={submit} class="max-w-sm flex flex-col gap-4"> | ||
<TextInput | ||
bind:value={oldPassword} | ||
label="Current Password" | ||
type="password" | ||
required | ||
/> | ||
<TextInput | ||
bind:value={newPassword} | ||
label="New Password" | ||
type="password" | ||
required | ||
/> | ||
<TextInput | ||
bind:value={newPasswordVerify} | ||
label="New Password (Verify)" | ||
type="password" | ||
required | ||
/> | ||
<Button size="lg" color="primary" submit {loading} disabled={loading}> | ||
Submit | ||
</Button> | ||
</form> |
Oops, something went wrong.