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) {