From 0c8aa599a0b66ef19667c6aaa2aea73d2b1e5bb8 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 11 Jan 2017 14:40:52 +0300 Subject: [PATCH] closes #5357 --- src/socket.io/user/profile.js | 2 +- src/user/profile.js | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 8a59fbbff2..fbd9632ed6 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -148,7 +148,7 @@ module.exports = function (SocketUser) { data.email = oldUserData.email; } - user.updateProfile(data.uid, data, next); + user.updateProfile(socket.uid, data, next); }, function (userData, next) { function log(type, eventData) { diff --git a/src/user/profile.js b/src/user/profile.js index 37b280612f..01caa931cf 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -16,6 +16,9 @@ module.exports = function (User) { var fields = ['username', 'email', 'fullname', 'website', 'location', 'groupTitle', 'birthday', 'signature', 'aboutme']; + var updateUid = data.uid; + var oldData; + async.waterfall([ function (next) { plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, next); @@ -27,14 +30,18 @@ module.exports = function (User) { async.series([ async.apply(isAboutMeValid, data), async.apply(isSignatureValid, data), - async.apply(isEmailAvailable, data, uid), - async.apply(isUsernameAvailable, data, uid), + async.apply(isEmailAvailable, data, updateUid), + async.apply(isUsernameAvailable, data, updateUid), async.apply(isGroupTitleValid, data) ], function (err) { next(err); }); }, function (next) { + User.getUserFields(updateUid, fields, next); + }, + function (_oldData, next) { + oldData = _oldData; async.each(fields, function (field, next) { if (!(data[field] !== undefined && typeof data[field] === 'string')) { return next(); @@ -43,21 +50,20 @@ module.exports = function (User) { data[field] = data[field].trim(); if (field === 'email') { - return updateEmail(uid, data.email, next); + return updateEmail(updateUid, data.email, next); } else if (field === 'username') { - return updateUsername(uid, data.username, next); + return updateUsername(updateUid, data.username, next); } else if (field === 'fullname') { - return updateFullname(uid, data.fullname, next); + return updateFullname(updateUid, data.fullname, next); } else if (field === 'signature') { data[field] = S(data[field]).stripTags().s; } - User.setUserField(uid, field, data[field], next); + User.setUserField(updateUid, field, data[field], next); }, next); }, function (next) { - plugins.fireHook('action:user.updateProfile', {data: data, uid: uid}); - User.getUserFields(uid, ['email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor'], next); + User.getUserFields(updateUid, ['email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor'], next); } ], callback); };