1 let crypto = require('crypto')
2 let jst_server = (await import('@ndcode/jst_server')).default
3 let XDate = require('xdate')
6 let get_account = await _require('/_lib/get_account.jst')
7 let get_session = await _require('/_lib/get_session.jst')
8 let post_request = await _require('/_lib/post_request.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)
19 throw new jst_server.Problem(
21 'Minimum length check failed',
25 let transaction = await env.site.database.Transaction()
27 let root = await transaction.get({})
28 let session = await get_session(env, root)
30 let account = await get_account(root, session)
31 if (account === undefined)
32 throw new jst_server.Problem(
34 'Please sign in first.',
38 if (old_password !== await account.get_json('password'))
39 throw new jst_server.Problem(
41 `Provided old password did not match the expected value.`,
45 account.set_json('password', new_password)
46 await transaction.commit()
49 transaction.rollback()