2 let post_request = await _require('/_lib/post_request.jst')
3 let get_session = await _require('/_lib/get_session.jst')
4 let Problem = await _require('/_lib/Problem.jst')
10 async (email, password) => {
11 // coerce and/or validate
12 email = email.slice(0, 256).toLowerCase()
13 password = password.slice(0, 256)
14 if (email.length === 0 || password.length < 8)
17 'Minimum length check failed',
21 let transaction = await env.site.database.Transaction()
23 let root = await transaction.get({})
25 let accounts = await root.get('accounts', {})
26 let account = await accounts.get(email)
28 account === undefined ||
29 password !== await account.get_json('password')
33 'Email and password combination was incorrect.'
37 if (!await account.get_json('email_verified'))
39 'Email not yet verified',
40 'Please verify your email address via email link before trying to sign in.',
44 let session = await get_session(env, root)
45 session.set_json('signed_in_as', email)
46 await transaction.commit()
49 transaction.rollback()