aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-29 11:41:43 -0800
committerAdam Soltys <[email protected]>2023-11-29 11:41:50 -0800
commit8c5835fc2ca21fbe0dfd870d932253f24c995b48 (patch)
treef14721047f8faa18fe33bb9086cfc6676afbd3f1
parentada148934ee075acf41e29592c7ca39868df34eb (diff)
downloadcoinos-server-8c5835fc2ca21fbe0dfd870d932253f24c995b48.tar.gz
coinos-server-8c5835fc2ca21fbe0dfd870d932253f24c995b48.zip
mail helper
-rw-r--r--lib/mail.js33
-rw-r--r--lib/payments.js4
-rw-r--r--lib/whitelist.js1
-rw-r--r--package.json1
-rw-r--r--pnpm-lock.yaml9
-rw-r--r--routes/email.js2
-rw-r--r--routes/users.js29
-rw-r--r--templates/payments/sent.html1
8 files changed, 62 insertions, 18 deletions
diff --git a/lib/mail.js b/lib/mail.js
new file mode 100644
index 00000000..1dc72b1f
--- /dev/null
+++ b/lib/mail.js
@@ -0,0 +1,33 @@
+import config from "$config";
+import { SESClient } from "@aws-sdk/client-ses";
+import { SendEmailCommand } from "@aws-sdk/client-ses";
+import handlebars from "handlebars";
+import fs from "fs";
+import path from "path";
+
+export let templates = {
+ paymentSent: "templates/payments/sent.html"
+};
+
+export let mail = async (user, subject, template, params) => {
+ if (!user.email) return;
+
+ let source = fs.readFileSync(path.join(__dirname, template), "utf8");
+ let html = handlebars.compile(source, params);
+
+ let client = new SESClient({ region: "us-east-2" });
+ await client.send(
+ new SendEmailCommand({
+ Destination: {
+ ToAddresses: [user.email]
+ },
+ Message: {
+ Body: {
+ Html: { Charset, Data: html }
+ },
+ Subject: { Charset, Data: subject }
+ },
+ Source: config.support
+ })
+ );
+};
diff --git a/lib/payments.js b/lib/payments.js
index 098c16f7..510f24e2 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -16,6 +16,7 @@ import EventEmitter from "events";
import crc32 from "buffer-crc32";
import { mqtt1, mqtt2 } from "$lib/mqtt";
import ln from "$lib/ln";
+import { mail, templates } from "$lib/mail";
export const types = {
internal: "internal",
@@ -98,6 +99,9 @@ export let debit = async (
l("sent", type, user.username, amount);
emit(user.id, "payment", p);
+ mail(user, "Payment sent", templates.paymentSent, {
+ username: user.username
+ });
return p;
};
diff --git a/lib/whitelist.js b/lib/whitelist.js
index 8da60b7f..1d722683 100644
--- a/lib/whitelist.js
+++ b/lib/whitelist.js
@@ -20,6 +20,7 @@ export default [
"linked",
"keys",
"locktime",
+ "nip5",
"payments",
"profile",
"prompt",
diff --git a/package.json b/package.json
index 9140c0b0..5e2ebe1d 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"file-type": "^18.0.0",
"fluent-ffmpeg": "^2.1.2",
"got": "^13.0.0",
+ "handlebars": "^4.7.8",
"jsonwebtoken": "^9.0.2",
"lnurl": "^0.24.2",
"mqtt": "^5.0.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 12c7e44b..940bb30b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -56,6 +56,9 @@ dependencies:
got:
specifier: ^13.0.0
version: 13.0.0
+ handlebars:
+ specifier: ^4.7.8
+ version: 4.7.8
jsonwebtoken:
specifier: ^9.0.2
version: 9.0.2
@@ -1878,7 +1881,7 @@ packages:
dependencies:
glob: 7.2.3
graceful-fs: 4.2.10
- handlebars: 4.7.7
+ handlebars: 4.7.8
dev: false
@@ -2189,8 +2192,8 @@ packages:
resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
dev: false
- resolution: {integrity: sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==}
+ resolution: {integrity: sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==}
engines: {node: '>=0.4.7'}
hasBin: true
dependencies:
diff --git a/routes/email.js b/routes/email.js
index 14e51bcb..ac2fd721 100644
--- a/routes/email.js
+++ b/routes/email.js
@@ -2,7 +2,7 @@ import { bail } from "$lib/utils";
import got from "got";
import config from "$config";
import { l, warn } from "$lib/logging";
-import { SESClient, CloneReceiptRuleSetCommand } from "@aws-sdk/client-ses";
+import { SESClient } from "@aws-sdk/client-ses";
import { SendEmailCommand } from "@aws-sdk/client-ses";
export default {
diff --git a/routes/users.js b/routes/users.js
index 42538005..678f0748 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -9,7 +9,7 @@ import {
wait,
bail,
fail,
- getUser,
+ getUser
} from "$lib/utils";
import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";
@@ -98,7 +98,7 @@ export default {
username: key,
display: key.substr(0, 6),
pubkey: key,
- anon: true,
+ anon: true
};
}
@@ -116,7 +116,7 @@ export default {
"pubkey",
"display",
"prompt",
- "id",
+ "id"
];
if (user.pubkey)
@@ -141,7 +141,7 @@ export default {
pubkey,
password,
username,
- salt,
+ salt
};
user = await register(user, ip, false);
@@ -194,7 +194,7 @@ export default {
newpin,
username,
shopifyToken,
- shopifyStore,
+ shopifyStore
} = body;
if (user.pin && !(pin === user.pin)) throw new Error("Pin required");
@@ -228,6 +228,7 @@ export default {
"language",
"fiat",
"locktime",
+ "nip5",
"prompt",
"profile",
"pubkey",
@@ -236,7 +237,7 @@ export default {
"tokens",
"twofa",
"shopifyToken",
- "shopifyStore",
+ "shopifyStore"
];
for (let a of attributes) {
@@ -314,7 +315,7 @@ export default {
if (!subscriptions) subscriptions = [];
if (
!subscriptions.find(
- (s) => JSON.stringify(s) === JSON.stringify(subscription)
+ s => JSON.stringify(s) === JSON.stringify(subscription)
)
)
subscriptions.push(subscription);
@@ -353,19 +354,19 @@ export default {
for (let { ref } of (
await Promise.all(
- payments.reverse().map(async (id) => await g(`payment:${id}`))
+ payments.reverse().map(async id => await g(`payment:${id}`))
)
- ).filter((p) => p.type === types.internal && p.ref)) {
- let i = contacts.findIndex((c) => c && c.id === ref);
+ ).filter(p => p.type === types.internal && p.ref)) {
+ let i = contacts.findIndex(c => c && c.id === ref);
if (~i) contacts.splice(i, 1);
let u = await g(`user:${ref}`);
if (typeof u === "string") u = await g(`user:${ref}`);
- if (u) contacts.unshift(u);
- }
+ if (u) contacts.unshift(pick(u, ["id", "profile", "username"]));
+ }
await s(`${id}:contacts`, contacts);
- res.send(contacts.map((u) => pick(u, fields)));
+ res.send(contacts);
},
async del({ params: { username }, headers: { authorization } }, res) {
@@ -424,5 +425,5 @@ export default {
async superuser({ body: { username } }, res) {
if (username === config.mqtt2.username) res.send({ ok: true });
else bail(res, "unauthorized");
- },
+ }
};
diff --git a/templates/payments/sent.html b/templates/payments/sent.html
new file mode 100644
index 00000000..ae142137
--- /dev/null
+++ b/templates/payments/sent.html
@@ -0,0 +1 @@
+hello {{username}}