add update password

This commit is contained in:
saml33 2021-12-21 13:37:10 +11:00
parent 69fae81306
commit 5e457a58c6
3 changed files with 22 additions and 4 deletions

View File

@ -13,4 +13,5 @@ export default {
mailUser: process.env.MAIL_USER || "",
mailJetKey: process.env.MAILJET_KEY || "",
mailJetSecret: process.env.MAILJET_SECRET || "",
updatePassword: process.env.UPDATE_PASSWORD,
}

View File

@ -15,7 +15,12 @@ import {
import { Commitment, Connection, PublicKey } from "@solana/web3.js"
import { UserError } from "./errors"
import { validateMangoAccount, validateEmail, sendAlert } from "./utils"
import {
validateMangoAccount,
validateEmail,
sendAlert,
validateUpdatePassword,
} from "./utils"
import config from "./environment"
const MESSAGE = "Your health ratio is at or below @ratio@% \n"
@ -129,15 +134,13 @@ router.get("/alerts/:mangoAccountPk", async (ctx, next) => {
router.post("/updates", async (ctx, next) => {
try {
const update: any = ctx.request.body
await validateUpdatePassword(update.password)
ctx.body = { status: "success" }
ctx.db.collection("updates").insertOne(update)
} catch (e: any) {
let errorMessage = "Something went wrong"
if (e.name == "UserError") {
errorMessage = e.message
} else {
// sendLogsToDiscord(null, e)
}
ctx.throw(400, errorMessage)
}

View File

@ -31,6 +31,20 @@ export const validateMangoAccount = (client: MangoClient, alert: any) => {
})
}
export const validateUpdatePassword = (password: string) => {
return new Promise<void>(async (resolve, reject) => {
try {
if (password != config.updatePassword) {
reject(new UserError("Invalid password"))
} else {
resolve()
}
} catch (e) {
reject(new UserError("Something went wrong"))
}
})
}
export const validateEmail = (email: string) => {
if (!EmailValidator.validate(email)) {
throw new UserError("Enter a valid email")