1 let crypto = require('crypto')
2 let logjson = (await import('@ndcode/logjson')).default
3 let XDate = require('xdate')
6 let post_request = await _require('/_lib/post_request.jst')
7 let session_cookie = await _require('/_lib/session_cookie.jst')
8 let Problem = await _require('/_lib/Problem.jst')
14 async (email, link_code) => {
15 // coerce and/or validate
16 email = email.slice(0, 256).toLowerCase()
17 link_code = link_code.slice(0, 256).toLowerCase()
18 if (email.length === 0 || link_code.length < 32)
21 'Minimum length check failed',
25 let transaction = await env.site.database.Transaction()
27 // initialize env.session_key, set cookie in env.response
28 await session_cookie(env, transaction)
32 await transaction.get({})
35 if (account === undefined)
37 'Account does not exist',
38 `Please create the account for "${email}" before attempting to verify the password reset link.`
42 let verify_password = await account.get('verify_password')
44 verify_password === undefined ||
45 XDate.now() >= await logjson.logjson_to_json(
46 await verify_password.get('expires')
51 `Password reset link code for account "${email}" does not exist or has expired.`,
55 link_code !== await logjson.logjson_to_json(
56 await verify_password.get('link_code')
61 `Provided password reset link code "${link_code}" does not match expected value.`,
65 await account.delete('verify_password')
66 await account.set('password', await verify_password.get('password'))
68 await transaction.commit()
71 transaction.rollback()