diff options
| author | Adam Soltys <[email protected]> | 2023-03-01 22:40:22 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-01 22:40:22 -0800 |
| commit | b61d08c745106aa6cbdff9dcee6fe561562d84b6 (patch) | |
| tree | 316ff802b478bfe811df871d54aac0ccb59dcdef /routes | |
| parent | 5b9f051af683e885cc52d0cfeba1618b670785b0 (diff) | |
| download | coinos-server-b61d08c745106aa6cbdff9dcee6fe561562d84b6.tar.gz coinos-server-b61d08c745106aa6cbdff9dcee6fe561562d84b6.zip | |
check captcha
Diffstat (limited to 'routes')
| -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"); + } } }; |
