1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-05 05:05:17 +02:00

feat: add public URL endpoint and update user type to include password status

This commit is contained in:
Sean Morley 2025-01-06 18:53:08 -05:00
parent 59b41c01df
commit e19781d7ac
15 changed files with 248 additions and 51 deletions

View file

@ -15,6 +15,7 @@ declare global {
profile_pic: string | null;
uuid: string;
public_profile: boolean;
has_password: boolean;
} | null;
locale: string;
}

View file

@ -30,8 +30,9 @@
<!-- svelte-ignore a11y-missing-attribute -->
<!-- svelte-ignore a11y-missing-attribute -->
<p class="text-lg ml-4 font-bold">
{$t('navbar.greeting')}, {user.first_name}
{user.last_name}
{$t('navbar.greeting')}, {user.first_name
? `${user.first_name} ${user.last_name}`
: user.username}
</p>
<li><button on:click={() => goto('/profile')}>{$t('navbar.profile')}</button></li>
<li><button on:click={() => goto('/adventures')}>{$t('navbar.my_adventures')}</button></li>

View file

@ -9,6 +9,7 @@ export type User = {
profile_pic: string | null;
uuid: string;
public_profile: boolean;
has_password: boolean;
};
export type Adventure = {

View file

@ -17,7 +17,11 @@
<div class="container mx-auto p-4">
<!-- Welcome Message -->
<div class="mb-8">
<h1 class="text-4xl font-extrabold">{$t('dashboard.welcome_back')}, {user?.first_name}!</h1>
<h1 class="text-4xl font-extrabold">
{$t('dashboard.welcome_back')}, {user?.first_name
? `${user.first_name} ${user.last_name}`
: user?.username}!
</h1>
</div>
<!-- Stats -->

View file

@ -66,12 +66,22 @@ export const load: PageServerLoad = async (event) => {
immichIntegration = await immichIntegrationsFetch.json();
}
let publicUrlFetch = await fetch(`${endpoint}/public-url/`);
let publicUrl = '';
if (!publicUrlFetch.ok) {
return redirect(302, '/');
} else {
let publicUrlJson = await publicUrlFetch.json();
publicUrl = publicUrlJson.PUBLIC_URL;
}
return {
props: {
user,
emails,
authenticators,
immichIntegration
immichIntegration,
publicUrl
}
};
};
@ -179,33 +189,52 @@ export const actions: Actions = {
const password1 = formData.get('password1') as string | null | undefined;
const password2 = formData.get('password2') as string | null | undefined;
const current_password = formData.get('current_password') as string | null | undefined;
let current_password = formData.get('current_password') as string | null | undefined;
if (password1 !== password2) {
return fail(400, { message: 'settings.password_does_not_match' });
}
if (!current_password) {
return fail(400, { message: 'settings.password_is_required' });
current_password = null;
}
let csrfToken = await fetchCSRFToken();
let res = await fetch(`${endpoint}/_allauth/browser/v1/account/password/change`, {
method: 'POST',
headers: {
Cookie: `sessionid=${sessionId}; csrftoken=${csrfToken}`,
'X-CSRFToken': csrfToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
current_password,
new_password: password1
})
});
if (!res.ok) {
return fail(res.status, { message: 'settings.error_change_password' });
if (current_password) {
let res = await fetch(`${endpoint}/_allauth/browser/v1/account/password/change`, {
method: 'POST',
headers: {
Cookie: `sessionid=${sessionId}; csrftoken=${csrfToken}`,
'X-CSRFToken': csrfToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
current_password,
new_password: password1
})
});
if (!res.ok) {
return fail(res.status, { message: 'settings.error_change_password' });
}
return { success: true };
} else {
let res = await fetch(`${endpoint}/_allauth/browser/v1/account/password/change`, {
method: 'POST',
headers: {
Cookie: `sessionid=${sessionId}; csrftoken=${csrfToken}`,
'X-CSRFToken': csrfToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
new_password: password1
})
});
if (!res.ok) {
console.log('Error:', await res.json());
return fail(res.status, { message: 'settings.error_change_password' });
}
return { success: true };
}
return { success: true };
},
changeEmail: async (event) => {
if (!event.locals.user) {

View file

@ -9,6 +9,7 @@
import TotpModal from '$lib/components/TOTPModal.svelte';
import { appTitle, appVersion } from '$lib/config.js';
import ImmichLogo from '$lib/assets/immich.svg';
import { goto } from '$app/navigation';
export let data;
console.log(data);
@ -20,7 +21,7 @@
}
let new_email: string = '';
let public_url: string = data.props.publicUrl;
let immichIntegration = data.props.immichIntegration;
let newImmichIntegration: ImmichIntegration = {
@ -307,17 +308,19 @@
</h2>
<div class="bg-neutral p-6 rounded-lg shadow-md">
<form method="post" action="?/changePassword" use:enhance class="space-y-6">
<div>
<label for="current_password" class="text-sm font-medium text-neutral-content"
>{$t('settings.current_password')}</label
>
<input
type="password"
id="current_password"
name="current_password"
class="block w-full mt-1 input input-bordered input-primary"
/>
</div>
{#if user.has_password}
<div>
<label for="current_password" class="text-sm font-medium text-neutral-content"
>{$t('settings.current_password')}</label
>
<input
type="password"
id="current_password"
name="current_password"
class="block w-full mt-1 input input-bordered input-primary"
/>
</div>
{/if}
<div>
<label for="password1" class="text-sm font-medium text-neutral-content"
@ -424,6 +427,58 @@
</div>
</section>
<!-- Admin Settings -->
{#if user.is_staff}
<section class="space-y-8">
<h2 class="text-2xl font-semibold text-center mt-8">Administration Settings</h2>
<div class="bg-neutral p-6 rounded-lg shadow-md text-center">
<a class="btn btn-primary mt-4" href={`${public_url}/admin/`} target="_blank"
>Launch Administration Pannel</a
>
</div>
</section>
{/if}
<!-- Social Auth Settings -->
<section class="space-y-8">
<h2 class="text-2xl font-semibold text-center mt-8">Social and ODIC Authentication</h2>
<div class="bg-neutral p-6 rounded-lg shadow-md text-center">
<p>
Enable or disable social and OIDC authentication providers for your account. These
connections allow you to sign in with self hosted authentication identity providers like
Authentik or 3rd party providers like GitHub.
</p>
<div role="alert" class="alert alert-info mt-2">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
class="h-6 w-6 shrink-0 stroke-current"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
></path>
</svg>
<span
>These settings are managed in the AdventureLog server and must be manually enabled by the
administrator. <a
href="https://adventurelog.app/docs/configuration/social_auth.html"
class="link link-neutral"
target="_blank">Documentation Link</a
>.
</span>
</div>
<a
class="btn btn-primary mt-4"
href={`${public_url}/accounts/social/connections/`}
target="_blank">Launch Account Connections</a
>
</div>
</section>
<!-- Immich Integration Section -->
<section class="space-y-8">
<h2 class="text-2xl font-semibold text-center mt-8">