aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-03-01 22:40:22 -0800
committerAdam Soltys <[email protected]>2023-03-01 22:40:22 -0800
commitb61d08c745106aa6cbdff9dcee6fe561562d84b6 (patch)
tree316ff802b478bfe811df871d54aac0ccb59dcdef
parent5b9f051af683e885cc52d0cfeba1618b670785b0 (diff)
downloadcoinos-server-b61d08c745106aa6cbdff9dcee6fe561562d84b6.tar.gz
coinos-server-b61d08c745106aa6cbdff9dcee6fe561562d84b6.zip
check captcha
-rw-r--r--routes/email.js40
1 files changed, 30 insertions, 10 deletions
diff --git a/routes/email.js b/routes/email.js
index 05f682af..9213cdd3 100644
--- a/routes/email.js
+++ b/routes/email.js
@@ -1,18 +1,38 @@
+import { bail } from "$lib/utils";
+import got from "got";
import config from "$config";
import sendgrid from "@sendgrid/mail";
export default {
async send({ body }, res) {
- sendgrid.setApiKey(config.sendgrid);
- const msg = {
- subject: body.subject || "Email Signup",
- text: JSON.stringify(body),
- html: JSON.stringify(body)
- };
+ let { token: response } = body;
+ let { recaptcha: secret } = config;
+ let { success } = await got
+ .post("https://www.google.com/recaptcha/api/siteverify", {
+ form: {
+ secret,
+ response
+ }
+ })
+ .json();
+
+ if (success) {
+ delete body.token;
+ sendgrid.setApiKey(config.sendgrid);
+ const msg = {
+ subject: body.subject || "Email Signup",
+ text: JSON.stringify(body),
+ html: JSON.stringify(body)
+ };
- await sendgrid.send(msg);
- res.send({ ok: true });
+ await sendgrid.send(msg);
+ res.send({ ok: true });
+
+ }
+ else {
+ bail(res, "failed captcha");
+ }
}
};