Skip to content

Node.js based forum software built for the modern web

refactor ban messaging; add ban duration to message; use bootbox instead of alert

psychobunnyb3bd70235a8e
diff --git a/public/language/en-GB/error.json b/public/language/en-GB/error.json
index 7473b8bc62..5c30bae07c 100644
--- a/public/language/en-GB/error.json
+++ b/public/language/en-GB/error.json
@@ -37,6 +37,7 @@
"user-banned": "User banned",
"user-banned-reason": "Sorry, this account has been banned (Reason: %1)",
+ "user-banned-reason-until": "Sorry, this account has been banned until %1 (Reason: %2)",
"user-too-new": "Sorry, you are required to wait %1 second(s) before making your first post",
"blacklisted-ip": "Sorry, your IP address has been banned from this community. If you feel this is in error, please contact an administrator.",
"ban-expiry-missing": "Please provide an end date for this ban",
diff --git a/public/src/app.js b/public/src/app.js
index 61e5deac50..75a68c9da5 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -10,7 +10,6 @@ app.cacheBuster = null;
(function () {
var showWelcomeMessage = !!utils.params().loggedin;
- var showBannedMessage = !!utils.params().banned && app.user && app.user.uid === 0;
templates.setGlobal('config', config);
@@ -266,11 +265,6 @@ app.cacheBuster = null;
title: '[[global:welcome_back]] ' + app.user.username + '!',
message: '[[global:you_have_successfully_logged_in]]',
},
- banned: {
- format: 'modal',
- title: '[[error:user-banned]]',
- message: '[[error:user-banned-reason, ' + utils.params().banned + ']]',
- },
};
function showAlert(type) {
@@ -303,13 +297,6 @@ app.cacheBuster = null;
showAlert('login');
});
}
-
- if (showBannedMessage) {
- showBannedMessage = false;
- $(document).ready(function () {
- showAlert('banned');
- });
- }
};
app.openChat = function (roomId, uid) {
diff --git a/public/src/sockets.js b/public/src/sockets.js
index 6b22ce9ac9..6b11f49e4f 100644
--- a/public/src/sockets.js
+++ b/public/src/sockets.js
@@ -121,7 +121,16 @@ app.isConnected = false;
app.isConnected = false;
}
- function onEventBanned() {
- window.location.href = config.relative_path + '/';
+ function onEventBanned(data) {
+ var message = data.until ? '[[error:user-banned-reason-until, ' + $.timeago(data.until) + ', ' + data.reason + ']]' : '[[error:user-banned-reason, ' + data.reason + ']]';
+
+ bootbox.alert({
+ title: '[[error:user-banned]]',
+ message: message,
+ closeButton: false,
+ callback: function () {
+ window.location.href = config.relative_path + '/';
+ },
+ });
}
}());
diff --git a/src/middleware/header.js b/src/middleware/header.js
index af1a2e0285..f620195a25 100644
--- a/src/middleware/header.js
+++ b/src/middleware/header.js
@@ -105,7 +105,7 @@ module.exports = function (middleware) {
function (results, next) {
if (results.banned) {
req.logout();
- return res.redirect('/?banned=' + (results.banReason || 'no-reason'));
+ return res.redirect('/');
}
results.user.isAdmin = results.isAdmin;
diff --git a/src/socket.io/user/ban.js b/src/socket.io/user/ban.js
index 8d31a2b341..99ef11d96f 100644
--- a/src/socket.io/user/ban.js
+++ b/src/socket.io/user/ban.js
@@ -7,6 +7,7 @@ var websockets = require('../index');
var events = require('../../events');
var privileges = require('../../privileges');
var plugins = require('../../plugins');
+var translator = require('../../translator');
module.exports = function (SocketUser) {
SocketUser.banUsers = function (socket, data, callback) {
@@ -99,7 +100,20 @@ module.exports = function (SocketUser) {
user.ban(uid, until, reason, next);
},
function (next) {
- websockets.in('uid_' + uid).emit('event:banned');
+ console.log(reason);
+ if (!reason) {
+ return translator.translate('[[user:info.banned-no-reason]]', function (translated) {
+ next(false, translated);
+ });
+ }
+
+ next(false, reason);
+ },
+ function (_reason, next) {
+ websockets.in('uid_' + uid).emit('event:banned', {
+ until: until,
+ reason: _reason,
+ });
next();
},
], callback);