mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
fix: #9819, show same time info for ban
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
define('forum/login', ['hooks', 'jquery-form'], function (hooks) {
|
define('forum/login', ['hooks', 'translator', 'jquery-form'], function (hooks, translator) {
|
||||||
var Login = {
|
var Login = {
|
||||||
_capsState: false,
|
_capsState: false,
|
||||||
};
|
};
|
||||||
@@ -44,17 +44,22 @@ define('forum/login', ['hooks', 'jquery-form'], function (hooks) {
|
|||||||
window.location.href = pathname + '?' + qs;
|
window.location.href = pathname + '?' + qs;
|
||||||
},
|
},
|
||||||
error: function (data) {
|
error: function (data) {
|
||||||
|
var message = data.responseText;
|
||||||
|
var errInfo = data.responseJSON;
|
||||||
if (data.status === 403 && data.responseText === 'Forbidden') {
|
if (data.status === 403 && data.responseText === 'Forbidden') {
|
||||||
window.location.href = config.relative_path + '/login?error=csrf-invalid';
|
window.location.href = config.relative_path + '/login?error=csrf-invalid';
|
||||||
} else {
|
} else if (errInfo && errInfo.hasOwnProperty('banned_until')) {
|
||||||
errorEl.find('p').translateText(data.responseText);
|
message = errInfo.banned_until ?
|
||||||
errorEl.show();
|
translator.compile('error:user-banned-reason-until', (new Date(errInfo.banned_until).toLocaleString()), errInfo.reason) :
|
||||||
submitEl.removeClass('disabled');
|
'[[error:user-banned-reason, ' + errInfo.reason + ']]';
|
||||||
|
}
|
||||||
|
errorEl.find('p').translateText(message);
|
||||||
|
errorEl.show();
|
||||||
|
submitEl.removeClass('disabled');
|
||||||
|
|
||||||
// Select the entire password if that field has focus
|
// Select the entire password if that field has focus
|
||||||
if ($('#password:focus').length) {
|
if ($('#password:focus').length) {
|
||||||
$('#password').select();
|
$('#password').select();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ function continueLogin(strategy, req, res, next) {
|
|||||||
passport.authenticate(strategy, async (err, userData, info) => {
|
passport.authenticate(strategy, async (err, userData, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
plugins.hooks.fire('action:login.continue', { req, strategy, userData, error: err });
|
plugins.hooks.fire('action:login.continue', { req, strategy, userData, error: err });
|
||||||
return helpers.noScriptErrors(req, res, err.message, 403);
|
return helpers.noScriptErrors(req, res, err.data || err.message, 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userData) {
|
if (!userData) {
|
||||||
@@ -433,8 +433,7 @@ authenticationController.localLogin = async function (req, username, password, n
|
|||||||
userData.isAdminOrGlobalMod = isAdminOrGlobalMod;
|
userData.isAdminOrGlobalMod = isAdminOrGlobalMod;
|
||||||
|
|
||||||
if (!canLoginIfBanned) {
|
if (!canLoginIfBanned) {
|
||||||
const banMesage = await getBanInfo(uid);
|
return next(await getBanError(uid));
|
||||||
return next(new Error(banMesage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doing this after the ban check, because user's privileges might change after a ban expires
|
// Doing this after the ban check, because user's privileges might change after a ban expires
|
||||||
@@ -493,19 +492,19 @@ authenticationController.logout = async function (req, res, next) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getBanInfo(uid) {
|
async function getBanError(uid) {
|
||||||
try {
|
try {
|
||||||
const banInfo = await user.getLatestBanInfo(uid);
|
const banInfo = await user.getLatestBanInfo(uid);
|
||||||
|
|
||||||
if (!banInfo.reason) {
|
if (!banInfo.reason) {
|
||||||
banInfo.reason = await translator.translate('[[user:info.banned-no-reason]]');
|
banInfo.reason = '[[user:info.banned-no-reason]]';
|
||||||
}
|
}
|
||||||
return banInfo.banned_until ?
|
const err = new Error(banInfo.reason);
|
||||||
`[[error:user-banned-reason-until, ${banInfo.banned_until_readable}, ${banInfo.reason}]]` :
|
err.data = banInfo;
|
||||||
`[[error:user-banned-reason, ${banInfo.reason}]]`;
|
return err;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.message === 'no-ban-info') {
|
if (err.message === 'no-ban-info') {
|
||||||
return '[[error:user-banned]]';
|
return new Error('[[error:user-banned]]');
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ const url = nconf.get('url');
|
|||||||
|
|
||||||
helpers.noScriptErrors = async function (req, res, error, httpStatus) {
|
helpers.noScriptErrors = async function (req, res, error, httpStatus) {
|
||||||
if (req.body.noscript !== 'true') {
|
if (req.body.noscript !== 'true') {
|
||||||
return res.status(httpStatus).send(error);
|
if (typeof error === 'string') {
|
||||||
|
return res.status(httpStatus).send(error);
|
||||||
|
}
|
||||||
|
return res.status(httpStatus).json(error);
|
||||||
}
|
}
|
||||||
const middleware = require('../middleware');
|
const middleware = require('../middleware');
|
||||||
const httpStatusString = httpStatus.toString();
|
const httpStatusString = httpStatus.toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user