Move account-related APIs down one level into /api/account and the former /api/sign_u...
[ndcode_site.git] / api / account / sign_up / send_email_verification_link.json.jst
@@ -14,8 +14,6 @@ return async env => {
   await post_request(
     // env
     env,
-    // endpoint
-    '/api/sign_up/send_verification_email.json',
     // handler
     async email => {
       // coerce and/or validate
@@ -40,10 +38,21 @@ return async env => {
         if (account === undefined)
           throw new Problem(
             'Account does not exist',
-            `Please create the account for "${email}" before attempting to send a email verification link.`
+            `Please create the account for "${email}" before attempting to send an email verification link.`
             421
           )
 
+        if (
+          await logjson.logjson_to_json(
+            await account.get('email_verified')
+          )
+        )
+          throw new Problem(
+            'Email already verified',
+            `Your email "${email}" is already verified. You can now sign in.`
+            422
+          )
+
         let link_code = crypto.randomBytes(16).toString('hex')
         let expires = new XDate()
         expires.addDays(1)