diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js index 497564d88a..26802a5cdd 100644 --- a/src/controllers/accounts/edit.js +++ b/src/controllers/accounts/edit.js @@ -1,15 +1,14 @@ 'use strict'; -var async = require('async'), - fs = require('fs'), - nconf = require('nconf'), - winston = require('winston'), +var async = require('async'); +var fs = require('fs'); +var nconf = require('nconf'); +var winston = require('winston'); - db = require('../../database'), - user = require('../../user'), - meta = require('../../meta'), - helpers = require('../helpers'), - accountHelpers = require('./helpers'); +var db = require('../../database'); +var user = require('../../user'); +var helpers = require('../helpers'); +var accountHelpers = require('./helpers'); var editController = {}; @@ -19,7 +18,6 @@ editController.get = function(req, res, callback) { return callback(err); } - userData['username:disableEdit'] = !userData.isAdmin && parseInt(meta.config['username:disableEdit'], 10) === 1; userData.title = '[[pages:account/edit, ' + userData.username + ']]'; userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:edit]]'}]); @@ -44,6 +42,9 @@ function renderRoute(name, req, res, next) { if (err) { return next(err); } + if ((name === 'username' && userData['username:disableEdit']) || (name === 'email' && userData['email:disableEdit'])) { + return next(); + } userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]'; userData.breadcrumbs = helpers.buildBreadcrumbs([ @@ -74,7 +75,6 @@ function getUserData(req, next, callback) { return callback(err); } - userData['username:disableEdit'] = parseInt(meta.config['username:disableEdit'], 10) === 1; userData.hasPassword = !!password; callback(null, userData); }); diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js index 9a679cd49a..5a4106e1b7 100644 --- a/src/controllers/accounts/helpers.js +++ b/src/controllers/accounts/helpers.js @@ -1,15 +1,14 @@ 'use strict'; -var async = require('async'), - validator = require('validator'), - nconf = require('nconf'), +var async = require('async'); +var validator = require('validator'); - user = require('../../user'), - groups = require('../../groups'), - plugins =require('../../plugins'), - meta = require('../../meta'), - utils = require('../../../public/src/utils'); +var user = require('../../user'); +var groups = require('../../groups'); +var plugins =require('../../plugins'); +var meta = require('../../meta'); +var utils = require('../../../public/src/utils'); var helpers = {}; @@ -103,6 +102,8 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) { userData['cover:url'] = userData['cover:url'] || require('../../coverPhoto').getDefaultProfileCover(userData.uid); userData['cover:position'] = userData['cover:position'] || '50% 50%'; + userData['username:disableEdit'] = !userData.isAdmin && parseInt(meta.config['username:disableEdit'], 10) === 1; + userData['email:disableEdit'] = !userData.isAdmin && parseInt(meta.config['email:disableEdit'], 10) === 1; next(null, userData); } diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 576276fe81..ba5e46986c 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -127,6 +127,10 @@ module.exports = function(SocketUser) { data.username = oldUserData.username; } + if (!isAdmin && parseInt(meta.config['email:disableEdit'], 10) === 1) { + data.email = oldUserData.email; + } + user.updateProfile(data.uid, data, next); }, function (userData, next) { diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index f1075b0c60..b02fe3f982 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -66,6 +66,12 @@ Disable username changes +
+ +