1 let logjson = (await import('@ndcode/logjson')).default
4 let globals = await env.site.get_json('/_config/globals.json')
5 let nodemailer_noreply = await env.site.get_nodemailer(
6 '/_config/nodemailer_noreply.json'
8 let post_request = await _require('/_lib/post_request.jst')
9 let session_cookie = await _require('/_lib/session_cookie.jst')
10 let Problem = await _require('/_lib/Problem.jst')
16 async (email, password) => {
17 // coerce and/or validate
18 email = email.slice(0, 256).toLowerCase()
19 password = password.slice(0, 256)
20 if (email.length === 0 || password.length < 8)
23 'Minimum length check failed',
27 let transaction = await env.site.database.Transaction()
29 // initialize env.session_key, set cookie in env.response
30 let session = await session_cookie(env, transaction)
34 await transaction.get({})
38 account === undefined ||
39 password !== await logjson.logjson_to_json(
40 await account.get('password')
45 'Email and password combination was incorrect.'
50 !await logjson.logjson_to_json(
51 await account.get('email_verified')
55 'Email not yet verified',
56 'Please verify your email address via email link before trying to sign in.',
60 session.set('signed_in_as', transaction.json_to_logjson(email))
62 await transaction.commit()
65 transaction.rollback()