Use jst_server.Problem everywhere, make /_lib/post_request.jst use jst_server's new...
[ndcode_site.git] / api / account / change_password.json.jst
index 6c06323..2bba98a 100644 (file)
@@ -1,11 +1,11 @@
 let crypto = require('crypto')
+let jst_server = (await import('@ndcode/jst_server')).default
 let XDate = require('xdate')
 
 return async env => {
   let get_account = await _require('/_lib/get_account.jst')
   let get_session = await _require('/_lib/get_session.jst')
   let post_request = await _require('/_lib/post_request.jst')
-  let Problem = await _require('/_lib/Problem.jst')
 
   await post_request(
     // env
@@ -16,7 +16,7 @@ return async env => {
       old_password = old_password.slice(0, 256)
       new_password = new_password.slice(0, 256)
       if (old_password.length < 8 || new_password.length < 8)
-        throw new Problem(
+        throw new jst_server.Problem(
           'Bad request',
           'Minimum length check failed',
           400
@@ -29,10 +29,14 @@ return async env => {
 
         let account = await get_account(root, session)
         if (account === undefined)
-          throw new Problem('Unauthorized', 'Please sign in first.', 401)
+          throw new jst_server.Problem(
+            'Unauthorized',
+            'Please sign in first.',
+            401
+          )
 
         if (old_password !== await account.get_json('password'))
-          throw new Problem(
+          throw new jst_server.Problem(
             'Incorrect password',
             `Provided old password did not match the expected value.`,
             426