aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-10-17 20:15:37 +0000
committerAdam Soltys <[email protected]>2023-10-17 20:15:37 +0000
commit68cbe8c74a9dc850b225a62317d8a26cf8ac82e9 (patch)
tree1ee15e9bf61cfdf2e53c07faf954b6c79fee8c0d
parent80521340c3b85508bf17bb9055b94d65f96b91b8 (diff)
downloadcoinos-server-68cbe8c74a9dc850b225a62317d8a26cf8ac82e9.tar.gz
coinos-server-68cbe8c74a9dc850b225a62317d8a26cf8ac82e9.zip
support email in config
-rw-r--r--routes/email.js82
1 files changed, 43 insertions, 39 deletions
diff --git a/routes/email.js b/routes/email.js
index c043f0c8..1642ff71 100644
--- a/routes/email.js
+++ b/routes/email.js
@@ -7,50 +7,54 @@ import { SendEmailCommand } from "@aws-sdk/client-ses";
export default {
async send({ body }, res) {
- let { token: response } = body;
- let { recaptcha: secret } = config;
- let { success } = await got
- .post("https://www.google.com/recaptcha/api/siteverify", {
- form: {
- secret,
- response
- }
- })
- .json();
+ try {
+ 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 || body.token === config.adminpass) {
- delete body.token;
+ if (success || body.token === config.adminpass) {
+ delete body.token;
- let client = new SESClient({ region: "us-east-2" });
- await client.send(
- new SendEmailCommand({
- Destination: {
- CcAddresses: [],
- ToAddresses: ["[email protected]"]
- },
- Message: {
- Body: {
- Html: {
- Charset: "UTF-8",
- Data: JSON.stringify(body)
+ let client = new SESClient({ region: "us-east-2" });
+ await client.send(
+ new SendEmailCommand({
+ Destination: {
+ CcAddresses: [],
+ ToAddresses: [config.support],
+ },
+ Message: {
+ Body: {
+ Html: {
+ Charset: "UTF-8",
+ Data: JSON.stringify(body),
+ },
+ Text: {
+ Charset: "UTF-8",
+ Data: JSON.stringify(body),
+ },
},
- Text: {
+ Subject: {
Charset: "UTF-8",
- Data: JSON.stringify(body)
- }
+ Data: body.subject || "Support Request",
+ },
},
- Subject: {
- Charset: "UTF-8",
- Data: body.subject || "Support Request"
- }
- },
- Source: "[email protected]"
- })
- );
+ Source: config.support,
+ })
+ );
- res.send({ ok: true });
- } else {
- bail(res, "failed captcha");
+ res.send({ ok: true });
+ } else {
+ bail(res, "failed captcha");
+ }
+ } catch (e) {
+ console.log(e);
}
- }
+ },
};