Node.js based forum software built for the modern web
add ban messaging when logged in
psychobunny41b4ef859f94
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.jsindex 54d8d99660..77f0fb46b5 100644--- a/src/controllers/authentication.js+++ b/src/controllers/authentication.js@@ -13,6 +13,7 @@ var user = require('../user');var plugins = require('../plugins');var utils = require('../utils');var Password = require('../password');+var translator = require('../translator');var sockets = require('../socket.io');@@ -379,24 +380,13 @@ authenticationController.localLogin = function (req, username, password, next) {if (!result.isAdmin && parseInt(meta.config.allowLocalLogin, 10) === 0) {return next(new Error('[[error:local-login-disabled]]'));}+if (!userData || !userData.password) {return next(new Error('[[error:invalid-user-data]]'));}+if (result.banned) {- // Retrieve ban reason and show error- return user.getLatestBanInfo(uid, function (err, banInfo) {- if (err) {- if (err.message === 'no-ban-info') {- next(new Error('[[error:user-banned]]'));- } else {- next(err);- }- } else if (banInfo.reason) {- next(new Error('[[error:user-banned-reason, ' + banInfo.reason + ']]'));- } else {- next(new Error('[[error:user-banned]]'));- }- });+ return banUser(uid, next);}Password.compare(password, userData.password, next);@@ -437,5 +427,25 @@ authenticationController.logout = function (req, res, next) {}};+function banUser(uid, next) {+ user.getLatestBanInfo(uid, function (err, banInfo) {+ if (err) {+ if (err.message === 'no-ban-info') {+ return next(new Error('[[error:user-banned]]'));+ }++ return next(err);+ }++ if (!banInfo.reason) {+ translator.translate('[[user:info.banned-no-reason]]', function (translated) {+ banInfo.reason = translated;+ next(new Error(banInfo.expiry ? '[[error:user-banned-reason-until, ' + banInfo.expiry_readable + ', ' + banInfo.reason + ']]' : '[[error:user-banned-reason, ' + banInfo.reason + ']]'));+ });+ } else {+ next(new Error(banInfo.expiry ? '[[error:user-banned-reason-until, ' + banInfo.expiry_readable + ', ' + banInfo.reason + ']]' : '[[error:user-banned-reason, ' + banInfo.reason + ']]'));+ }+ });+}module.exports = authenticationController;diff --git a/src/socket.io/user/ban.js b/src/socket.io/user/ban.jsindex 99ef11d96f..cbc15d3270 100644--- a/src/socket.io/user/ban.js+++ b/src/socket.io/user/ban.js@@ -100,7 +100,6 @@ module.exports = function (SocketUser) {user.ban(uid, until, reason, next);},function (next) {- console.log(reason);if (!reason) {return translator.translate('[[user:info.banned-no-reason]]', function (translated) {next(false, translated);diff --git a/src/user/info.js b/src/user/info.jsindex d3ad7d765d..755c7cff8c 100644--- a/src/user/info.js+++ b/src/user/info.js@@ -41,7 +41,7 @@ module.exports = function (User) {uid: uid,timestamp: timestamp,expiry: parseInt(expiry, 10),- expiry_readable: new Date(parseInt(expiry, 10)).toString().replace(/:/g, '%3A'),+ expiry_readable: new Date(parseInt(expiry, 10)).toString(),reason: validator.escape(String(reason)),});});