diff --git a/package.json b/package.json index 7190e4e1..11afaa5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "1.13.5", + "version": "1.14.0", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/routes/profile/(local_user)/password/+page.svelte b/src/routes/profile/(local_user)/password/+page.svelte index f92b9ed1..b7c10194 100644 --- a/src/routes/profile/(local_user)/password/+page.svelte +++ b/src/routes/profile/(local_user)/password/+page.svelte @@ -2,15 +2,22 @@ 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 { Button, 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' + + export let data let oldPassword = '', newPassword = '', newPasswordVerify = '' let loading = false - async function submit() { + $: totpLink = data.my_user?.local_user_view?.local_user?.totp_2fa_url + + async function changePassword() { try { if (!$profile?.jwt) return loading = true @@ -41,29 +48,88 @@ loading = false } + + async function twofa(enabled: boolean) { + if (!$profile?.jwt) return + + try { + await getClient().saveUserSettings({ + ...data.my_user?.local_user_view.local_user, + ...data.my_user?.local_user_view.person, + generate_totp_2fa: enabled, + auth: $profile?.jwt, + }) + goto($page.url, { invalidateAll: true }) + toast({ + content: `Successfully ${enabled ? 'enabled' : 'disabled'} 2FA.`, + type: 'success', + }) + } catch (e) { + toast({ content: e as any, type: 'error' }) + } + } -

Change Password

-
- - - - - +

Credentials

+
+
+

Password

+
+ + + + + +
+
+

2FA

+

+ 2FA on Lemmy is unstable and you may lock yourself out of your account. +

+ {#if totpLink} + + + + Paste this in your authenticator app. + + + + {:else} + + {/if} +
+
diff --git a/src/routes/profile/(local_user)/settings/+page.svelte b/src/routes/profile/(local_user)/settings/+page.svelte index c0055256..7d88519a 100644 --- a/src/routes/profile/(local_user)/settings/+page.svelte +++ b/src/routes/profile/(local_user)/settings/+page.svelte @@ -26,15 +26,18 @@ let pfp = profileImage ? await uploadImage(profileImage[0], $profile.instance, $profile.jwt) : undefined + const res = await getClient().saveUserSettings({ auth: $profile.jwt, ...formData, avatar: pfp, }) + toast({ content: 'Saved your user settings.', type: 'success', }) + if (res.verify_email_sent) { toast({ content: 'A verification email was sent.', diff --git a/src/routes/profile/+layout.svelte b/src/routes/profile/+layout.svelte index e3cc3c66..4ac3139c 100644 --- a/src/routes/profile/+layout.svelte +++ b/src/routes/profile/+layout.svelte @@ -18,7 +18,7 @@ '/profile/blocks', '/profile/password', ]} - optionNames={['User', 'Settings', 'Blocks', 'Login']} + optionNames={['User', 'Settings', 'Blocks', 'Credentials']} selected={$page.url.pathname} on:select={(e) => { goto(e.detail)