7 files changed
+390
-5
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "photon-lemmy",
|
||||
"version": "0.9.6",
|
||||
"version": "0.9.7",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { setUser } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
@@ -53,7 +54,7 @@
|
||||
<title>Login</title>
|
||||
</svelte:head>
|
||||
|
||||
<Card class="p-6 max-w-lg w-full mx-auto">
|
||||
<div class="max-w-lg w-full mx-auto">
|
||||
<form on:submit|preventDefault={logIn} class="flex flex-col gap-6">
|
||||
<h1 class="font-bold text-2xl">Log in</h1>
|
||||
<div class="flex flex-row w-full items-center gap-2">
|
||||
@@ -118,5 +119,9 @@
|
||||
>
|
||||
Log in
|
||||
</Button>
|
||||
<hr class="dark:border-zinc-700" />
|
||||
<p class="text-sm text-center opacity-80">
|
||||
Don't have an account? <Link href="/signup" highlight>Sign up</Link>
|
||||
</p>
|
||||
</form>
|
||||
</Card>
|
||||
</div>
|
||||
@@ -1,12 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile, profileData, setUserID } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||
import FileInput from '$lib/components/input/FileInput.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||
import { removeToast, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { getClient, uploadImage } from '$lib/lemmy.js'
|
||||
import type { SaveUserSettings } from 'lemmy-js-client'
|
||||
|
||||
@@ -50,9 +52,104 @@
|
||||
loading = false
|
||||
}
|
||||
|
||||
let deletion = {
|
||||
modal: false,
|
||||
password: '',
|
||||
}
|
||||
|
||||
async function deleteAccount(level: number) {
|
||||
if (!$profile?.jwt) return
|
||||
switch (level) {
|
||||
case 0: {
|
||||
toast({
|
||||
content: 'Are you sure you want to delete your account?',
|
||||
action: () => deleteAccount(1),
|
||||
})
|
||||
return
|
||||
}
|
||||
case 1: {
|
||||
toast({
|
||||
content: 'Are you really sure?',
|
||||
action: () => deleteAccount(2),
|
||||
})
|
||||
return
|
||||
}
|
||||
case 2: {
|
||||
toast({
|
||||
content: 'Final warning. Are you reeeeeeally sure?',
|
||||
action: () => deleteAccount(3),
|
||||
})
|
||||
return
|
||||
}
|
||||
case 3: {
|
||||
deletion.modal = true
|
||||
deletion.password = ''
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (!(deletion.password || null)) {
|
||||
toast({
|
||||
content: 'You must provide your password.',
|
||||
type: 'warning',
|
||||
})
|
||||
}
|
||||
|
||||
const id = toast({
|
||||
content: 'You did this. Deleting account...',
|
||||
loading: true,
|
||||
})
|
||||
|
||||
try {
|
||||
const { jwt } = $profile
|
||||
|
||||
await getClient().deleteAccount({
|
||||
auth: jwt,
|
||||
password: deletion.password,
|
||||
})
|
||||
|
||||
profileData.update((pd) => {
|
||||
pd.profiles.splice(
|
||||
pd.profiles.findIndex((p) => pd.profile == p.id),
|
||||
1
|
||||
)
|
||||
|
||||
return pd
|
||||
})
|
||||
|
||||
setUserID(-1)
|
||||
toast({
|
||||
content: 'Your account was deleted.',
|
||||
})
|
||||
goto('/')
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
} finally {
|
||||
removeToast(id)
|
||||
}
|
||||
}
|
||||
|
||||
let loading = false
|
||||
</script>
|
||||
|
||||
{#if deletion.modal}
|
||||
<Modal
|
||||
bind:open={deletion.modal}
|
||||
action="Submit"
|
||||
on:action={() => deleteAccount(4)}
|
||||
>
|
||||
<span slot="title">Delete account</span>
|
||||
<TextInput
|
||||
label="Password"
|
||||
type="password"
|
||||
bind:value={deletion.password}
|
||||
/>
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<form class="flex flex-col gap-4 h-full" on:submit|preventDefault={save}>
|
||||
<h1 class="font-bold text-2xl">User settings</h1>
|
||||
{#if data.local_user_view?.local_user && formData}
|
||||
@@ -97,4 +194,12 @@
|
||||
The API didn't return your user settings.
|
||||
</Card>
|
||||
{/if}
|
||||
<Button
|
||||
on:click={() => deleteAccount(0)}
|
||||
color="danger"
|
||||
size="lg"
|
||||
class="ml-auto"
|
||||
>
|
||||
Delete account
|
||||
</Button>
|
||||
</form>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { DEFAULT_INSTANCE_URL } from '$lib/instance.js'
|
||||
import { validateInstance } from '$lib/lemmy.js'
|
||||
|
||||
let instance: string = ''
|
||||
let validating: boolean = false
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Sign up | Choose Instance</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="mx-auto max-w-xl flex flex-col gap-4">
|
||||
<h1 class="font-bold text-2xl">Sign Up</h1>
|
||||
<h2 class="font-bold text-xl">Choose an instance</h2>
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
on:submit|preventDefault={async () => {
|
||||
if (instance != '') {
|
||||
validating = true
|
||||
|
||||
if (await validateInstance(instance.trim())) {
|
||||
goto(`/signup/${instance}`)
|
||||
} else {
|
||||
toast({
|
||||
content: 'Could not contact that instance URL',
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
validating = false
|
||||
}
|
||||
}}
|
||||
>
|
||||
<TextInput
|
||||
bind:value={instance}
|
||||
label="Instance URL"
|
||||
required
|
||||
placeholder={DEFAULT_INSTANCE_URL}
|
||||
on:input={() => {
|
||||
instance = instance.toLowerCase().replaceAll(' ', '')
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
submit
|
||||
color="primary"
|
||||
size="lg"
|
||||
loading={validating}
|
||||
disabled={validating}
|
||||
>
|
||||
Go
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
import { LINKED_INSTANCE_URL } from "$lib/instance.js";
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
|
||||
export const load = () => {
|
||||
if (LINKED_INSTANCE_URL) {
|
||||
throw redirect(300, `/signup/${LINKED_INSTANCE_URL}`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import { setUser } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { GetCaptchaResponse } from 'lemmy-js-client'
|
||||
import {
|
||||
ArrowPath,
|
||||
ExclamationCircle,
|
||||
ExclamationTriangle,
|
||||
Icon,
|
||||
QuestionMarkCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let data
|
||||
|
||||
const instance = $page.params.instance
|
||||
|
||||
let captchaRequired = data.site_view.local_site.captcha_enabled
|
||||
|
||||
let email: string | undefined = ''
|
||||
|
||||
$: if (email == '') email = undefined
|
||||
|
||||
let username = '',
|
||||
password = '',
|
||||
passwordVerify = '',
|
||||
captcha: GetCaptchaResponse | null = null,
|
||||
verifyCaptcha: string | undefined = undefined,
|
||||
application: string | undefined = undefined,
|
||||
submitting: boolean = false,
|
||||
honeypot: string | undefined = undefined
|
||||
|
||||
const getCaptcha = async () =>
|
||||
(captcha = await getClient(instance, fetch).getCaptcha())
|
||||
|
||||
$: captchaAudio = captcha?.ok?.wav
|
||||
? `data:audio/wav;base64,${captcha.ok.wav}`
|
||||
: ''
|
||||
|
||||
async function submit() {
|
||||
submitting = true
|
||||
|
||||
try {
|
||||
const res = await getClient(instance, fetch).register({
|
||||
username: username,
|
||||
email: email,
|
||||
password: password,
|
||||
password_verify: passwordVerify,
|
||||
show_nsfw: true,
|
||||
answer: application,
|
||||
captcha_answer: verifyCaptcha,
|
||||
captcha_uuid: captcha?.ok?.uuid,
|
||||
honeypot,
|
||||
})
|
||||
|
||||
toast({
|
||||
content: `Signed up.${
|
||||
res.verify_email_sent ? ' A verification email was sent.' : ''
|
||||
}`,
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
if (res?.jwt) {
|
||||
await setUser(res.jwt, $page.params.instance, username)
|
||||
|
||||
toast({ content: 'Successfully logged in.', type: 'success' })
|
||||
goto('/')
|
||||
} else {
|
||||
throw new Error('Invalid credentials')
|
||||
}
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
submitting = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Sign up</title>
|
||||
</svelte:head>
|
||||
|
||||
<form
|
||||
class="flex flex-col gap-4 max-w-2xl mx-auto h-full"
|
||||
on:submit|preventDefault={submit}
|
||||
>
|
||||
<span class="flex gap-4 items-center font-bold text-xl text-center mx-auto">
|
||||
{#if data.site_view.site.icon}
|
||||
<Avatar width={48} url={data.site_view.site.icon} />
|
||||
{/if}
|
||||
{data.site_view.site.name}
|
||||
</span>
|
||||
|
||||
<h1 class="font-bold text-3xl">Create account</h1>
|
||||
{#if data.site_view.local_site.registration_mode == 'Closed'}
|
||||
<p class="mx-auto text-left">Registrations are closed for this instance.</p>
|
||||
{:else}
|
||||
<TextInput
|
||||
bind:value={email}
|
||||
label="Email"
|
||||
required={data.site_view.local_site.require_email_verification}
|
||||
type="email"
|
||||
placeholder="nigerianprince@notascam.com"
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={username}
|
||||
label="Username"
|
||||
required
|
||||
placeholder="BobTheDestroyer"
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={password}
|
||||
label="Password"
|
||||
required
|
||||
type="password"
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={passwordVerify}
|
||||
label="Confirm Password"
|
||||
required
|
||||
type="password"
|
||||
/>
|
||||
{#if data.site_view.local_site.registration_mode == 'RequireApplication'}
|
||||
<Card
|
||||
class="p-4 dark:text-yellow-200 text-yellow-800"
|
||||
cardColor="warning"
|
||||
>
|
||||
<Icon src={ExclamationTriangle} mini size="20" />
|
||||
To join this instance, you need to fill out this application, and wait to
|
||||
be accepted.
|
||||
</Card>
|
||||
{#if data.site_view.local_site.application_question}
|
||||
<Markdown source={data.site_view.local_site.application_question} />
|
||||
{/if}
|
||||
<TextArea
|
||||
label="Application"
|
||||
required
|
||||
placeholder="i like this instance's icon "
|
||||
bind:value={application}
|
||||
/>
|
||||
{/if}
|
||||
{#if captchaRequired}
|
||||
<div>
|
||||
<div class="block my-1 font-bold text-sm">Captcha</div>
|
||||
<div class="flex flex-col gap-4">
|
||||
{#await getCaptcha()}
|
||||
<Spinner width={32} />
|
||||
{:then}
|
||||
{#if captcha?.ok}
|
||||
<img
|
||||
src="data:image/png;base64,{captcha.ok.png}"
|
||||
alt="Captcha"
|
||||
class="w-max"
|
||||
/>
|
||||
<audio controls src={captchaAudio} />
|
||||
{:else}
|
||||
<Card cardColor="warning" class="p-3 flex gap-2">
|
||||
<Icon src={QuestionMarkCircle} mini size="24" />
|
||||
No captcha was returned
|
||||
</Card>
|
||||
{/if}
|
||||
{:catch err}
|
||||
<Card cardColor="error" class="p-3 flex gap-2">
|
||||
<Icon src={ExclamationCircle} mini size="24" />
|
||||
{err}
|
||||
</Card>
|
||||
{/await}
|
||||
<Button on:click={() => getCaptcha()} size="square-md">
|
||||
<Icon src={ArrowPath} size="16" mini />
|
||||
</Button>
|
||||
<TextInput
|
||||
required
|
||||
bind:value={verifyCaptcha}
|
||||
placeholder="i guess i'm a robot"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<input type="dn" name="honeypot" bind:value={honeypot} class="hidden" />
|
||||
<Button
|
||||
submit
|
||||
color="primary"
|
||||
size="lg"
|
||||
loading={submitting}
|
||||
disabled={submitting}
|
||||
class="mt-auto"
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
{/if}
|
||||
</form>
|
||||
@@ -0,0 +1,7 @@
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
|
||||
export async function load({ params, fetch }) {
|
||||
const site = await getClient(params.instance, fetch).getSite()
|
||||
|
||||
return site
|
||||
}
|
||||
Reference in new issue
Block a user