From ac18b73c073957098374cdeeeee48b02acd007a3 Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Wed, 3 Jun 2026 21:56:35 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20email=20field=20in=20settings=20?= =?UTF-8?q?=E2=80=94=20lets=20users=20set=20address=20for=20self-service?= =?UTF-8?q?=20password=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/src/pages/settings/index.astro | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/site/src/pages/settings/index.astro b/site/src/pages/settings/index.astro index 677180b..54452b1 100644 --- a/site/src/pages/settings/index.astro +++ b/site/src/pages/settings/index.astro @@ -51,6 +51,25 @@ import Base from '../../layouts/Base.astro'; + +
+

Email

+

Used to receive a reset link when you forget your password.

+
+
+ + +
+ +
+ +
+

Password

@@ -602,10 +621,48 @@ import Base from '../../layouts/Base.astro'; } }); + // ── Email ───────────────────────────────────────────────────────────────────── + + const emailForm = document.getElementById('email-form') as HTMLFormElement; + const emailInput = document.getElementById('email-input') as HTMLInputElement; + const emailStatus = document.getElementById('email-status') as HTMLElement; + + async function loadEmail() { + const authUrl: string = (window as any).__bincioAuthUrl ?? ''; + if (!authUrl) return; // single-user / no bincio-auth + try { + const r = await fetch(`${authUrl}/api/me/email`, { credentials: 'include' }); + if (r.ok) { + const { email } = await r.json(); + if (email) emailInput.value = email; + } + } catch { /* ignore */ } + } + + emailForm.addEventListener('submit', async e => { + e.preventDefault(); + const authUrl: string = (window as any).__bincioAuthUrl ?? ''; + if (!authUrl) { setStatus(emailStatus, 'Not available on this instance.', false); return; } + const email = emailInput.value.trim(); + try { + const r = await fetch(`${authUrl}/api/me/email`, { + method: 'POST', + credentials: 'include', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ email }), + }); + const d = await r.json().catch(() => ({})); + setStatus(emailStatus, r.ok ? 'Saved.' : (d.detail ?? 'Failed.'), r.ok); + } catch { + setStatus(emailStatus, 'Could not reach server.', false); + } + }); + // ── Init ───────────────────────────────────────────────────────────────────── loadMe(); loadStorage(); + loadEmail(); loadNavPrefs(); loadActivityDefaults(); loadStravaCreds();