Skip to content

Commit

Permalink
fix: make password changing actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyphyn committed Sep 27, 2023
1 parent 76f22da commit ac14708
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
13 changes: 0 additions & 13 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,6 @@ instance.subscribe(async (i) => {
} 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) {
const pd = get(profileData)
if (id == -1) {
Expand Down
10 changes: 10 additions & 0 deletions src/routes/admin/config/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@
<Checkbox bind:checked={formData.federation_enabled} defaultValue={true}>
Federation enabled
</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}
<Button color="primary" size="lg" loading={saving} disabled={saving} submit>
Save
Expand Down
3 changes: 1 addition & 2 deletions src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { setUser } from '$lib/auth.js'
import Link from '$lib/components/input/Link.svelte'
import { Material, toast } from 'mono-svelte'
import { toast } from 'mono-svelte'
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
import { getClient, validateInstance } from '$lib/lemmy.js'
import { Button, TextInput } from 'mono-svelte'
Expand Down
17 changes: 13 additions & 4 deletions src/routes/profile/(local_user)/password/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<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 { trycatch } from '$lib/util.js'
import { Button, TextInput, toast } from 'mono-svelte'
import { instance as currentInstance } from '$lib/instance.js'
let oldPassword = '',
newPassword = '',
newPasswordVerify = ''
let loading = false
async function submit() {
loading = true
const res = await trycatch(async () => {
if (!$profile?.jwt) return
const res = await getClient().changePassword({
Expand All @@ -18,8 +21,10 @@
old_password: oldPassword,
})
if (res?.jwt) {
updateJwt($profile.id, res.jwt)
await setUserID($profile.id)
const { instance, username } = $profile
deleteProfile($profile.id)
await setUser(res.jwt, instance, username!)
$currentInstance = instance
toast({ content: 'Your login was refreshed.', type: 'success' })
} else {
Expand All @@ -28,6 +33,8 @@
})
if (res) toast({ content: 'Successfully changed your password. ' })
loading = false
}
</script>

Expand All @@ -51,5 +58,7 @@
type="password"
required
/>
<Button size="lg" color="primary" submit>Submit</Button>
<Button size="lg" color="primary" submit {loading} disabled={loading}>
Submit
</Button>
</form>

0 comments on commit ac14708

Please sign in to comment.