Use jst_server.Problem everywhere, make /_lib/post_request.jst use jst_server's new...
[ndcode_site.git] / api / account / sign_up / create_account.json.jst
index 2685f30..2eb3efe 100644 (file)
@@ -1,9 +1,9 @@
+let jst_server = (await import('@ndcode/jst_server')).default
 let XDate = require('xdate')
 
 return async env => {
   let post_request = await _require('/_lib/post_request.jst')
   let get_session = await _require('/_lib/get_session.jst')
-  let Problem = await _require('/_lib/Problem.jst')
 
   await post_request(
     // env
@@ -24,7 +24,7 @@ return async env => {
           details.given_names.length === 0 ||
           details.password.length < 8
       )
-        throw new Problem(
+        throw new jst_server.Problem(
           'Bad request',
           'Minimum length check failed',
           400
@@ -40,7 +40,7 @@ return async env => {
           captcha === undefined ||
             XDate.now() >= await captcha.get_json('expires')
         )
-          throw new Problem(
+          throw new jst_server.Problem(
             'No verification image in session',
             `Please call the "/api/verification_image.png" endpoint to create a verification image, in same session as the "/api/account/sign_up/create_account.json" call and less than one hour prior.`,
             418
@@ -50,7 +50,7 @@ return async env => {
         if (verification_code !== captcha_text) {
           console.log(`verification code mismatch, \"${verification_code}\" should be \"${captcha_text}\"`)
 
-          throw new Problem(
+          throw new jst_server.Problem(
             'Verification code mismatch',
             `The provided verification code "${verification_code}" did not match the verification image.`,
             419
@@ -59,7 +59,7 @@ return async env => {
 
         let accounts = await root.get('accounts', {})
         if (accounts.has(details.email))
-          throw new Problem(
+          throw new jst_server.Problem(
             'Account already exists',
             `The email "${details.email}" already has an account registered.`,
             420