add update password
This commit is contained in:
parent
69fae81306
commit
5e457a58c6
|
@ -13,4 +13,5 @@ export default {
|
||||||
mailUser: process.env.MAIL_USER || "",
|
mailUser: process.env.MAIL_USER || "",
|
||||||
mailJetKey: process.env.MAILJET_KEY || "",
|
mailJetKey: process.env.MAILJET_KEY || "",
|
||||||
mailJetSecret: process.env.MAILJET_SECRET || "",
|
mailJetSecret: process.env.MAILJET_SECRET || "",
|
||||||
|
updatePassword: process.env.UPDATE_PASSWORD,
|
||||||
}
|
}
|
||||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -15,7 +15,12 @@ import {
|
||||||
import { Commitment, Connection, PublicKey } from "@solana/web3.js"
|
import { Commitment, Connection, PublicKey } from "@solana/web3.js"
|
||||||
|
|
||||||
import { UserError } from "./errors"
|
import { UserError } from "./errors"
|
||||||
import { validateMangoAccount, validateEmail, sendAlert } from "./utils"
|
import {
|
||||||
|
validateMangoAccount,
|
||||||
|
validateEmail,
|
||||||
|
sendAlert,
|
||||||
|
validateUpdatePassword,
|
||||||
|
} from "./utils"
|
||||||
import config from "./environment"
|
import config from "./environment"
|
||||||
|
|
||||||
const MESSAGE = "Your health ratio is at or below @ratio@% \n"
|
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) => {
|
router.post("/updates", async (ctx, next) => {
|
||||||
try {
|
try {
|
||||||
const update: any = ctx.request.body
|
const update: any = ctx.request.body
|
||||||
|
await validateUpdatePassword(update.password)
|
||||||
ctx.body = { status: "success" }
|
ctx.body = { status: "success" }
|
||||||
ctx.db.collection("updates").insertOne(update)
|
ctx.db.collection("updates").insertOne(update)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
let errorMessage = "Something went wrong"
|
let errorMessage = "Something went wrong"
|
||||||
if (e.name == "UserError") {
|
if (e.name == "UserError") {
|
||||||
errorMessage = e.message
|
errorMessage = e.message
|
||||||
} else {
|
|
||||||
// sendLogsToDiscord(null, e)
|
|
||||||
}
|
}
|
||||||
ctx.throw(400, errorMessage)
|
ctx.throw(400, errorMessage)
|
||||||
}
|
}
|
||||||
|
|
14
src/utils.ts
14
src/utils.ts
|
@ -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) => {
|
export const validateEmail = (email: string) => {
|
||||||
if (!EmailValidator.validate(email)) {
|
if (!EmailValidator.validate(email)) {
|
||||||
throw new UserError("Enter a valid email")
|
throw new UserError("Enter a valid email")
|
||||||
|
|
Loading…
Reference in New Issue