design: redesign credentials page
This commit is contained in:
1 parent
37b28cf8ab
commit
3ada11ea58
15 files changed
+558
-289
No files matched your search
@@ -13,6 +13,7 @@
|
|||||||
"@tailwindcss/container-queries": "^0.1.1",
|
"@tailwindcss/container-queries": "^0.1.1",
|
||||||
"@tanstack/svelte-virtual": "^3.8.1",
|
"@tanstack/svelte-virtual": "^3.8.1",
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
|
"@types/ua-parser-js": "^0.7.39",
|
||||||
"autoprefixer": "^10.4.16",
|
"autoprefixer": "^10.4.16",
|
||||||
"jsdom": "^22.1.0",
|
"jsdom": "^22.1.0",
|
||||||
"lemmy-js-client": "latest",
|
"lemmy-js-client": "latest",
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
"tailwindcss": "^3.3.3",
|
"tailwindcss": "^3.3.3",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
|
"ua-parser-js": "^1.0.38",
|
||||||
"vite": "^5.0.0",
|
"vite": "^5.0.0",
|
||||||
"vitest": "^1.0.0"
|
"vitest": "^1.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
}[] = []
|
}[] = []
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Material color="transparent" padding="none" rounding="xl">
|
<Material color="transparent" padding="none" rounding="xl" {...$$restProps}>
|
||||||
{#if banner}
|
{#if banner}
|
||||||
<div class="max-h-36 overflow-visible">
|
<div class="max-h-36 overflow-visible">
|
||||||
<img
|
<img
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
class="ring-4 ring-slate-25 dark:ring-zinc-925 bg-slate-25 dark:bg-zinc-925"
|
class="ring-4 ring-slate-25 dark:ring-zinc-925 bg-slate-25 dark:bg-zinc-925"
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<span class="text-lg font-semibold">
|
<span class="text-lg font-medium">
|
||||||
{name}
|
{name}
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"
|
"
|
||||||
>
|
>
|
||||||
<h1
|
<h1
|
||||||
class="text-3xl font-bold flex items-center gap-2 w-full
|
class="text-3xl font-medium flex items-center gap-2 w-full
|
||||||
{$userSettings.font == 'satoshi/nunito'
|
{$userSettings.font == 'satoshi/nunito'
|
||||||
? 'font-display'
|
? 'font-display'
|
||||||
: ''} {$$props.class ?? ''}"
|
: ''} {$$props.class ?? ''}"
|
||||||
|
|||||||
@@ -22,10 +22,8 @@
|
|||||||
on:click
|
on:click
|
||||||
on:contextmenu
|
on:contextmenu
|
||||||
class="font-normal {selected
|
class="font-normal {selected
|
||||||
? 'text-primary-900 dark:!text-primary-100'
|
? 'text-primary-900 dark:!text-primary-100 bg-slate-100 dark:bg-zinc-800'
|
||||||
: 'text-slate-600 dark:text-zinc-400'} {$userSettings.expandSidebar
|
: 'text-slate-600 dark:text-zinc-400'} {$$props.class}"
|
||||||
? ''
|
|
||||||
: '//max-lg:!p-1 //[&>*]:max-lg:!justify-center'} {$$props.class}"
|
|
||||||
>
|
>
|
||||||
<slot {selected} name="icon" slot="prefix">
|
<slot {selected} name="icon" slot="prefix">
|
||||||
{#if icon}
|
{#if icon}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@
|
|||||||
"user": "User",
|
"user": "User",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"blocks": "Blocks",
|
"blocks": "Blocks",
|
||||||
"credentials": "Credentials",
|
"credentials": "Account",
|
||||||
"moderates": "Moderating",
|
"moderates": "Moderating",
|
||||||
"favorites": "Favorites",
|
"favorites": "Favorites",
|
||||||
"upvoted": "Upvoted",
|
"upvoted": "Upvoted",
|
||||||
@@ -205,6 +205,12 @@
|
|||||||
"media": {
|
"media": {
|
||||||
"title": "Media",
|
"title": "Media",
|
||||||
"download": "Download"
|
"download": "Download"
|
||||||
|
},
|
||||||
|
"logins": "Logins",
|
||||||
|
"welcome": "Welcome, {{default}}!",
|
||||||
|
"delete": {
|
||||||
|
"title": "Delete account",
|
||||||
|
"warning": "This is permanent. Are you sure you want to do this?"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"translators": "Translators",
|
"translators": "Translators",
|
||||||
@@ -532,7 +538,8 @@
|
|||||||
"disable": "Disable",
|
"disable": "Disable",
|
||||||
"add": "Add",
|
"add": "Add",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"send": "Send"
|
"send": "Send",
|
||||||
|
"general": "General"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"success": "Success",
|
"success": "Success",
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<script>
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import { Button } from 'mono-svelte'
|
||||||
|
|
||||||
|
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{
|
||||||
|
name: $t('routes.profile.credentials'),
|
||||||
|
url: '/profile/password',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: $t('form.profile.2fa.2fa'),
|
||||||
|
url: '/profile/password/2fa',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: $t('routes.passwordChange.title'),
|
||||||
|
url: '/profile/password/change',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: $t('routes.profile.logins'),
|
||||||
|
url: '/profile/password/logins',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: $t('routes.profile.delete.title'),
|
||||||
|
url: '/profile/password/delete',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Header pageHeader>
|
||||||
|
{routes.find((r) => $page.url.pathname == r.url)?.name}
|
||||||
|
</Header>
|
||||||
|
<div class="flex flex-row gap-12">
|
||||||
|
<nav class="flex flex-col gap-2 flex-1 max-sm:hidden">
|
||||||
|
{#each routes as route}
|
||||||
|
<SidebarButton
|
||||||
|
size="lg"
|
||||||
|
rounding="lg"
|
||||||
|
selected={$page.url.pathname == route.url}
|
||||||
|
href={route.url}
|
||||||
|
>
|
||||||
|
{route.name}
|
||||||
|
</SidebarButton>
|
||||||
|
{/each}
|
||||||
|
</nav>
|
||||||
|
<div class="flex-[3] max-w-full w-full min-w-0">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,178 +1,103 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { deleteProfile, profile, setUser } from '$lib/auth.js'
|
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||||
import { getClient, site } from '$lib/lemmy.js'
|
import { t } from '$lib/translations'
|
||||||
import { trycatch } from '$lib/util.js'
|
import { Material } from 'mono-svelte'
|
||||||
import { Button, Material, Snippet, TextInput, toast } from 'mono-svelte'
|
import {
|
||||||
import { instance as currentInstance } from '$lib/instance.js'
|
Icon,
|
||||||
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
Identification,
|
||||||
import { goto } from '$app/navigation'
|
Key,
|
||||||
import { page } from '$app/stores'
|
Trash,
|
||||||
import Switch from '$lib/components/input/Switch.svelte'
|
UserGroup,
|
||||||
import { feature } from '$lib/version.js'
|
} from 'svelte-hero-icons'
|
||||||
import { qr } from '@svelte-put/qr/svg'
|
|
||||||
import { t } from '$lib/translations.js'
|
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
let oldPassword = '',
|
|
||||||
newPassword = '',
|
|
||||||
newPasswordVerify = ''
|
|
||||||
let loading = false
|
|
||||||
|
|
||||||
let verify_totp = ''
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
let totpLink: string | undefined = undefined
|
|
||||||
$: totpEnabled =
|
|
||||||
data.my_user?.local_user_view.local_user.totp_2fa_enabled ?? totpLink
|
|
||||||
|
|
||||||
async function changePassword() {
|
|
||||||
try {
|
|
||||||
if (!$profile?.jwt) return
|
|
||||||
loading = true
|
|
||||||
const res = await getClient().changePassword({
|
|
||||||
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: $t('toast.loginRefresh'), type: 'success' })
|
|
||||||
} else {
|
|
||||||
throw new Error($t('toast.invalidLogin'))
|
|
||||||
}
|
|
||||||
|
|
||||||
toast({ content: $t('toast.passwordReset') })
|
|
||||||
} catch (e) {
|
|
||||||
toast({
|
|
||||||
content: e as any,
|
|
||||||
type: 'error',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
loading = false
|
|
||||||
}
|
|
||||||
|
|
||||||
async function twofa(enabled: boolean, update: boolean = false) {
|
|
||||||
if (!$profile?.jwt) return
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (update) {
|
|
||||||
await getClient().updateTotp({
|
|
||||||
enabled: enabled,
|
|
||||||
totp_token: verify_totp,
|
|
||||||
})
|
|
||||||
|
|
||||||
toast({
|
|
||||||
content: `2FA has been ${enabled ? 'enabled' : 'disabled'}`,
|
|
||||||
type: 'success',
|
|
||||||
})
|
|
||||||
|
|
||||||
goto($page.url, { invalidateAll: true })
|
|
||||||
} else {
|
|
||||||
const res = await getClient().generateTotpSecret()
|
|
||||||
totpLink = res.totp_secret_url
|
|
||||||
totpEnabled = true
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
toast({ content: e as any, type: 'error' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Header pageHeader>{$t('routes.profile.credentials')}</Header>
|
<div
|
||||||
<div class="flex flex-row flex-wrap gap-8">
|
class="grid grid-cols-1 lg:grid-cols-2 gap-4
|
||||||
<div class="flex flex-col gap-2 max-w-sm w-full">
|
grid-rows-2"
|
||||||
<Header>{$t('form.password')}</Header>
|
>
|
||||||
<form
|
<EntityHeader
|
||||||
on:submit|preventDefault={changePassword}
|
color="transparent"
|
||||||
class="max-w-sm flex flex-col gap-4"
|
avatar={data.my_user?.local_user_view.person.avatar}
|
||||||
|
name={$t('routes.profile.welcome', {
|
||||||
|
default: data.my_user?.local_user_view.person.name,
|
||||||
|
})}
|
||||||
|
stats={[
|
||||||
|
{
|
||||||
|
name: $t('profile.subscribed'),
|
||||||
|
value: data.my_user?.follows.length.toString() ?? '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: $t('routes.profile.moderates'),
|
||||||
|
value: data.my_user?.moderates.length.toString() ?? '',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
rounding="2xl"
|
||||||
|
class="row-span-2"
|
||||||
|
/>
|
||||||
|
<a href="/profile/password/2fa" class="row-span-1">
|
||||||
|
<Material
|
||||||
|
class="hover:ring-primary-900 dark:hover:ring-primary-100 hover:ring-2 transition-all
|
||||||
|
flex flex-col gap-2 h-full"
|
||||||
|
rounding="2xl"
|
||||||
>
|
>
|
||||||
<TextInput
|
<Material
|
||||||
bind:value={oldPassword}
|
rounding="full"
|
||||||
label={$t('form.profile.currentPassword')}
|
padding="sm"
|
||||||
type="password"
|
color="default"
|
||||||
minlength={10}
|
class="h-max w-max"
|
||||||
required
|
>
|
||||||
/>
|
<Icon src={Key} size="24" />
|
||||||
<TextInput
|
</Material>
|
||||||
bind:value={newPassword}
|
<span class="font-medium text-lg">{$t('form.profile.2fa.2fa')}</span>
|
||||||
label={$t('form.profile.newPassword')}
|
<span class="text-sm">
|
||||||
type="password"
|
{data.my_user?.local_user_view.local_user.totp_2fa_enabled
|
||||||
minlength={10}
|
? $t('common.enabled')
|
||||||
required
|
: $t('common.disabled')}
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
bind:value={newPasswordVerify}
|
|
||||||
label={$t('form.profile.verifyNewPassword')}
|
|
||||||
type="password"
|
|
||||||
minlength={10}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<Button size="lg" color="primary" submit {loading} disabled={loading}>
|
|
||||||
{$t('form.submit')}
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col gap-4 max-w-sm w-full">
|
|
||||||
<Header>{$t('form.profile.2fa.2fa')}</Header>
|
|
||||||
<p>
|
|
||||||
<span class="font-bold">
|
|
||||||
{totpEnabled ? $t('common.enabled') : $t('common.disabled')}
|
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</Material>
|
||||||
{#if totpEnabled || totpLink}
|
</a>
|
||||||
{#if totpLink && !totpEnabled}
|
<a href="/profile/password/change" class="row-span-1">
|
||||||
<Material color="transparent" class="!fill-white">
|
<Material
|
||||||
<svg use:qr={{ data: totpLink, logo: '/img/logo-isolated.svg' }} />
|
class="hover:ring-primary-900 dark:hover:ring-primary-100 hover:ring-2 transition-all
|
||||||
</Material>
|
flex flex-col gap-2 h-full"
|
||||||
<TextInput
|
rounding="2xl"
|
||||||
disabled
|
>
|
||||||
type="password"
|
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||||
value={totpLink}
|
<Icon src={Identification} size="24" />
|
||||||
label={$t('form.profile.2fa.totp')}
|
</Material>
|
||||||
>
|
<span class="font-medium text-lg">
|
||||||
<button
|
{$t('routes.passwordChange.title')}
|
||||||
slot="suffix"
|
</span>
|
||||||
class="contents"
|
</Material>
|
||||||
on:click={() => {
|
</a>
|
||||||
if (!totpLink) return
|
<a href="/profile/password/logins" class="sm:col-span-1">
|
||||||
navigator.clipboard?.writeText(totpLink)
|
<Material
|
||||||
toast({ content: $t('toast.copied') })
|
class="hover:ring-primary-900 dark:hover:ring-primary-100 hover:ring-2 transition-all
|
||||||
}}
|
flex flex-col gap-2 h-full"
|
||||||
>
|
rounding="2xl"
|
||||||
<Icon src={ClipboardDocument} size="20" mini />
|
>
|
||||||
</button>
|
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||||
<span class="font-normal text-xs">
|
<Icon src={UserGroup} size="24" />
|
||||||
{$t('form.profile.2fa.paste')}
|
</Material>
|
||||||
</span>
|
<span class="font-medium text-lg">
|
||||||
</TextInput>
|
{$t('routes.profile.logins')}
|
||||||
{/if}
|
</span>
|
||||||
<form class="flex flex-col gap-2" on:submit|preventDefault={() => {}}>
|
</Material>
|
||||||
<TextInput
|
</a>
|
||||||
bind:value={verify_totp}
|
<a href="/profile/password/logins" class="sm:col-span-1">
|
||||||
placeholder="012345"
|
<Material
|
||||||
label={$t('form.2fa')}
|
class="hover:ring-red-500 dark:hover:ring-red-500 hover:ring-2 transition-all
|
||||||
/>
|
flex flex-col gap-2 h-full text-red-500"
|
||||||
{#if totpEnabled}
|
rounding="2xl"
|
||||||
<Button on:click={() => twofa(false, true)} size="lg" color="primary">
|
>
|
||||||
{$t('common.disabled')}
|
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||||
</Button>
|
<Icon src={Trash} size="24" />
|
||||||
{:else}
|
</Material>
|
||||||
<Button on:click={() => twofa(true, true)} size="lg" color="primary">
|
<span class="font-medium text-lg">
|
||||||
{$t('common.enabled')}
|
{$t('routes.profile.delete.title')}
|
||||||
</Button>
|
</span>
|
||||||
{/if}
|
</Material>
|
||||||
</form>
|
</a>
|
||||||
{:else}
|
|
||||||
<Button on:click={() => twofa(true)} size="lg" color="primary">
|
|
||||||
{$t('form.setup')}
|
|
||||||
</Button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import { client } from '$lib/lemmy.js'
|
||||||
|
import { t } from '$lib/translations.js'
|
||||||
|
import { qr } from '@svelte-put/qr/svg'
|
||||||
|
import { Button, Material, TextInput, toast } from 'mono-svelte'
|
||||||
|
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
export let data
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
let totpLink: string | undefined = undefined
|
||||||
|
$: totpEnabled =
|
||||||
|
data.my_user?.local_user_view.local_user.totp_2fa_enabled ?? totpLink
|
||||||
|
|
||||||
|
let verify_totp = ''
|
||||||
|
|
||||||
|
async function twofa(enabled: boolean, update: boolean = false) {
|
||||||
|
try {
|
||||||
|
if (update) {
|
||||||
|
await client().updateTotp({
|
||||||
|
enabled: enabled,
|
||||||
|
totp_token: verify_totp,
|
||||||
|
})
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: `2FA has been ${enabled ? 'enabled' : 'disabled'}`,
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
|
||||||
|
goto($page.url, { invalidateAll: true })
|
||||||
|
} else {
|
||||||
|
const res = await client().generateTotpSecret()
|
||||||
|
totpLink = res.totp_secret_url
|
||||||
|
totpEnabled = true
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toast({ content: e as any, type: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="w-full flex flex-col">
|
||||||
|
<p class="">
|
||||||
|
<span class="font-medium text-lg">
|
||||||
|
{totpEnabled ? $t('common.enabled') : $t('common.disabled')}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
{#if totpEnabled || totpLink}
|
||||||
|
{#if totpLink && !totpEnabled}
|
||||||
|
<Material color="transparent" class="!fill-white">
|
||||||
|
<svg use:qr={{ data: totpLink, logo: '/img/logo-isolated.svg' }} />
|
||||||
|
</Material>
|
||||||
|
<TextInput
|
||||||
|
disabled
|
||||||
|
type="password"
|
||||||
|
value={totpLink}
|
||||||
|
label={$t('form.profile.2fa.totp')}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
slot="suffix"
|
||||||
|
class="contents"
|
||||||
|
on:click={() => {
|
||||||
|
if (!totpLink) return
|
||||||
|
navigator.clipboard?.writeText(totpLink)
|
||||||
|
toast({ content: $t('toast.copied') })
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon src={ClipboardDocument} size="20" mini />
|
||||||
|
</button>
|
||||||
|
<span class="font-normal text-xs">
|
||||||
|
{$t('form.profile.2fa.paste')}
|
||||||
|
</span>
|
||||||
|
</TextInput>
|
||||||
|
{/if}
|
||||||
|
<form
|
||||||
|
class="flex flex-col gap-2 w-full"
|
||||||
|
on:submit|preventDefault={() => {}}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
bind:value={verify_totp}
|
||||||
|
placeholder="012345"
|
||||||
|
label={$t('form.2fa')}
|
||||||
|
/>
|
||||||
|
{#if totpEnabled}
|
||||||
|
<Button on:click={() => twofa(false, true)} size="lg" color="primary">
|
||||||
|
{$t('common.disable')}
|
||||||
|
</Button>
|
||||||
|
{:else}
|
||||||
|
<Button on:click={() => twofa(true, true)} size="lg" color="primary">
|
||||||
|
{$t('common.enable')}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</form>
|
||||||
|
{:else}
|
||||||
|
<Button on:click={() => twofa(true)} size="lg" color="primary">
|
||||||
|
{$t('form.setup')}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { deleteProfile, profile, setUser } from '$lib/auth'
|
||||||
|
import { client } from '$lib/lemmy'
|
||||||
|
import { instance as currentInstance } from '$lib/instance'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import { Button, TextInput, toast } from 'mono-svelte'
|
||||||
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
|
||||||
|
let oldPassword = '',
|
||||||
|
newPassword = '',
|
||||||
|
newPasswordVerify = ''
|
||||||
|
let loading = false
|
||||||
|
|
||||||
|
async function changePassword() {
|
||||||
|
try {
|
||||||
|
loading = true
|
||||||
|
const res = await client().changePassword({
|
||||||
|
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: $t('toast.loginRefresh'), type: 'success' })
|
||||||
|
} else {
|
||||||
|
throw new Error($t('toast.invalidLogin'))
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({ content: $t('toast.passwordReset') })
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
content: errorMessage(e as any),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form on:submit|preventDefault={changePassword} class="flex flex-col gap-4">
|
||||||
|
<TextInput
|
||||||
|
bind:value={oldPassword}
|
||||||
|
label={$t('form.profile.currentPassword')}
|
||||||
|
type="password"
|
||||||
|
minlength={10}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
bind:value={newPassword}
|
||||||
|
label={$t('form.profile.newPassword')}
|
||||||
|
type="password"
|
||||||
|
minlength={10}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
bind:value={newPasswordVerify}
|
||||||
|
label={$t('form.profile.verifyNewPassword')}
|
||||||
|
type="password"
|
||||||
|
minlength={10}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
class="sm:ml-auto"
|
||||||
|
size="lg"
|
||||||
|
color="primary"
|
||||||
|
submit
|
||||||
|
{loading}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{$t('form.submit')}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { profileData, setUserID } from '$lib/auth'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import { client } from '$lib/lemmy'
|
||||||
|
import { t } from '$lib/translations'
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Material,
|
||||||
|
Modal,
|
||||||
|
removeToast,
|
||||||
|
Switch,
|
||||||
|
TextInput,
|
||||||
|
toast,
|
||||||
|
} from 'mono-svelte'
|
||||||
|
|
||||||
|
let deletion = {
|
||||||
|
modal: false,
|
||||||
|
password: '',
|
||||||
|
deleteContent: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteAccount(level: number) {
|
||||||
|
switch (level) {
|
||||||
|
case 0: {
|
||||||
|
toast({
|
||||||
|
content: $t('toast.confirmDelete1'),
|
||||||
|
action: () => deleteAccount(1),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
toast({
|
||||||
|
content: $t('toast.confirmDelete2'),
|
||||||
|
action: () => deleteAccount(2),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
toast({
|
||||||
|
content: $t('toast.confirmDelete3'),
|
||||||
|
action: () => deleteAccount(3),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
deletion.modal = true
|
||||||
|
deletion.password = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(deletion.password || null)) {
|
||||||
|
toast({
|
||||||
|
content: $t('toast.needPassword'),
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = toast({
|
||||||
|
content: $t('toast.deleting'),
|
||||||
|
loading: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client().deleteAccount({
|
||||||
|
password: deletion.password,
|
||||||
|
|
||||||
|
delete_content: deletion.deleteContent,
|
||||||
|
})
|
||||||
|
|
||||||
|
profileData.update((pd) => {
|
||||||
|
pd.profiles.splice(
|
||||||
|
pd.profiles.findIndex((p) => pd.profile == p.id),
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
return pd
|
||||||
|
})
|
||||||
|
|
||||||
|
setUserID(-1)
|
||||||
|
toast({
|
||||||
|
content: $t('toast.deleted'),
|
||||||
|
})
|
||||||
|
goto('/')
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: err as any,
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
removeToast(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if deletion.modal}
|
||||||
|
<Modal
|
||||||
|
bind:open={deletion.modal}
|
||||||
|
action="Submit"
|
||||||
|
on:action={() => deleteAccount(4)}
|
||||||
|
>
|
||||||
|
<span slot="title">{$t('form.profile.deleteAccount.label')}</span>
|
||||||
|
<TextInput
|
||||||
|
label={$t('form.password')}
|
||||||
|
type="password"
|
||||||
|
bind:value={deletion.password}
|
||||||
|
/>
|
||||||
|
<Checkbox bind:checked={deletion.deleteContent}>
|
||||||
|
{$t('form.profile.deleteAccount.deleteContent')}
|
||||||
|
<span slot="description">
|
||||||
|
{$t('form.profile.deleteAccount.warning')}
|
||||||
|
</span>
|
||||||
|
</Checkbox>
|
||||||
|
</Modal>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<Material
|
||||||
|
color="distinct"
|
||||||
|
class="border-2 !border-red-500 text-red-600 dark:text-red-400 flex flex-col gap-4"
|
||||||
|
padding="xl"
|
||||||
|
rounding="2xl"
|
||||||
|
>
|
||||||
|
<Header class="mx-auto w-max !font-bold">
|
||||||
|
{$t('routes.profile.delete.title')}
|
||||||
|
</Header>
|
||||||
|
<p class="text-base">
|
||||||
|
{$t('routes.profile.delete.warning')}
|
||||||
|
</p>
|
||||||
|
<Switch bind:checked={deletion.deleteContent}>
|
||||||
|
{$t('form.profile.deleteAccount.deleteContent')}
|
||||||
|
<span slot="description">
|
||||||
|
{$t('form.profile.deleteAccount.warning')}
|
||||||
|
</span>
|
||||||
|
</Switch>
|
||||||
|
<Button size="lg" color="danger" on:click={() => deleteAccount(3)}>
|
||||||
|
{$t('routes.profile.delete.title')}
|
||||||
|
</Button>
|
||||||
|
</Material>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
|
import { client } from '$lib/lemmy.js'
|
||||||
|
import { Checkbox, Material } from 'mono-svelte'
|
||||||
|
import { Icon, Key } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
import { UAParser } from 'ua-parser-js'
|
||||||
|
|
||||||
|
export let data
|
||||||
|
|
||||||
|
let checked: {
|
||||||
|
[token: string]: boolean
|
||||||
|
} = {}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Material
|
||||||
|
color="transparent"
|
||||||
|
class="flex flex-col gap-4 border overflow-auto max-h-[40rem]
|
||||||
|
h-full w-full
|
||||||
|
min-w-0 max-w-full"
|
||||||
|
rounding="2xl"
|
||||||
|
padding="none"
|
||||||
|
>
|
||||||
|
<table>
|
||||||
|
<thead class="sticky top-0">
|
||||||
|
<tr
|
||||||
|
class="divide-x border-b divide-slate-200 dark:divide-zinc-800 h-12 *:px-4
|
||||||
|
bg-slate-50 dark:bg-zinc-900"
|
||||||
|
>
|
||||||
|
<th class="w-4"></th>
|
||||||
|
<th align="left">User Agent</th>
|
||||||
|
<th align="left">IP</th>
|
||||||
|
<th align="right" class="w-24">Date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody
|
||||||
|
class="divide-y *:h-14 divide-slate-200 dark:divide-zinc-800 bg-white
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{#each data.tokens as token}
|
||||||
|
{@const ua = new UAParser(token.user_agent).getResult()}
|
||||||
|
<tr class="divide-x *:px-3 divide-slate-200 dark:divide-zinc-800">
|
||||||
|
<td class="!pr-1">
|
||||||
|
<Checkbox bind:checked={checked[token.user_id]} />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<div class="text-base">{ua.os.name} {ua.os.version}</div>
|
||||||
|
<div class="text-sm">{ua.browser.name}</div>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<span class="font-mono">{token.ip}</span>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td align="right">
|
||||||
|
<RelativeDate date={publishedToDate(token.published)} />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</Material>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { client } from '$lib/lemmy.js'
|
||||||
|
|
||||||
|
export async function load({ fetch, parent }) {
|
||||||
|
const user = await parent()
|
||||||
|
|
||||||
|
const response = await client({ func: fetch }).listLogins()
|
||||||
|
|
||||||
|
return {
|
||||||
|
tokens: response,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
|
||||||
import { profile, profileData, setUserID } from '$lib/auth.js'
|
import { profile, profileData, setUserID } from '$lib/auth.js'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { ImageInput, Material, removeToast, toast } from 'mono-svelte'
|
import { ImageInput, Material, removeToast, toast } from 'mono-svelte'
|
||||||
@@ -53,110 +52,9 @@
|
|||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
let deletion = {
|
|
||||||
modal: false,
|
|
||||||
password: '',
|
|
||||||
deleteContent: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteAccount(level: number) {
|
|
||||||
if (!$profile?.jwt) return
|
|
||||||
switch (level) {
|
|
||||||
case 0: {
|
|
||||||
toast({
|
|
||||||
content: $t('toast.confirmDelete1'),
|
|
||||||
action: () => deleteAccount(1),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case 1: {
|
|
||||||
toast({
|
|
||||||
content: $t('toast.confirmDelete2'),
|
|
||||||
action: () => deleteAccount(2),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case 2: {
|
|
||||||
toast({
|
|
||||||
content: $t('toast.confirmDelete3'),
|
|
||||||
action: () => deleteAccount(3),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case 3: {
|
|
||||||
deletion.modal = true
|
|
||||||
deletion.password = ''
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(deletion.password || null)) {
|
|
||||||
toast({
|
|
||||||
content: $t('toast.needPassword'),
|
|
||||||
type: 'warning',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = toast({
|
|
||||||
content: $t('toast.deleting'),
|
|
||||||
loading: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
|
||||||
await getClient().deleteAccount({
|
|
||||||
password: deletion.password,
|
|
||||||
|
|
||||||
delete_content: deletion.deleteContent,
|
|
||||||
})
|
|
||||||
|
|
||||||
profileData.update((pd) => {
|
|
||||||
pd.profiles.splice(
|
|
||||||
pd.profiles.findIndex((p) => pd.profile == p.id),
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
return pd
|
|
||||||
})
|
|
||||||
|
|
||||||
setUserID(-1)
|
|
||||||
toast({
|
|
||||||
content: $t('toast.deleted'),
|
|
||||||
})
|
|
||||||
goto('/')
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
content: err as any,
|
|
||||||
type: 'error',
|
|
||||||
})
|
|
||||||
} finally {
|
|
||||||
removeToast(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let loading = false
|
let loading = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if deletion.modal}
|
|
||||||
<Modal
|
|
||||||
bind:open={deletion.modal}
|
|
||||||
action="Submit"
|
|
||||||
on:action={() => deleteAccount(4)}
|
|
||||||
>
|
|
||||||
<span slot="title">{$t('form.profile.deleteAccount.label')}</span>
|
|
||||||
<TextInput
|
|
||||||
label={$t('form.password')}
|
|
||||||
type="password"
|
|
||||||
bind:value={deletion.password}
|
|
||||||
/>
|
|
||||||
<Checkbox bind:checked={deletion.deleteContent}>
|
|
||||||
{$t('form.profile.deleteAccount.deleteContent')}
|
|
||||||
<span slot="description">
|
|
||||||
{$t('form.profile.deleteAccount.warning')}
|
|
||||||
</span>
|
|
||||||
</Checkbox>
|
|
||||||
</Modal>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<form class="flex flex-col gap-4 h-full" on:submit|preventDefault={save}>
|
<form class="flex flex-col gap-4 h-full" on:submit|preventDefault={save}>
|
||||||
<Header pageHeader>{$t('routes.profile.settings')}</Header>
|
<Header pageHeader>{$t('routes.profile.settings')}</Header>
|
||||||
{#if data.my_user?.local_user_view?.local_user && formData}
|
{#if data.my_user?.local_user_view?.local_user && formData}
|
||||||
@@ -206,12 +104,4 @@
|
|||||||
{$t('common.save')}
|
{$t('common.save')}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
<Button
|
|
||||||
on:click={() => deleteAccount(0)}
|
|
||||||
color="danger"
|
|
||||||
size="lg"
|
|
||||||
class="ml-auto"
|
|
||||||
>
|
|
||||||
{$t('form.profile.deleteAccount.label')}
|
|
||||||
</Button>
|
|
||||||
</form>
|
</form>
|
||||||
@@ -15,6 +15,7 @@ export default {
|
|||||||
inter: ['Inter', 'system-ui', 'sans-serif'],
|
inter: ['Inter', 'system-ui', 'sans-serif'],
|
||||||
nunito: ['Nunito', 'system-ui', 'sans-serif'],
|
nunito: ['Nunito', 'system-ui', 'sans-serif'],
|
||||||
display: ['Satoshi', 'system-ui', 'sans-serif'],
|
display: ['Satoshi', 'system-ui', 'sans-serif'],
|
||||||
|
mono: ['monospace'],
|
||||||
},
|
},
|
||||||
extend: {
|
extend: {
|
||||||
animation: {
|
animation: {
|
||||||
|
|||||||
Reference in new issue
Block a user