1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-31 10:49:37 +02:00

email change

This commit is contained in:
Sean Morley 2024-07-09 11:39:07 -04:00
parent 2ff47cbaf3
commit 933173883a
2 changed files with 52 additions and 0 deletions

View file

@ -139,5 +139,33 @@ export const actions: Actions = {
return fail(res.status, await res.json()); return fail(res.status, await res.json());
} }
return { success: true }; return { success: true };
},
changeEmail: async (event) => {
if (!event.locals.user) {
return redirect(302, '/');
}
if (!event.cookies.get('auth')) {
return redirect(302, '/');
}
const formData = await event.request.formData();
const new_email = formData.get('new_email') as string | null | undefined;
if (!new_email) {
return fail(400, { message: 'Email is required' });
} else {
let res = await fetch(`${endpoint}/auth/change-email/`, {
method: 'POST',
headers: {
Cookie: event.cookies.get('auth') || '',
'Content-Type': 'application/json'
},
body: JSON.stringify({
new_email
})
});
if (!res.ok) {
return fail(res.status, await res.json());
}
return { success: true };
}
} }
}; };

View file

@ -118,6 +118,30 @@
</form> </form>
</div> </div>
<h1 class="text-center font-extrabold text-xl mt-4 mb-2">Email Change</h1>
<div class="flex justify-center">
<form action="?/changeEmail" method="post" class="w-full max-w-xs">
<label for="current_email">Current Email</label>
<input
type="email"
name="current_email"
placeholder={user.email || 'No Email Set'}
id="current_email"
readonly
class="block mb-2 input input-bordered w-full max-w-xs"
/>
<br />
<input
type="email"
name="new_email"
placeholder="New Email"
id="new_email"
class="block mb-2 input input-bordered w-full max-w-xs"
/>
<button class="py-2 px-4 btn btn-primary mt-2">Change Email</button>
</form>
</div>
<small class="text-center" <small class="text-center"
><b>For Debug Use:</b> Server PK={user.pk} | Date Joined: {user.date_joined ><b>For Debug Use:</b> Server PK={user.pk} | Date Joined: {user.date_joined
? new Date(user.date_joined).toDateString() ? new Date(user.date_joined).toDateString()