Skip to content

Commit 6392311

Browse files
committed
feat: add illegal usernames as well
1 parent a504487 commit 6392311

6 files changed

Lines changed: 61 additions & 23 deletions

File tree

index.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const validator = require('validator');
34
var winston = require.main.require('winston');
45
var meta = require.main.require('./src/meta');
56

@@ -25,6 +26,7 @@ var Beep = {
2526
banned_words: null,
2627
banned_urls: null,
2728
illegal_words: null,
29+
illegal_usernames: null,
2830

2931
parseContent: function (content, symbol) {
3032
var nil = '^(?!x)x';
@@ -39,6 +41,7 @@ var Beep = {
3941
}
4042

4143
Beep.illegal_words = Beep.toRegExp(hash.illegal, true);
44+
Beep.illegal_usernames = Beep.toRegExp(hash['illegal-usernames'], true);
4245

4346
if (hash.id && hash.id.length) {
4447
var words = hash.id.split(',').filter(function (word) {
@@ -146,17 +149,17 @@ var Beep = {
146149
// from http://htmlarrows.com/symbols/
147150
var starHTML = '*';
148151

149-
if (data.topic.hasOwnProperty('title')) {
150-
data.topic.title = Beep.parseContent(data.topic.title, starHTML);
151-
}
152+
if (data.topic.hasOwnProperty('title')) {
153+
data.topic.title = Beep.parseContent(data.topic.title, starHTML);
154+
}
152155

153-
if (data.topic.hasOwnProperty('slug')) {
154-
data.topic.slug = Beep.parseContent(data.topic.slug, starHTML);
155-
}
156+
if (data.topic.hasOwnProperty('slug')) {
157+
data.topic.slug = Beep.parseContent(data.topic.slug, starHTML);
158+
}
156159

157-
if (data.topic.hasOwnProperty('titleRaw')) {
158-
data.topic.titleRaw = Beep.parseContent(data.topic.titleRaw, starHTML);
159-
}
160+
if (data.topic.hasOwnProperty('titleRaw')) {
161+
data.topic.titleRaw = Beep.parseContent(data.topic.titleRaw, starHTML);
162+
}
160163

161164
callback(null, data);
162165
},
@@ -206,6 +209,16 @@ var Beep = {
206209
callback(null, data);
207210
},
208211
},
212+
filterUserCreate: function (hookData) {
213+
const { user } = hookData;
214+
if (user && user.username) {
215+
const isIllegal = user.username.match(Beep.illegal_usernames);
216+
if (isIllegal) {
217+
throw new Error(`[[beep:username.error, ${validator.escape(user.username)}]]`);
218+
}
219+
}
220+
return hookData;
221+
},
209222
};
210223

211224
module.exports = Beep;

languages/en_GB/beep.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"titleMatch.error": "You may not use the word \"%1\" in your title.",
33
"contentMatch.error": "You may not use the word \"%1\" in your post.",
4-
"tagMatch.error": "You may not use the word \"%1\" in your tags."
4+
"tagMatch.error": "You may not use the word \"%1\" in your tags.",
5+
"username.error": "You may not use the word \"%1\" as your username."
56
}

package-lock.json

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"name": "@nodebb/nodebb-plugin-beep",
33
"version": "1.0.0",
4-
"description": "NodeBB Censor Curse Words Plugin",
5-
"deprecated": false,
4+
"description": "NodeBB Plugin that allows users to censor curse words in their posts.",
65
"main": "index.js",
76
"scripts": {
87
"test": "node tests"
98
},
109
"repository": {
1110
"type": "git",
12-
"url": "https://github.com/ninenine/nodebb-plugin-beep"
11+
"url": "https://github.com/NodeBB-Community/nodebb-plugin-beep"
1312
},
1413
"keywords": [
1514
"nodebb",
@@ -19,17 +18,18 @@
1918
"curse",
2019
"words"
2120
],
21+
"dependencies": {
22+
"validator": "13.11.0"
23+
},
2224
"author": {
2325
"name": "Davis Wainaina",
2426
"email": "davisjwn@gmail.com"
2527
},
2628
"license": "BSD-2-Clause",
2729
"bugs": {
28-
"url": "https://github.com/ninenine/nodebb-plugin-beep/issues"
30+
"url": "https://github.com/NodeBB-Community/nodebb-plugin-beep/issues"
2931
},
30-
"readme": "",
3132
"readmeFilename": "README.md",
32-
"_from": "nodebb-plugin-beep@0.4.4",
3333
"nbbpm": {
3434
"compatibility": "^3.2.0"
3535
}

plugin.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"id": "nodebb-plugin-beep",
3-
"name": "NodeBB Censor Curse Words Plugin",
4-
"description": "NodeBB Plugin that allows users to censor curse words in their posts.",
5-
"url": "https://github.com/ninenine/nodebb-plugin-beep",
62
"library": "./index.js",
73
"templates":"public/templates",
84
"modules": {
@@ -29,7 +25,9 @@
2925

3026
{ "hook": "filter:config.get", "method": "appendConfig" },
3127

32-
{ "hook": "filter:messaging.getTeaser", "method": "messaging.getTeaser" }
28+
{ "hook": "filter:messaging.getTeaser", "method": "messaging.getTeaser" },
29+
30+
{ "hook": "filter:user.create", "method": "filterUserCreate" }
3331
],
3432
"languages": "languages",
3533
"defaultLang": "en_GB"

public/templates/admin/plugins/beep.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
<textarea class="form-control" id="illegal" name="illegal" placeholder="eg. anal, anus, arse, ass, ballsack" rows="6"></textarea>
1212
</div>
1313
</div>
14+
<div class="mb-3">
15+
<h5 class="fw-bold tracking-tight settings-header">Illegal Usernames</h5>
16+
<div>
17+
<label class="form-label" for="illegal-usernames"><i>comma-separated</i> list of Illegal Usernames (user creation will not be allowed)</label>
18+
<textarea class="form-control" id="illegal-usernames" name="illegal-usernames" placeholder="eg. anal, anus, arse, ass, ballsack" rows="6"></textarea>
19+
</div>
20+
</div>
1421
<div class="mb-3">
1522
<h5 class="fw-bold tracking-tight settings-header">Banned Words</h5>
1623

0 commit comments

Comments
 (0)