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 (old_password, new_password) => {
15 // coerce and/or validate
16 old_password = old_password.slice(0, 256)
17 new_password = new_password.slice(0, 256)
18 if (old_password.length < 8 || new_password.length < 8)
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)
29 if (env.signed_in_as === null)
30 throw new Problem('Unauthorized', 'Please sign in first.', 401)
34 await transaction.get({})
36 ).get(env.signed_in_as)
39 old_password !== await logjson.logjson_to_json(
40 await account.get('password')
45 `Provided old password did not match the expected value.`,
51 transaction.json_to_logjson(new_password)
54 await transaction.commit()
57 transaction.rollback()