lock as onlyAdmin endpoint

This commit is contained in:
SrGooglo 2025-02-25 23:09:54 +00:00
parent d05253c8cd
commit 7321876864

View File

@ -1,42 +1,43 @@
import templates from "../../templates" import templates from "../../templates"
export default { export default {
useContext: ["mailTransporter"], useContext: ["mailTransporter"],
middlewares: ["withAuthentication"], middlewares: ["withAuthentication", "onlyAdmin"],
fn: async (req, res) => { fn: async (req, res) => {
req.body = await req.urlencoded() req.body = await req.urlencoded()
let { to, subject, body, template } = req.body let { to, subject, body, template } = req.body
if (template) { if (template) {
if (!templates[template]) { if (!templates[template]) {
throw new OperationError(404, "Template not found") throw new OperationError(404, "Template not found")
} }
body = templates[template]({ body = templates[template]({
...req.body ...req.body,
}) })
} }
const mailOptions = { const mailOptions = {
from: process.env.SMTP_USERNAME, from: process.env.SMTP_USERNAME,
to: to, to: to,
subject: subject, subject: subject,
html: body html: body,
} }
console.log(mailOptions) console.log(mailOptions)
console.log(`Sending email to ${to}...`) console.log(`Sending email to ${to}...`)
const result = await this.default.contexts.mailTransporter.sendMail(mailOptions) const result =
await this.default.contexts.mailTransporter.sendMail(mailOptions)
console.log("Email sent! >", result) console.log("Email sent! >", result)
return res.json({ return res.json({
code: 0, code: 0,
message: "ok", message: "ok",
result: result result: result,
}) })
} },
} }