From b8e7de704694bbcbdd58338704832e50c216dcdc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 22 Mar 2023 15:53:35 +0000 Subject: catch update errors --- lib/register.js | 4 ++-- routes/email.js | 23 ++++++++++++----------- routes/users.js | 7 ++++++- watcher.sh | 15 ++++++++------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lib/register.js b/lib/register.js index ccf6d902..92df8615 100644 --- a/lib/register.js +++ b/lib/register.js @@ -54,9 +54,9 @@ export default async (user, ip, requireChallenge) => { } await s(`user:${id}`, user); - await s(`user:${user.username.toLowerCase()}`, id); + await s(`user:${username}`, id); await s(`user:${pubkey}`, id); - l("new user", user.username); + l("new user", username); return user; }; diff --git a/routes/email.js b/routes/email.js index 1f7ce4a0..ba590d4c 100644 --- a/routes/email.js +++ b/routes/email.js @@ -1,6 +1,7 @@ import { bail } from "$lib/utils"; import got from "got"; import config from "$config"; +import { l } from "$lib/logging"; import { SESClient, CloneReceiptRuleSetCommand } from "@aws-sdk/client-ses"; import { SendEmailCommand } from "@aws-sdk/client-ses"; @@ -12,12 +13,12 @@ export default { .post("https://www.google.com/recaptcha/api/siteverify", { form: { secret, - response - } + response, + }, }) .json(); - if (success) { + if (success || body.token === config.adminpass) { delete body.token; let client = new SESClient({ region: "us-east-2" }); @@ -25,25 +26,25 @@ export default { new SendEmailCommand({ Destination: { CcAddresses: [], - ToAddresses: ["support@coinos.io"] + ToAddresses: ["support@coinos.io"], }, Message: { Body: { Html: { Charset: "UTF-8", - Data: JSON.stringify(body) + Data: JSON.stringify(body), }, Text: { Charset: "UTF-8", - Data: JSON.stringify(body) - } + Data: JSON.stringify(body), + }, }, Subject: { Charset: "UTF-8", - Data: body.subject || "Email Signup" - } + Data: body.subject || "Support Request", + }, }, - Source: "support@coinos.io" + Source: "support@coinos.io", }) ); @@ -51,5 +52,5 @@ export default { } else { bail(res, "failed captcha"); } - } + }, }; diff --git a/routes/users.js b/routes/users.js index 89a04004..aafeeaf2 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,7 +1,7 @@ import { g, s, db } from "$lib/db"; import config from "$config"; import store from "$lib/store"; -import { fields, nada, pick, uniq, wait, fail } from "$lib/utils"; + import { fields, nada, pick, uniq, wait, bail, fail } from "$lib/utils"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; import { authenticator } from "otplib"; @@ -165,6 +165,7 @@ export default { }, async update({ user, body }, res) { + try { l("updating user", user.username); let { confirm, password, pin, newpin, username } = body; @@ -218,6 +219,10 @@ export default { emit(user.id, "user", user); res.send({ user, token }); + } catch(e) { + warn("failed to update", user.username, e.message); + bail(res, e.message); + } }, async login(req, res) { diff --git a/watcher.sh b/watcher.sh index 6de246fb..b12ee1cb 100755 --- a/watcher.sh +++ b/watcher.sh @@ -12,11 +12,12 @@ do accts=$(curl -s https://coinos.io/api/balances | jr '.total') gap=$(node -pe "$accts - $total") echo $(date -Is) lnc $lnc lnw $lnw bc $bc tot $total gap $gap - # low=$(node -pe "!!($gap > $threshold)") - # if "$low"; then - # echo "Threshold hit, setting new threshold" - # pnpm pm2 stop 0 > /dev/null - # node /root/mailgun/index.js - # fi - sleep 60 + low=$(node -pe "!!($gap > $threshold)") + + if "$low"; then + echo "Threshold hit, setting new threshold" + docker stop app; + curl localhost:3119/email -H "content-type: application/json" -d '{"token": "MPJzfq97ab!!!!", "message": "threshold hit"}' + fi + sleep 120 done -- cgit v1.2.3