Update email verification and password reset flows; refactor Docker Compose and enhance email management
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import { fetchCSRFToken } from '$lib/index.server';
|
||||
import type { PageServerLoad, Actions } from './$types';
|
||||
|
||||
export const load = (async ({ params }) => {
|
||||
const key = params.key;
|
||||
if (!key) {
|
||||
throw redirect(302, '/');
|
||||
}
|
||||
return { key };
|
||||
}) satisfies PageServerLoad;
|
||||
|
||||
export const actions: Actions = {
|
||||
default: async (event) => {
|
||||
const formData = await event.request.formData();
|
||||
const password = formData.get('password');
|
||||
const confirm_password = formData.get('confirm_password');
|
||||
const key = event.params.key;
|
||||
|
||||
if (!password || !confirm_password) {
|
||||
return fail(400, { message: 'both_passwords_required' });
|
||||
}
|
||||
|
||||
if (password !== confirm_password) {
|
||||
return fail(400, { message: 'passwords_not_match' });
|
||||
}
|
||||
|
||||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||
const csrfToken = await fetchCSRFToken();
|
||||
|
||||
const response = await event.fetch(
|
||||
`${serverEndpoint}/_allauth/browser/v1/auth/password/reset`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Cookie: `csrftoken=${csrfToken}`,
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ key: key, password: password })
|
||||
}
|
||||
);
|
||||
|
||||
if (response.status !== 401) {
|
||||
const error_message = await response.json();
|
||||
console.error(error_message);
|
||||
console.log(response);
|
||||
return fail(response.status, { message: 'reset_failed' });
|
||||
}
|
||||
|
||||
return redirect(302, '/login');
|
||||
}
|
||||
};
|
||||
47
frontend/src/routes/user/reset-password/[key]/+page.svelte
Normal file
47
frontend/src/routes/user/reset-password/[key]/+page.svelte
Normal file
@@ -0,0 +1,47 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { page } from '$app/stores';
|
||||
import type { PageData } from '../../../$types';
|
||||
import { t } from 'svelte-i18n';
|
||||
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<h1 class="text-center font-bold text-4xl mb-4">{$t('settings.change_password')}</h1>
|
||||
|
||||
<form method="POST" use:enhance>
|
||||
<div class="mb-4">
|
||||
<label for="password" class="block mb-2">{$t('auth.new_password')}</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
class="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="confirm_password" class="block mb-2">{$t('auth.confirm_password')}</label>
|
||||
<input
|
||||
type="password"
|
||||
id="confirm_password"
|
||||
name="confirm_password"
|
||||
required
|
||||
class="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded"
|
||||
>{$t('auth.reset_password')}</button
|
||||
>
|
||||
|
||||
{#if $page.form?.message}
|
||||
<div class="text-center text-error mt-4">
|
||||
{$page.form?.message}
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
|
||||
<svelte:head>
|
||||
<title>Password Reset Confirm</title>
|
||||
<meta name="description" content="Confirm your password reset and make a new password." />
|
||||
</svelte:head>
|
||||
Reference in New Issue
Block a user