From 7cb3a8db191a0d67b6caccd0aabda15a35015058 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 6 Feb 2026 22:52:09 -0800 Subject: skip captcha for funds --- .../fund/[id]/sweep/[...amount]/+page.server.ts | 77 +++++-------- .../(app)/fund/[id]/sweep/[...amount]/+page.svelte | 122 +++++---------------- 2 files changed, 52 insertions(+), 147 deletions(-) (limited to 'src/routes/(app)') 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 13ce5e9d..8cc463c2 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,10 @@ import { randomName, randomPassword } from "$lib/random"; import getRates from "$lib/rates"; -import { auth, get, login, post, sats } from "$lib/utils"; +import { auth, get, post, register, sats } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; +import { env } from "$env/dynamic/private"; -export async function load({ cookies, params, parent }) { +export async function load({ cookies, request, params, parent }) { let { user } = await parent(); const { id } = params; let [amount, currency] = params.amount.split("/"); @@ -21,59 +22,35 @@ export async function load({ cookies, params, parent }) { amount = Math.round((amount * sats) / rate); } - if (!amount) redirect(307, `/fund/${id}`); - - 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 }; -} + const username = randomName() + Math.floor(Math.random() * 99) + 1; + const password = randomPassword(); -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")); + if (!amount) redirect(307, `/fund/${id}`); + if (!user) { const ip = request.headers.get("cf-connecting-ip"); - const host = request.headers.get("host"); - - const username = randomName() + Math.floor(Math.random() * 99) + 1; - const password = randomPassword(); - const user = { username, password, fresh: true, recaptcha }; + user = { + username, + password, + fresh: true, + }; - const { sk } = await post( - "/register", - { user }, - { "cf-connecting-ip": ip }, - ); + let redirectUrl = `/fund/${id}/sweep`; + if (params.amount && !params.currency) redirectUrl += `/${params.amount}`; + if (params.currency) redirectUrl += `/${params.amount}/params.currency}`; - await login(user, cookies, ip, host); + const extraHeaders: Record = {}; + if (env.INTERNAL_API_KEY) + extraHeaders["x-api-key"] = env.INTERNAL_API_KEY; - const expires = new Date(); - expires.setSeconds(expires.getSeconds() + 21000000); - cookies.set("sk", sk, { - path: "/", - expires, - httpOnly: false, - sameSite: "lax", - }); + await register(user, ip, cookies, redirectUrl, undefined, extraHeaders); + } - let swept; - try { - swept = await post("/take", { amount, id }, auth(cookies)); - } catch (e) { - redirect(307, `/fund/${id}`); - } + try { + ({ amount } = await post("/take", { amount, id }, auth(cookies))); + } catch (e) { + redirect(307, `/fund/${id}`); + } - return { amount: swept.amount, password, username }; - }, -}; + return { amount, currency, id, rate, rates, password }; +} diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte index fbe8e6ca..7a7d5402 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte @@ -1,108 +1,36 @@ -{#if loading} -
- -
- -{:else if swept} -
- -
- - -
-
- -
- {$t("payments.tapAnywhere")} -
-{/if} +
+ +
+ + +
+
+ +
+ {$t("payments.tapAnywhere")} +
-- cgit v1.2.3