mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
lock as onlyAdmin endpoint
This commit is contained in:
parent
d05253c8cd
commit
7321876864
@ -1,42 +1,43 @@
|
||||
import templates from "../../templates"
|
||||
|
||||
export default {
|
||||
useContext: ["mailTransporter"],
|
||||
middlewares: ["withAuthentication"],
|
||||
fn: async (req, res) => {
|
||||
req.body = await req.urlencoded()
|
||||
useContext: ["mailTransporter"],
|
||||
middlewares: ["withAuthentication", "onlyAdmin"],
|
||||
fn: async (req, res) => {
|
||||
req.body = await req.urlencoded()
|
||||
|
||||
let { to, subject, body, template } = req.body
|
||||
let { to, subject, body, template } = req.body
|
||||
|
||||
if (template) {
|
||||
if (!templates[template]) {
|
||||
throw new OperationError(404, "Template not found")
|
||||
}
|
||||
if (template) {
|
||||
if (!templates[template]) {
|
||||
throw new OperationError(404, "Template not found")
|
||||
}
|
||||
|
||||
body = templates[template]({
|
||||
...req.body
|
||||
})
|
||||
}
|
||||
body = templates[template]({
|
||||
...req.body,
|
||||
})
|
||||
}
|
||||
|
||||
const mailOptions = {
|
||||
from: process.env.SMTP_USERNAME,
|
||||
to: to,
|
||||
subject: subject,
|
||||
html: body
|
||||
}
|
||||
const mailOptions = {
|
||||
from: process.env.SMTP_USERNAME,
|
||||
to: to,
|
||||
subject: subject,
|
||||
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({
|
||||
code: 0,
|
||||
message: "ok",
|
||||
result: result
|
||||
})
|
||||
}
|
||||
return res.json({
|
||||
code: 0,
|
||||
message: "ok",
|
||||
result: result,
|
||||
})
|
||||
},
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user