From 3a27ae85e5167c0745a28061d03c7cd9c4f52230 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 6 Feb 2026 22:36:03 -0800 Subject: pass captcha when sweeping --- .../fund/[id]/sweep/[...amount]/+page.server.ts | 74 +++++++++---- .../(app)/fund/[id]/sweep/[...amount]/+page.svelte | 122 ++++++++++++++++----- 2 files changed, 148 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts index 78df3461..13ce5e9d 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -1,9 +1,9 @@ import { randomName, randomPassword } from "$lib/random"; import getRates from "$lib/rates"; -import { auth, get, post, register, sats } from "$lib/utils"; +import { auth, get, login, post, sats } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; -export async function load({ cookies, request, params, parent }) { +export async function load({ cookies, params, parent }) { let { user } = await parent(); const { id } = params; let [amount, currency] = params.amount.split("/"); @@ -21,31 +21,59 @@ export async function load({ cookies, request, params, parent }) { amount = Math.round((amount * sats) / rate); } - const username = randomName() + Math.floor(Math.random() * 99) + 1; - const password = randomPassword(); - if (!amount) redirect(307, `/fund/${id}`); - if (!user) { + + if (user) { + try { + ({ amount } = await post("/take", { amount, id }, auth(cookies))); + } catch (e) { + redirect(307, `/fund/${id}`); + } + + return { amount, currency, id, rate, rates, password: null }; + } + + return { amount, currency, id, rate, rates, needsCaptcha: true }; +} + +export const actions = { + default: async ({ cookies, request, params }) => { + const { id } = params; + const form = await request.formData(); + const recaptcha = form.get("recaptcha") as string; + const amount = Number(form.get("amount")); const ip = request.headers.get("cf-connecting-ip"); + const host = request.headers.get("host"); - user = { - username, - password, - fresh: true, - }; + const username = randomName() + Math.floor(Math.random() * 99) + 1; + const password = randomPassword(); - let redirectUrl = `/fund/${id}/sweep`; - if (params.amount && !params.currency) redirectUrl += `/${params.amount}`; - if (params.currency) redirectUrl += `/${params.amount}/params.currency}`; + const user = { username, password, fresh: true, recaptcha }; - await register(user, ip, cookies, redirectUrl); - } + const { sk } = await post( + "/register", + { user }, + { "cf-connecting-ip": ip }, + ); - try { - ({ amount } = await post("/take", { amount, id }, auth(cookies))); - } catch (e) { - redirect(307, `/fund/${id}`); - } + await login(user, cookies, ip, host); - return { amount, currency, id, rate, rates, password }; -} + const expires = new Date(); + expires.setSeconds(expires.getSeconds() + 21000000); + cookies.set("sk", sk, { + path: "/", + expires, + httpOnly: false, + sameSite: "lax", + }); + + let swept; + try { + swept = await post("/take", { amount, id }, auth(cookies)); + } catch (e) { + redirect(307, `/fund/${id}`); + } + + return { amount: swept.amount, password, username }; + }, +}; diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte index 7a7d5402..fbe8e6ca 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte @@ -1,36 +1,108 @@ -
- -
- - -
-
- -
- {$t("payments.tapAnywhere")} -
+{#if loading} +
+ +
+ +{:else if swept} +
+ +
+ + +
+
+ +
+ {$t("payments.tapAnywhere")} +
+{/if} -- cgit v1.2.3