From ca4ceecd1baeb6d4608d4d21c2db0c8f66e57f56 Mon Sep 17 00:00:00 2001 From: 0x73746F66 Date: Wed, 12 Jun 2024 00:06:15 +1000 Subject: [PATCH] feat: login D1 Signed-off-by: 0x73746F66 --- functions/login/[email]/[hash].js | 10 +++++++--- functions/register/[org]/[email]/[hash].js | 12 +++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/functions/login/[email]/[hash].js b/functions/login/[email]/[hash].js index 410def1..925e09c 100644 --- a/functions/login/[email]/[hash].js +++ b/functions/login/[email]/[hash].js @@ -4,10 +4,14 @@ export const onRequestGet = async context => { context.params?.hash ) { console.log('email', context.params.email) - - + const { results } = await context.env.d1db.prepare( + "SELECT * FROM members WHERE email = ?" + ) + .bind(context.params.email) + .all() + return Response.json(results) } - return new Response.json({ 'err': 'OAuth authorization code not provided' }) + return new Response.json({ 'err': 'Authentication' }) } async function pbkdf2Verify(key, password, hashBits = 512) { diff --git a/functions/register/[org]/[email]/[hash].js b/functions/register/[org]/[email]/[hash].js index ae8a2ed..c1765f2 100644 --- a/functions/register/[org]/[email]/[hash].js +++ b/functions/register/[org]/[email]/[hash].js @@ -6,14 +6,12 @@ export const onRequestGet = async context => { ) { console.log('org', context.params.org) // const kid = crypto.randomUUID() - const { results } = await context.env.trivial_triage.prepare( - "SELECT * FROM members WHERE email = ?" - ) - .bind(context.params.email) - .all() - return Response.json(results) + const info = await db.prepare('INSERT INTO members (orgName, email, passwordhash) VALUES (?1, ?2, ?3)') + .bind(context.params.org, context.params.email, pbkdf2(context.params.hash)) + .run() + return Response.json(info) } - return new Response.json({ 'err': 'OAuth authorization code not provided' }) + return new Response.json({ 'err': 'missing properties /register/[org]/[email]/[sha1]' }) } async function pbkdf2(password, iterations = 1e6, hashBits = 512) {