fix: make password changing actually work
This commit is contained in:
1 parent
76f22dab5c
commit
ac147086f1
4 files changed
+24
-19
No files matched your search
@@ -227,19 +227,6 @@ instance.subscribe(async (i) => {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
})
|
})
|
||||||
|
|
||||||
export function updateJwt(id: number, newJwt: string) {
|
|
||||||
const pd = get(profileData)
|
|
||||||
let prof = pd.profiles.find((p) => p.id == id)
|
|
||||||
|
|
||||||
if (!prof) return
|
|
||||||
prof = serializeUser(prof)
|
|
||||||
prof.jwt = newJwt
|
|
||||||
|
|
||||||
profileData.update((p) => ({ ...p, profile: id }))
|
|
||||||
|
|
||||||
profile.update(() => prof)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function setUserID(id: number) {
|
export async function setUserID(id: number) {
|
||||||
const pd = get(profileData)
|
const pd = get(profileData)
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
|
|||||||
@@ -128,6 +128,16 @@
|
|||||||
<Checkbox bind:checked={formData.federation_enabled} defaultValue={true}>
|
<Checkbox bind:checked={formData.federation_enabled} defaultValue={true}>
|
||||||
Federation enabled
|
Federation enabled
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
|
<Checkbox bind:checked={formData.federation_debug} defaultValue={false}>
|
||||||
|
Federation debug mode
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox bind:checked={formData.captcha_enabled} defaultValue={false}>
|
||||||
|
Captcha enabled
|
||||||
|
</Checkbox>
|
||||||
|
{#if formData.captcha_enabled}
|
||||||
|
{console.log(formData.captcha_difficulty)}
|
||||||
|
<Select bind:value={formData.captcha_difficulty} />
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<Button color="primary" size="lg" loading={saving} disabled={saving} submit>
|
<Button color="primary" size="lg" loading={saving} disabled={saving} submit>
|
||||||
Save
|
Save
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { setUser } from '$lib/auth.js'
|
import { setUser } from '$lib/auth.js'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { Material, toast } from 'mono-svelte'
|
|
||||||
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||||
import { getClient, validateInstance } from '$lib/lemmy.js'
|
import { getClient, validateInstance } from '$lib/lemmy.js'
|
||||||
import { Button, TextInput } from 'mono-svelte'
|
import { Button, TextInput } from 'mono-svelte'
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { profile, setUser, setUserID, updateJwt } from '$lib/auth.js'
|
import { deleteProfile, profile, setUser } from '$lib/auth.js'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { trycatch } from '$lib/util.js'
|
import { trycatch } from '$lib/util.js'
|
||||||
import { Button, TextInput, toast } from 'mono-svelte'
|
import { Button, TextInput, toast } from 'mono-svelte'
|
||||||
|
import { instance as currentInstance } from '$lib/instance.js'
|
||||||
|
|
||||||
let oldPassword = '',
|
let oldPassword = '',
|
||||||
newPassword = '',
|
newPassword = '',
|
||||||
newPasswordVerify = ''
|
newPasswordVerify = ''
|
||||||
|
let loading = false
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
|
loading = true
|
||||||
const res = await trycatch(async () => {
|
const res = await trycatch(async () => {
|
||||||
if (!$profile?.jwt) return
|
if (!$profile?.jwt) return
|
||||||
const res = await getClient().changePassword({
|
const res = await getClient().changePassword({
|
||||||
@@ -18,8 +21,10 @@
|
|||||||
old_password: oldPassword,
|
old_password: oldPassword,
|
||||||
})
|
})
|
||||||
if (res?.jwt) {
|
if (res?.jwt) {
|
||||||
updateJwt($profile.id, res.jwt)
|
const { instance, username } = $profile
|
||||||
await setUserID($profile.id)
|
deleteProfile($profile.id)
|
||||||
|
await setUser(res.jwt, instance, username!)
|
||||||
|
$currentInstance = instance
|
||||||
|
|
||||||
toast({ content: 'Your login was refreshed.', type: 'success' })
|
toast({ content: 'Your login was refreshed.', type: 'success' })
|
||||||
} else {
|
} else {
|
||||||
@@ -28,6 +33,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (res) toast({ content: 'Successfully changed your password. ' })
|
if (res) toast({ content: 'Successfully changed your password. ' })
|
||||||
|
|
||||||
|
loading = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -51,5 +58,7 @@
|
|||||||
type="password"
|
type="password"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<Button size="lg" color="primary" submit>Submit</Button>
|
<Button size="lg" color="primary" submit {loading} disabled={loading}>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
Reference in new issue
Block a user