#278 [mail][ban] send email on ban
This commit is contained in:
parent
54f9e8d165
commit
8e0915c48e
|
@ -1,12 +1,12 @@
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import SQL from 'sql-template-strings';
|
import SQL from 'sql-template-strings';
|
||||||
import avatar from '../avatar';
|
import avatar from '../avatar';
|
||||||
import {config as socialLoginConfig} from "../social";
|
|
||||||
import {buildDict, now, shuffle, handleErrorAsync, buildLocaleList} from "../../src/helpers";
|
import {buildDict, now, shuffle, handleErrorAsync, buildLocaleList} from "../../src/helpers";
|
||||||
import locales from '../../src/locales';
|
import locales from '../../src/locales';
|
||||||
import {calculateStats, statsFile} from '../../src/stats';
|
import {calculateStats, statsFile} from '../../src/stats';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { caches } from "../../src/cache";
|
import { caches } from "../../src/cache";
|
||||||
|
import mailer from "../../src/mailer";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ router.post('/admin/ban/:username', handleErrorAsync(async (req, res) => {
|
||||||
return res.status(401).json({error: 'Unauthorised'});
|
return res.status(401).json({error: 'Unauthorised'});
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await req.db.get(SQL`SELECT id FROM users WHERE usernameNorm = ${normalise(req.params.username)}`);
|
const user = await req.db.get(SQL`SELECT id, email FROM users WHERE usernameNorm = ${normalise(req.params.username)}`);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return res.status(400).json({error: 'No such user'});
|
return res.status(400).json({error: 'No such user'});
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,7 @@ router.post('/admin/ban/:username', handleErrorAsync(async (req, res) => {
|
||||||
bannedBy = ${req.user.id}
|
bannedBy = ${req.user.id}
|
||||||
WHERE id = ${user.id}
|
WHERE id = ${user.id}
|
||||||
`);
|
`);
|
||||||
|
mailer(user.email, 'ban', {reason: req.body.reason});
|
||||||
} else {
|
} else {
|
||||||
await req.db.get(SQL`
|
await req.db.get(SQL`
|
||||||
UPDATE users
|
UPDATE users
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default [
|
module.exports = [
|
||||||
'propagation of totalitarian regimes',
|
'propagation of totalitarian regimes',
|
||||||
'hate speech',
|
'hate speech',
|
||||||
'racism',
|
'racism',
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const mailer = require('mailer');
|
const mailer = require('mailer');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const Suml = require('suml');
|
const Suml = require('suml');
|
||||||
|
const forbidden = require('./forbidden');
|
||||||
|
|
||||||
const color = '#C71585';
|
const color = '#C71585';
|
||||||
const logo = fs.readFileSync(__dirname + '/../node_modules/@fortawesome/fontawesome-pro/svgs/light/tags.svg').toString('utf-8');
|
const logo = fs.readFileSync(__dirname + '/../node_modules/@fortawesome/fontawesome-pro/svgs/light/tags.svg').toString('utf-8');
|
||||||
|
@ -30,6 +31,8 @@ const sendEmail = (to, subject, body = undefined, html = undefined) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const terms = `It is forbidden to post on the Service any Content that might break the law or violate social norms, including but not limited to: ${forbidden.join(', ')}`
|
||||||
|
|
||||||
const templates = {
|
const templates = {
|
||||||
base: {
|
base: {
|
||||||
subject: `[[title]] » {{content}}`,
|
subject: `[[title]] » {{content}}`,
|
||||||
|
@ -61,7 +64,16 @@ const templates = {
|
||||||
<p style="border: 1px solid #aaa;border-radius: 8px;overflow: hidden;text-align: center;user-select: all;font-size: 24px; padding:8px;letter-spacing: 8px; font-weight: bold;">{{code}}</p>
|
<p style="border: 1px solid #aaa;border-radius: 8px;overflow: hidden;text-align: center;user-select: all;font-size: 24px; padding:8px;letter-spacing: 8px; font-weight: bold;">{{code}}</p>
|
||||||
<p style="font-size: 12px; color: #777">[[user.login.email.extra]]</p>
|
<p style="font-size: 12px; color: #777">[[user.login.email.extra]]</p>
|
||||||
`,
|
`,
|
||||||
}
|
},
|
||||||
|
ban: {
|
||||||
|
subject: '[[ban.header]]',
|
||||||
|
text: `[[ban.header]]\n\n[[ban.reason]][[quotation.colon]] %reason%\n\n[[quotation.start]]${terms}[[quotation.end]]`,
|
||||||
|
html: `
|
||||||
|
<p>[[ban.header]]</p>
|
||||||
|
<p>[[ban.reason]][[quotation.colon]] %reason%</p>
|
||||||
|
<p style="font-size: 12px; color: #777">[[quotation.start]]${terms}[[quotation.end]]</p>
|
||||||
|
`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const applyTemplate = (template, context, params) => {
|
const applyTemplate = (template, context, params) => {
|
||||||
|
@ -71,6 +83,8 @@ const applyTemplate = (template, context, params) => {
|
||||||
template = templates.base[context].replace('{{content}}', template);
|
template = templates.base[context].replace('{{content}}', template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template = template.replace(/%reason%/g, '{{reason}}'); // TODO
|
||||||
|
|
||||||
template = template.replace(/\[\[([^\]]+)]]/g, m => {
|
template = template.replace(/\[\[([^\]]+)]]/g, m => {
|
||||||
let x = translations;
|
let x = translations;
|
||||||
for (let part of m.substring(2, m.length - 2).split('.')) {
|
for (let part of m.substring(2, m.length - 2).split('.')) {
|
||||||
|
|
Reference in New Issue