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

v1.18.x
psychobunny 8 years ago
parent 76a2b4800b
commit b3bd70235a

@ -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",

@ -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) {

@ -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 + '/';
},
});
}
}());

@ -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;

@ -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);

Loading…
Cancel
Save