diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 721e0255ae..bfcc38db89 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -24,6 +24,8 @@ var fs = require('fs'), websockets = require('../socket.io'); function userNotFound(res) { + res.locals.notFound = true; + if (res.locals.isAPI) { res.status(404).json('no-user'); } else { diff --git a/src/meta/title.js b/src/meta/title.js index 0ca2d346ac..735a3558c7 100644 --- a/src/meta/title.js +++ b/src/meta/title.js @@ -15,7 +15,7 @@ module.exports = function(Meta) { isUserPage: /^user\/[^\/]+(\/[\w]+)?/ }; - Meta.title.build = function (urlFragment, language, callback) { + Meta.title.build = function (urlFragment, language, locals, callback) { var uri = ''; try { uri = decodeURIComponent(urlFragment); @@ -23,7 +23,8 @@ module.exports = function(Meta) { winston.error('Invalid url fragment : ' + urlFragment, e.stack); return callback(null, Meta.config.browserTitle || 'NodeBB'); } - Meta.title.parseFragment(uri, language, function(err, title) { + + Meta.title.parseFragment(uri, language, locals, function(err, title) { if (err) { title = Meta.config.browserTitle || 'NodeBB'; } else { @@ -34,7 +35,7 @@ module.exports = function(Meta) { }); }; - Meta.title.parseFragment = function (urlFragment, language, callback) { + Meta.title.parseFragment = function (urlFragment, language, locals, callback) { urlFragment = validator.escape(urlFragment); var translated = ['', 'recent', 'unread', 'users', 'notifications']; if (translated.indexOf(urlFragment) !== -1) { @@ -69,6 +70,10 @@ module.exports = function(Meta) { return callback(err); } + if (locals.notFound) { + username = '[[error:no-user]]'; + } + if (!subpage) { return callback(null, username); } diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 19bf1b1bef..66f5852a9a 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -339,10 +339,10 @@ middleware.renderHeader = function(req, res, callback) { if (err) { return next(err); } - meta.title.build(req.url.slice(1), settings.language, next); + meta.title.build(req.url.slice(1), settings.language, res.locals, next); }); } else { - meta.title.build(req.url.slice(1), meta.config.defaultLang, next); + meta.title.build(req.url.slice(1), meta.config.defaultLang, res.locals, next); } }, isAdmin: function(next) {