mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 02:31:30 +08:00
Adding endpoint for admins to send transactional e-mail.
This commit is contained in:
@@ -7,6 +7,8 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const resetEmailFile = fs.readFileSync(path.resolve(__dirname, '../../../views/password-reset-email.ejs'));
|
||||
const resetEmailTemplate = ejs.compile(resetEmailFile.toString());
|
||||
const notificationEmailFile = fs.readFileSync(path.resolve(__dirname, '../../../views/notification-email.ejs'));
|
||||
const notificationEmailTemplate = ejs.compile(notificationEmailFile.toString());
|
||||
const authorization = require('../../../middleware/authorization');
|
||||
|
||||
const csrf = require('csurf');
|
||||
@@ -64,6 +66,25 @@ router.post('/:user_id/status', parseForm, csrfProtection, (req, res, next) => {
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
router.post('/:user_id/email', authorization.needed('admin'), parseForm, csrfProtection, (req, res, next) => {
|
||||
User.find(req.user_id)
|
||||
.then(user => {
|
||||
const options = {
|
||||
subject: req.subject,
|
||||
from: process.env.TALK_SMTP_FROM_ADDRESS,
|
||||
to: user.email,
|
||||
html: notificationEmailTemplate({
|
||||
body: req.body
|
||||
})
|
||||
};
|
||||
|
||||
return mailer.sendSimple(options);
|
||||
})
|
||||
.then(() => {
|
||||
res.status(204).end();
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/', parseForm, csrfProtection, (req, res, next) => {
|
||||
const {email, password, displayName} = req.body;
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%= body %>
|
||||
Reference in New Issue
Block a user