design: redesign credentials page
This commit is contained in:
1 parent
37b28cf8ab
commit
3ada11ea58
15 files changed
+558
-289
No files matched your search
@@ -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">
|
||||
import { deleteProfile, profile, setUser } from '$lib/auth.js'
|
||||
import { getClient, site } from '$lib/lemmy.js'
|
||||
import { trycatch } from '$lib/util.js'
|
||||
import { Button, Material, Snippet, TextInput, toast } from 'mono-svelte'
|
||||
import { instance as currentInstance } from '$lib/instance.js'
|
||||
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import Switch from '$lib/components/input/Switch.svelte'
|
||||
import { feature } from '$lib/version.js'
|
||||
import { qr } from '@svelte-put/qr/svg'
|
||||
import { t } from '$lib/translations.js'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { Material } from 'mono-svelte'
|
||||
import {
|
||||
Icon,
|
||||
Identification,
|
||||
Key,
|
||||
Trash,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
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>
|
||||
|
||||
<Header pageHeader>{$t('routes.profile.credentials')}</Header>
|
||||
<div class="flex flex-row flex-wrap gap-8">
|
||||
<div class="flex flex-col gap-2 max-w-sm w-full">
|
||||
<Header>{$t('form.password')}</Header>
|
||||
<form
|
||||
on:submit|preventDefault={changePassword}
|
||||
class="max-w-sm flex flex-col gap-4"
|
||||
<div
|
||||
class="grid grid-cols-1 lg:grid-cols-2 gap-4
|
||||
grid-rows-2"
|
||||
>
|
||||
<EntityHeader
|
||||
color="transparent"
|
||||
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
|
||||
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 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')}
|
||||
<Material
|
||||
rounding="full"
|
||||
padding="sm"
|
||||
color="default"
|
||||
class="h-max w-max"
|
||||
>
|
||||
<Icon src={Key} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">{$t('form.profile.2fa.2fa')}</span>
|
||||
<span class="text-sm">
|
||||
{data.my_user?.local_user_view.local_user.totp_2fa_enabled
|
||||
? $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" 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.disabled')}
|
||||
</Button>
|
||||
{:else}
|
||||
<Button on:click={() => twofa(true, true)} size="lg" color="primary">
|
||||
{$t('common.enabled')}
|
||||
</Button>
|
||||
{/if}
|
||||
</form>
|
||||
{:else}
|
||||
<Button on:click={() => twofa(true)} size="lg" color="primary">
|
||||
{$t('form.setup')}
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</Material>
|
||||
</a>
|
||||
<a href="/profile/password/change" 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"
|
||||
>
|
||||
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||
<Icon src={Identification} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">
|
||||
{$t('routes.passwordChange.title')}
|
||||
</span>
|
||||
</Material>
|
||||
</a>
|
||||
<a href="/profile/password/logins" class="sm:col-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"
|
||||
>
|
||||
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||
<Icon src={UserGroup} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">
|
||||
{$t('routes.profile.logins')}
|
||||
</span>
|
||||
</Material>
|
||||
</a>
|
||||
<a href="/profile/password/logins" class="sm:col-span-1">
|
||||
<Material
|
||||
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"
|
||||
rounding="2xl"
|
||||
>
|
||||
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||
<Icon src={Trash} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">
|
||||
{$t('routes.profile.delete.title')}
|
||||
</span>
|
||||
</Material>
|
||||
</a>
|
||||
</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">
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile, profileData, setUserID } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, Material, removeToast, toast } from 'mono-svelte'
|
||||
@@ -53,110 +52,9 @@
|
||||
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
|
||||
</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}>
|
||||
<Header pageHeader>{$t('routes.profile.settings')}</Header>
|
||||
{#if data.my_user?.local_user_view?.local_user && formData}
|
||||
@@ -206,12 +104,4 @@
|
||||
{$t('common.save')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
on:click={() => deleteAccount(0)}
|
||||
color="danger"
|
||||
size="lg"
|
||||
class="ml-auto"
|
||||
>
|
||||
{$t('form.profile.deleteAccount.label')}
|
||||
</Button>
|
||||
</form>
|
||||
Reference in new issue
Block a user