Skip to content

Node.js based forum software built for the modern web

closes #5357

barisusakli0c8aa599a0b6
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);
};