Node.js based forum software built for the modern web
Merge remote-tracking branch 'origin/master' into user-icons
Julian Lamb52475c2709e
diff --cc public/language/en_GB/user.jsonindex 3505d1814c,097a562e3f..a4b3f33475--- a/public/language/en_GB/user.json+++ b/public/language/en_GB/user.json@@@ -38,8 -39,9 +38,10 @@@"profile_update_success": "Profile has been updated successfully!","change_picture": "Change Picture",+ "change_username": "Change Username",+ "change_email": "Change Email","edit": "Edit",+ "default_picture": "Default Icon","uploaded_picture": "Uploaded Picture","upload_new_picture": "Upload New Picture","upload_new_picture_from_url": "Upload New Picture From URL",diff --cc public/less/generics.lessindex ce824ab04f,8104d2a35f..4115f7d117--- a/public/less/generics.less+++ b/public/less/generics.less@@@ -41,17 -41,3 +41,17 @@@}}}++.user-icon {+ display: inline-block;+ text-align: center;+ color: @gray-lighter;+ font-weight: normal;++ &:before {+ content: '';+ display: inline-block;+ height: 100%;+ vertical-align: middle;+ }- }++}diff --cc public/src/app.jsindex e2265fbe24,c3727f6c77..f739ac9c4f--- a/public/src/app.js+++ b/public/src/app.js@@@ -138,13 -140,10 +140,12 @@@ app.cacheBuster = nullusername: app.user.username,userslug: app.user.userslug,picture: app.user.picture,- status: app.user.status+ status: app.user.status,+ 'icon:bgColor': app.user['icon:bgColor'],+ 'icon:text': app.user['icon:text']}, function(err) {if (err) {- app.alertError(err.message);- return;+ return app.alertError(err.message);}app.currentRoom = room;});diff --cc public/src/client/account/edit.jsindex 7271e854bc,b3cdfe4966..7969a1bcf1--- a/public/src/client/account/edit.js+++ b/public/src/client/account/edit.js@@@ -4,11 -4,12 +4,10 @@@define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], function(header, uploader, translator) {var AccountEdit = {},- gravatarPicture = '',uploadedPicture = '',- selectedImageType = '',- currentEmail;+ selectedImageType = '';AccountEdit.init = function() {- gravatarPicture = ajaxify.data.gravatarpicture;uploadedPicture = ajaxify.data.uploadedpicture;header.init();@@@ -57,21 -53,12 +51,7 @@@$('#user-current-picture').attr('src', data.picture);}- if (data.userslug) {- var oldslug = $('.account-username-box').attr('data-userslug');- $('.account-username-box a').each(function() {- $(this).attr('href', $(this).attr('href').replace(oldslug, data.userslug));- });-- $('.account-username-box').attr('data-userslug', data.userslug);- }-- if (currentEmail !== data.email) {- currentEmail = data.email;- $('#confirm-email').removeClass('hide');- if (data.gravatarpicture) {- $('#user-gravatar-picture').attr('src', data.gravatarpicture);- gravatarPicture = data.gravatarpicture;-- }--- updateHeader(data.picture, userData.username, data.userslug);+ updateHeader(data.picture);});return false;diff --cc src/middleware/header.jsindex 0000000000,8dcde8a93a..d5baaeedaamode 000000,100644..100644--- a/src/middleware/header.js+++ b/src/middleware/header.js@@@ -1,0 -1,157 +1,157 @@@+ 'use strict';++ var async = require('async');+ var nconf = require('nconf');++ var user = require('../user');+ var meta = require('../meta');+ var plugins = require('../plugins');+ var navigation = require('../navigation');+ var translator = require('../../public/src/modules/translator');++ var controllers = {+ api: require('../controllers/api'),+ helpers: require('../controllers/helpers')+ };++ module.exports = function(app, middleware) {++ middleware.buildHeader = function(req, res, next) {+ res.locals.renderHeader = true;+ res.locals.isAPI = false;++ middleware.applyCSRF(req, res, function() {+ async.parallel({+ config: function(next) {+ controllers.api.getConfig(req, res, next);+ },+ footer: function(next) {+ app.render('footer', {loggedIn: (req.user ? parseInt(req.user.uid, 10) !== 0 : false)}, next);+ },+ plugins: function(next) {+ plugins.fireHook('filter:middleware.buildHeader', {req: req, locals: res.locals}, next);+ }+ }, function(err, results) {+ if (err) {+ return next(err);+ }++ res.locals.config = results.config;++ translator.translate(results.footer, results.config.defaultLang, function(parsedTemplate) {+ res.locals.footer = parsedTemplate;+ next();+ });+ });+ });+ };++ middleware.renderHeader = function(req, res, data, callback) {+ var registrationType = meta.config.registrationType || 'normal';+ var templateValues = {+ bootswatchCSS: meta.config['theme:src'],+ title: meta.config.title || '',+ description: meta.config.description || '',+ 'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',+ 'brand:logo': meta.config['brand:logo'] || '',+ 'brand:logo:url': meta.config['brand:logo:url'] || '',+ 'brand:logo:alt': meta.config['brand:logo:alt'] || '',+ 'brand:logo:display': meta.config['brand:logo']?'':'hide',+ allowRegistration: registrationType === 'normal' || registrationType === 'admin-approval',+ searchEnabled: plugins.hasListeners('filter:search.query'),+ config: res.locals.config,+ relative_path: nconf.get('relative_path'),+ bodyClass: data.bodyClass+ };++ templateValues.configJSON = JSON.stringify(res.locals.config);++ async.parallel({+ isAdmin: function(next) {+ user.isAdministrator(req.uid, next);+ },+ user: function(next) {+ if (req.uid) {- user.getUserFields(req.uid, ['username', 'userslug', 'email', 'picture', 'status', 'email:confirmed', 'banned'], next);++ user.getUserFields(req.uid, ['username', 'userslug', 'email', 'picture', 'icon:bgColor', 'icon:text', 'status', 'email:confirmed', 'banned'], next);+ } else {+ next(null, {+ username: '[[global:guest]]',+ userslug: '',- picture: user.createGravatarURLFromEmail(''),++ picture: meta.config.defaultAvatar,+ status: 'offline',+ banned: false,+ uid: 0+ });+ }+ },+ navigation: async.apply(navigation.get),+ tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags)+ }, function(err, results) {+ if (err) {+ return callback(err);+ }++ if (results.user && parseInt(results.user.banned, 10) === 1) {+ req.logout();+ return res.redirect('/');+ }++ results.user.isAdmin = results.isAdmin;+ results.user.uid = parseInt(results.user.uid, 10);+ results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1;++ if (res.locals.config.bootswatchSkin !== 'default') {+ templateValues.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + res.locals.config.bootswatchSkin + '/bootstrap.min.css';+ }++ templateValues.browserTitle = controllers.helpers.buildTitle(data.title);+ templateValues.navigation = results.navigation;+ templateValues.metaTags = results.tags.meta;+ templateValues.linkTags = results.tags.link;+ templateValues.isAdmin = results.user.isAdmin;+ templateValues.user = results.user;+ templateValues.userJSON = JSON.stringify(results.user);+ templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS;+ templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : '';+ templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1;+ templateValues.customJS = templateValues.useCustomJS ? meta.config.customJS : '';+ templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;+ templateValues.defaultLang = meta.config.defaultLang || 'en_GB';++ templateValues.template = {name: res.locals.template};+ templateValues.template[res.locals.template] = true;++ if (req.route && req.route.path === '/') {+ modifyTitle(templateValues);+ }++ plugins.fireHook('filter:middleware.renderHeader', {templateValues: templateValues, req: req, res: res}, function(err, data) {+ if (err) {+ return callback(err);+ }++ app.render('header', data.templateValues, callback);+ });+ });+ };+++ function modifyTitle(obj) {+ var title = controllers.helpers.buildTitle('[[pages:home]]');+ obj.browserTitle = title;++ if (obj.metaTags) {+ obj.metaTags.forEach(function(tag, i) {+ if (tag.property === 'og:title') {+ obj.metaTags[i].content = title;+ }+ });+ }++ return title;+ }++ };+++diff --cc src/middleware/middleware.jsindex 5b5ad36a6a,6215f6a5b7..6b8447bc57--- a/src/middleware/middleware.js+++ b/src/middleware/middleware.js@@@ -168,219 -147,8 +147,6 @@@ middleware.isAdmin = function(req, res});};- middleware.buildHeader = function(req, res, next) {- res.locals.renderHeader = true;- res.locals.isAPI = false;-- middleware.applyCSRF(req, res, function() {- async.parallel({- config: function(next) {- controllers.api.getConfig(req, res, next);- },- footer: function(next) {- app.render('footer', {loggedIn: (req.user ? parseInt(req.user.uid, 10) !== 0 : false)}, next);- },- plugins: function(next) {- plugins.fireHook('filter:middleware.buildHeader', {req: req, locals: res.locals}, next);- }- }, function(err, results) {- if (err) {- return next(err);- }-- res.locals.config = results.config;-- translator.translate(results.footer, results.config.defaultLang, function(parsedTemplate) {- res.locals.footer = parsedTemplate;- next();- });- });- });- };-- middleware.renderHeader = function(req, res, data, callback) {- var registrationType = meta.config.registrationType || 'normal';- var templateValues = {- bootswatchCSS: meta.config['theme:src'],- title: meta.config.title || '',- description: meta.config.description || '',- 'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',- 'brand:logo': meta.config['brand:logo'] || '',- 'brand:logo:url': meta.config['brand:logo:url'] || '',- 'brand:logo:alt': meta.config['brand:logo:alt'] || '',- 'brand:logo:display': meta.config['brand:logo']?'':'hide',- allowRegistration: registrationType === 'normal' || registrationType === 'admin-approval',- searchEnabled: plugins.hasListeners('filter:search.query'),- config: res.locals.config,- relative_path: nconf.get('relative_path')- };-- templateValues.configJSON = JSON.stringify(res.locals.config);-- async.parallel({- customCSS: function(next) {- templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1;- if (!templateValues.useCustomCSS || !meta.config.customCSS || !meta.config.renderedCustomCSS) {- return next(null, '');- }- next(null, meta.config.renderedCustomCSS);- },- customJS: function(next) {- templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1;- next(null, templateValues.useCustomJS ? meta.config.customJS : '');- },- settings: function(next) {- if (req.uid) {- user.getSettings(req.uid, next);- } else {- next();- }- },- title: function(next) {- next(null, controllers.helpers.buildTitle(data.title));- },- isAdmin: function(next) {- user.isAdministrator(req.uid, next);- },- user: function(next) {- if (req.uid) {- user.getUserFields(req.uid, ['username', 'userslug', 'email', 'picture', 'icon:bgColor', 'icon:text', 'status', 'email:confirmed', 'banned'], next);- } else {- next(null, {- username: '[[global:guest]]',- userslug: '',- picture: meta.config.defaultAvatar,- status: 'offline',- banned: false,- uid: 0- });- }- },- navigation: async.apply(navigation.get),- tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags)- }, function(err, results) {- if (err) {- return callback(err);- }-- if (results.user && parseInt(results.user.banned, 10) === 1) {- req.logout();- return res.redirect('/');- }- results.user.isAdmin = results.isAdmin || false;- results.user.uid = parseInt(results.user.uid, 10);- results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1;-- if (results.settings && results.settings.bootswatchSkin && results.settings.bootswatchSkin !== 'default') {- templateValues.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + results.settings.bootswatchSkin + '/bootstrap.min.css';- }-- templateValues.browserTitle = results.title;- templateValues.navigation = results.navigation;- templateValues.metaTags = results.tags.meta;- templateValues.linkTags = results.tags.link;- templateValues.isAdmin = results.user.isAdmin;- templateValues.user = results.user;- templateValues.userJSON = JSON.stringify(results.user);- templateValues.customCSS = results.customCSS;- templateValues.customJS = results.customJS;- templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;- templateValues.defaultLang = meta.config.defaultLang || 'en_GB';-- templateValues.template = {name: res.locals.template};- templateValues.template[res.locals.template] = true;-- if (req.route && req.route.path === '/') {- modifyTitle(templateValues);- }-- plugins.fireHook('filter:middleware.renderHeader', {templateValues: templateValues, req: req, res: res}, function(err, data) {- if (err) {- return callback(err);- }-- app.render('header', data.templateValues, callback);- });- });- };-- middleware.processRender = function(req, res, next) {- // res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687- var render = res.render;- res.render = function(template, options, fn) {- var self = this,- req = this.req,- app = req.app,- defaultFn = function(err, str){- if (err) {- return req.next(err);- }-- self.send(str);- };- options = options || {};-- if ('function' === typeof options) {- fn = options;- options = {};- }-- options.loggedIn = req.user ? parseInt(req.user.uid, 10) !== 0 : false;- options.relative_path = nconf.get('relative_path');- options.template = {name: template};- options.template[template] = true;- res.locals.template = template;-- if ('function' !== typeof fn) {- fn = defaultFn;- }-- if (res.locals.isAPI) {- if (req.route && req.route.path === '/api/') {- options.title = '[[pages:home]]';- }-- return res.json(options);- }-- var ajaxifyData = encodeURIComponent(JSON.stringify(options));- render.call(self, template, options, function(err, str) {- if (err) {- winston.error(err);- return fn(err);- }-- str = str + '<input type="hidden" ajaxify-data="' + ajaxifyData + '" />';- str = (res.locals.postHeader ? res.locals.postHeader : '') + str + (res.locals.preFooter ? res.locals.preFooter : '');-- if (res.locals.footer) {- str = str + res.locals.footer;- } else if (res.locals.adminFooter) {- str = str + res.locals.adminFooter;- }-- if (res.locals.renderHeader || res.locals.renderAdminHeader) {- var method = res.locals.renderHeader ? middleware.renderHeader : middleware.admin.renderHeader;- method(req, res, options, function(err, template) {- if (err) {- return fn(err);- }- str = template + str;- var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB';- language = req.query.lang || language;- translator.translate(str, language, function(translated) {- fn(err, translated);- });- });- } else {- fn(err, str);- }- });- };--- next();- };--middleware.routeTouchIcon = function(req, res) {if (meta.config['brand:logo'] && validator.isURL(meta.config['brand:logo'])) {return res.redirect(meta.config['brand:logo']);diff --cc src/socket.io/user/picture.jsindex f7c4d61739,0dbd87b34f..d46ce9284c--- a/src/socket.io/user/picture.js+++ b/src/socket.io/user/picture.js@@@ -23,17 -23,14 +23,17 @@@ module.exports = function(SocketUser)} else if (type === 'uploaded') {type = 'uploadedpicture';} else {- return callback(new Error('[[error:invalid-image-type, ' + ['default', 'uploadedpicture'].join(', ') + ']]'));- return callback(new Error('[[error:invalid-image-type, ' + ['gravatar', 'uploadedpicture'].join(', ') + ']]'));++ return callback(new Error('[[error:invalid-image-type, ' + ['default', 'uploadedpicture'].join(', ') + ']]'));}async.waterfall([function (next) {- SocketUser.isAdminOrSelf(socket, data.uid, next);+ user.isAdminOrSelf(socket.uid, data.uid, next);},function (next) {+ if (!type) {+ next(null, '');+ }user.getUserField(data.uid, type, next);},function (picture, next) {diff --cc src/user.jsindex 74c3a75cd6,0ea081a66e..4d6593ab20--- a/src/user.js+++ b/src/user.js@@@ -36,7 -33,7 +33,8 @@@ var async = require('async')require('./user/picture')(User);require('./user/approval')(User);require('./user/invite')(User);+ require('./user/icon')(User);+ require('./user/password')(User);User.updateLastOnlineTime = function(uid, callback) {callback = callback || function() {};