v1.18.x
barisusakli 9 years ago
parent aafd4b6984
commit 9bc43ba5e1

@ -374,12 +374,8 @@ var db = require('./database'),
}; };
Messaging.canMessage = function(fromUid, toUid, callback) { Messaging.canMessage = function(fromUid, toUid, callback) {
if (parseInt(meta.config.disableChat) === 1) { if (parseInt(meta.config.disableChat) === 1 || !fromUid || toUid === fromUid) {
return callback(new Error('[[error:chat-disabled]]')); return callback(null, false);
} else if (toUid === fromUid) {
return callback(new Error('[[error:cant-chat-with-yourself]]'));
} else if (!fromUid) {
return callback(new Error('[[error:not-logged-in]]'));
} }
async.waterfall([ async.waterfall([
@ -388,17 +384,17 @@ var db = require('./database'),
}, },
function (exists, next) { function (exists, next) {
if (!exists) { if (!exists) {
return next(new Error('[[error:no-user]]')); return callback(null, false);
} }
user.getUserFields(fromUid, ['banned', 'email:confirmed'], next); user.getUserFields(fromUid, ['banned', 'email:confirmed'], next);
}, },
function (userData, next) { function (userData, next) {
if (parseInt(userData.banned, 10) === 1) { if (parseInt(userData.banned, 10) === 1) {
return next(new Error('[[error:user-banned]]')); return callback(null, false);
} }
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) { if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
return next(new Error('[[error:email-not-confirmed-chat]]')); return callback(null, false);
} }
user.getSettings(toUid, next); user.getSettings(toUid, next);

@ -175,7 +175,7 @@ function handle404(app, middleware) {
} }
function handleErrors(app, middleware) { function handleErrors(app, middleware) {
app.use(function(err, req, res) { app.use(function(err, req, res, next) {
if (err.code === 'EBADCSRFTOKEN') { if (err.code === 'EBADCSRFTOKEN') {
winston.error(req.path + '\n', err.message); winston.error(req.path + '\n', err.message);
return res.sendStatus(403); return res.sendStatus(403);
@ -190,7 +190,7 @@ function handleErrors(app, middleware) {
res.status(err.status || 500); res.status(err.status || 500);
if (res.locals.isAPI) { if (res.locals.isAPI) {
return res.json({path: req.path, error: err.message}); res.json({path: req.path, error: err.message});
} else { } else {
middleware.buildHeader(req, res, function() { middleware.buildHeader(req, res, function() {
res.render('500', {path: req.path, error: err.message}); res.render('500', {path: req.path, error: err.message});

@ -0,0 +1,9 @@
<script type="text/tpl" data-template="500">
<div class="alert alert-danger">
<strong>[[global:500.title]]</strong>
<p>[[global:500.message]]</p>
<p>{path}</p>
<!-- IF error --><p>{error}</p><!-- ENDIF error -->
</div>
</script>

@ -1,9 +1,6 @@
<script type="text/tpl" data-template="500">
<div class="alert alert-danger"> <div class="alert alert-danger">
<strong>[[global:500.title]]</strong> <strong>[[global:500.title]]</strong>
<p>[[global:500.message]]</p> <p>[[global:500.message]]</p>
<p>{path}</p> <p>{path}</p>
<!-- IF error --><p>{error}</p><!-- ENDIF error --> <!-- IF error --><p>{error}</p><!-- ENDIF error -->
</div> </div>
</script>
Loading…
Cancel
Save