diff options
| -rw-r--r-- | routes/email.js | 40 |
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 = { - to: "[email protected]", - from: "[email protected]", - 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 = { + to: "[email protected]", + from: "[email protected]", + 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"); + } } }; |
