migration to new backend
This commit is contained in:
30
frontend/src/routes/settings/forgot-password/+page.server.ts
Normal file
30
frontend/src/routes/settings/forgot-password/+page.server.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { fail, type Actions } from '@sveltejs/kit';
|
||||
|
||||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||
|
||||
export const actions: Actions = {
|
||||
forgotPassword: async (event) => {
|
||||
const formData = await event.request.formData();
|
||||
|
||||
const email = formData.get('email') as string | null | undefined;
|
||||
|
||||
if (!email) {
|
||||
return fail(400, { message: 'Email is required' });
|
||||
}
|
||||
|
||||
let res = await fetch(`${endpoint}/auth/password/reset/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email
|
||||
})
|
||||
});
|
||||
if (!res.ok) {
|
||||
return fail(res.status, { message: await res.json() });
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
30
frontend/src/routes/settings/forgot-password/+page.svelte
Normal file
30
frontend/src/routes/settings/forgot-password/+page.svelte
Normal file
@@ -0,0 +1,30 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { page } from '$app/stores';
|
||||
</script>
|
||||
|
||||
<h1 class="text-center font-extrabold text-4xl mb-6">Reset Password</h1>
|
||||
|
||||
<div class="flex justify-center">
|
||||
<form method="post" action="?/forgotPassword" class="w-full max-w-xs">
|
||||
<label for="email">Email</label>
|
||||
<input
|
||||
name="email"
|
||||
type="email"
|
||||
id="email"
|
||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||
/><br />
|
||||
<button class="py-2 px-4 btn btn-primary mr-2">Reset Password</button>
|
||||
{#if $page.form?.message}
|
||||
<div class="text-center text-error mt-4">
|
||||
{$page.form?.message}
|
||||
</div>
|
||||
{/if}
|
||||
{#if $page.form?.success}
|
||||
<div class="text-center text-success mt-4">
|
||||
If the email address you provided is associated with an account, you will receive an email
|
||||
with instructions to reset your password!
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user