mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
refactor ban messaging; add ban duration to message; use bootbox instead of alert
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
"user-banned": "User banned",
|
"user-banned": "User banned",
|
||||||
"user-banned-reason": "Sorry, this account has been banned (Reason: %1)",
|
"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",
|
"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.",
|
"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",
|
"ban-expiry-missing": "Please provide an end date for this ban",
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ app.cacheBuster = null;
|
|||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var showWelcomeMessage = !!utils.params().loggedin;
|
var showWelcomeMessage = !!utils.params().loggedin;
|
||||||
var showBannedMessage = !!utils.params().banned && app.user && app.user.uid === 0;
|
|
||||||
|
|
||||||
templates.setGlobal('config', config);
|
templates.setGlobal('config', config);
|
||||||
|
|
||||||
@@ -266,11 +265,6 @@ app.cacheBuster = null;
|
|||||||
title: '[[global:welcome_back]] ' + app.user.username + '!',
|
title: '[[global:welcome_back]] ' + app.user.username + '!',
|
||||||
message: '[[global:you_have_successfully_logged_in]]',
|
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) {
|
function showAlert(type) {
|
||||||
@@ -303,13 +297,6 @@ app.cacheBuster = null;
|
|||||||
showAlert('login');
|
showAlert('login');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showBannedMessage) {
|
|
||||||
showBannedMessage = false;
|
|
||||||
$(document).ready(function () {
|
|
||||||
showAlert('banned');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app.openChat = function (roomId, uid) {
|
app.openChat = function (roomId, uid) {
|
||||||
|
|||||||
@@ -121,7 +121,16 @@ app.isConnected = false;
|
|||||||
app.isConnected = false;
|
app.isConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onEventBanned() {
|
function onEventBanned(data) {
|
||||||
window.location.href = config.relative_path + '/';
|
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 + '/';
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ module.exports = function (middleware) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
if (results.banned) {
|
if (results.banned) {
|
||||||
req.logout();
|
req.logout();
|
||||||
return res.redirect('/?banned=' + (results.banReason || 'no-reason'));
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
results.user.isAdmin = results.isAdmin;
|
results.user.isAdmin = results.isAdmin;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ var websockets = require('../index');
|
|||||||
var events = require('../../events');
|
var events = require('../../events');
|
||||||
var privileges = require('../../privileges');
|
var privileges = require('../../privileges');
|
||||||
var plugins = require('../../plugins');
|
var plugins = require('../../plugins');
|
||||||
|
var translator = require('../../translator');
|
||||||
|
|
||||||
module.exports = function (SocketUser) {
|
module.exports = function (SocketUser) {
|
||||||
SocketUser.banUsers = function (socket, data, callback) {
|
SocketUser.banUsers = function (socket, data, callback) {
|
||||||
@@ -99,7 +100,20 @@ module.exports = function (SocketUser) {
|
|||||||
user.ban(uid, until, reason, next);
|
user.ban(uid, until, reason, next);
|
||||||
},
|
},
|
||||||
function (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();
|
next();
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
Reference in New Issue
Block a user