feat: add password changing
This commit is contained in:
1 parent
505175277c
commit
76f22dab5c
12 files changed
+138
-54
No files matched your search
+14
-1
@@ -135,7 +135,7 @@ export async function setUser(jwt: string, inst: string, username: string) {
|
||||
|
||||
return {
|
||||
profile: id,
|
||||
profiles: [...pd.profiles, newProfile],
|
||||
profiles: [newProfile, ...pd.profiles],
|
||||
}
|
||||
})
|
||||
|
||||
@@ -227,6 +227,19 @@ 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) {
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<title>Communities</title>
|
||||
</svelte:head>
|
||||
|
||||
<h1 class="text-2xl font-bold">
|
||||
<h1 class="text-3xl font-bold">
|
||||
<span>Communities</span>
|
||||
<Popover
|
||||
openOnHover
|
||||
|
||||
@@ -46,6 +46,6 @@
|
||||
passedCommunity={community}
|
||||
on:submit={(e) => goto(`/post/${e.detail.post.id}`)}
|
||||
>
|
||||
<h1 class="text-2xl font-bold" slot="formtitle">Create Post</h1>
|
||||
<h1 class="text-3xl font-bold" slot="formtitle">Create Post</h1>
|
||||
</PostForm>
|
||||
</div>
|
||||
@@ -19,7 +19,7 @@
|
||||
</script>
|
||||
|
||||
<div class="mb-4 flex flex-col gap-4">
|
||||
<h1 class="font-bold text-2xl">Reports</h1>
|
||||
<h1 class="font-bold text-3xl">Reports</h1>
|
||||
<div class="flex flex-row gap-2 flex-wrap items-center">
|
||||
<Select
|
||||
bind:value={data.type}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load() {
|
||||
return (await getClient().getSite({ auth: get(profile)?.jwt })).my_user
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { profile, setUser, setUserID, updateJwt } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { trycatch } from '$lib/util.js'
|
||||
import { Button, TextInput, toast } from 'mono-svelte'
|
||||
|
||||
let oldPassword = '',
|
||||
newPassword = '',
|
||||
newPasswordVerify = ''
|
||||
|
||||
async function submit() {
|
||||
const res = await trycatch(async () => {
|
||||
if (!$profile?.jwt) return
|
||||
const res = await getClient().changePassword({
|
||||
auth: $profile?.jwt,
|
||||
new_password: newPassword,
|
||||
new_password_verify: newPasswordVerify,
|
||||
old_password: oldPassword,
|
||||
})
|
||||
if (res?.jwt) {
|
||||
updateJwt($profile.id, res.jwt)
|
||||
await setUserID($profile.id)
|
||||
|
||||
toast({ content: 'Your login was refreshed.', type: 'success' })
|
||||
} else {
|
||||
throw new Error('Invalid credentials')
|
||||
}
|
||||
})
|
||||
|
||||
if (res) toast({ content: 'Successfully changed your password. ' })
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1 class="font-bold text-3xl">Change Password</h1>
|
||||
<form on:submit|preventDefault={submit} class="max-w-sm flex flex-col gap-4">
|
||||
<TextInput
|
||||
bind:value={oldPassword}
|
||||
label="Current Password"
|
||||
type="password"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={newPassword}
|
||||
label="New Password"
|
||||
type="password"
|
||||
required
|
||||
/>
|
||||
<TextInput
|
||||
bind:value={newPasswordVerify}
|
||||
label="New Password (Verify)"
|
||||
type="password"
|
||||
required
|
||||
/>
|
||||
<Button size="lg" color="primary" submit>Submit</Button>
|
||||
</form>
|
||||
@@ -11,8 +11,8 @@
|
||||
export let data
|
||||
|
||||
let formData: Omit<SaveUserSettings, 'auth'> | undefined = {
|
||||
...data.local_user_view?.local_user,
|
||||
...data.local_user_view?.person,
|
||||
...data.my_user?.local_user_view?.local_user,
|
||||
...data.my_user?.local_user_view?.person,
|
||||
}
|
||||
|
||||
let profileImage: FileList | undefined
|
||||
@@ -150,7 +150,7 @@
|
||||
|
||||
<form class="flex flex-col gap-4 h-full" on:submit|preventDefault={save}>
|
||||
<h1 class="font-bold text-2xl">User settings</h1>
|
||||
{#if data.local_user_view?.local_user && formData}
|
||||
{#if data.my_user?.local_user_view?.local_user && formData}
|
||||
<TextInput
|
||||
label="Display name"
|
||||
bind:value={formData.display_name}
|
||||
|
||||
@@ -12,8 +12,13 @@
|
||||
<div class="flex flex-col gap-4 h-full">
|
||||
<MultiSelect
|
||||
headless
|
||||
options={['/profile/user', '/profile/settings', '/profile/blocks']}
|
||||
optionNames={['User', 'Settings', 'Blocks']}
|
||||
options={[
|
||||
'/profile/user',
|
||||
'/profile/settings',
|
||||
'/profile/blocks',
|
||||
'/profile/password',
|
||||
]}
|
||||
optionNames={['User', 'Settings', 'Blocks', 'Password']}
|
||||
selected={$page.url.pathname}
|
||||
on:select={(e) => {
|
||||
goto(e.detail)
|
||||
|
||||
@@ -5,43 +5,12 @@ import type { SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: 'comments' | 'posts' | 'all' =
|
||||
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New'
|
||||
|
||||
const user = await getClient(undefined, fetch).getPersonDetails({
|
||||
limit: 20,
|
||||
page: page,
|
||||
username: get(profile)!.user?.local_user_view.person.name,
|
||||
sort: sort,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
const items = [...user.posts, ...user.comments]
|
||||
|
||||
if (sort == 'TopAll') {
|
||||
items.sort(
|
||||
(a, b) =>
|
||||
b.counts.upvotes -
|
||||
b.counts.downvotes -
|
||||
(a.counts.upvotes - a.counts.downvotes)
|
||||
)
|
||||
} else if (sort == 'New') {
|
||||
items.sort(
|
||||
(a, b) =>
|
||||
Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
|
||||
)
|
||||
}
|
||||
const my_user = (await getClient().getSite({ auth: get(profile)?.jwt }))
|
||||
.my_user
|
||||
|
||||
return {
|
||||
type: type,
|
||||
page: page,
|
||||
sort: sort,
|
||||
user: {
|
||||
person_view: user.person_view,
|
||||
moderates: user.moderates,
|
||||
submissions: items,
|
||||
},
|
||||
my_user: my_user,
|
||||
community_blocks: my_user?.community_blocks,
|
||||
person_blocks: my_user?.person_blocks,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ url, fetch, parent }) {
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: 'comments' | 'posts' | 'all' =
|
||||
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New'
|
||||
|
||||
const { my_user } = await parent()
|
||||
|
||||
const user = await getClient(undefined, fetch).getPersonDetails({
|
||||
limit: 20,
|
||||
page: page,
|
||||
username: my_user?.local_user_view.person.name,
|
||||
sort: sort,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
const items = [...user.posts, ...user.comments]
|
||||
|
||||
if (sort == 'TopAll') {
|
||||
items.sort(
|
||||
(a, b) =>
|
||||
b.counts.upvotes -
|
||||
b.counts.downvotes -
|
||||
(a.counts.upvotes - a.counts.downvotes)
|
||||
)
|
||||
} else if (sort == 'New') {
|
||||
items.sort(
|
||||
(a, b) =>
|
||||
Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
type: type,
|
||||
page: page,
|
||||
sort: sort,
|
||||
user: {
|
||||
submissions: items,
|
||||
moderates: user.moderates,
|
||||
person_view: user.person_view,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
<title>Saved</title>
|
||||
</svelte:head>
|
||||
|
||||
<h1 class="text-2xl font-bold">Saved</h1>
|
||||
<h1 class="text-3xl font-bold">Saved</h1>
|
||||
<div
|
||||
class="flex flex-col list-none my-4 divide-slate-200 dark:divide-zinc-800"
|
||||
class:gap-4={$userSettings.view == 'card'}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<title>Search</title>
|
||||
</svelte:head>
|
||||
|
||||
<h1 class="font-bold text-2xl">Search</h1>
|
||||
<h1 class="font-bold text-3xl">Search</h1>
|
||||
<div class="flex flex-row flex-wrap sm:justify-between items-center gap-4 mt-4">
|
||||
<Select
|
||||
bind:value={data.type}
|
||||
|
||||
Reference in new issue
Block a user