|
|
@ -16,6 +16,9 @@ module.exports = function (User) {
|
|
|
|
var fields = ['username', 'email', 'fullname', 'website', 'location',
|
|
|
|
var fields = ['username', 'email', 'fullname', 'website', 'location',
|
|
|
|
'groupTitle', 'birthday', 'signature', 'aboutme'];
|
|
|
|
'groupTitle', 'birthday', 'signature', 'aboutme'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var updateUid = data.uid;
|
|
|
|
|
|
|
|
var oldData;
|
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, next);
|
|
|
|
plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, next);
|
|
|
@ -27,14 +30,18 @@ module.exports = function (User) {
|
|
|
|
async.series([
|
|
|
|
async.series([
|
|
|
|
async.apply(isAboutMeValid, data),
|
|
|
|
async.apply(isAboutMeValid, data),
|
|
|
|
async.apply(isSignatureValid, data),
|
|
|
|
async.apply(isSignatureValid, data),
|
|
|
|
async.apply(isEmailAvailable, data, uid),
|
|
|
|
async.apply(isEmailAvailable, data, updateUid),
|
|
|
|
async.apply(isUsernameAvailable, data, uid),
|
|
|
|
async.apply(isUsernameAvailable, data, updateUid),
|
|
|
|
async.apply(isGroupTitleValid, data)
|
|
|
|
async.apply(isGroupTitleValid, data)
|
|
|
|
], function (err) {
|
|
|
|
], function (err) {
|
|
|
|
next(err);
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
User.getUserFields(updateUid, fields, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (_oldData, next) {
|
|
|
|
|
|
|
|
oldData = _oldData;
|
|
|
|
async.each(fields, function (field, next) {
|
|
|
|
async.each(fields, function (field, next) {
|
|
|
|
if (!(data[field] !== undefined && typeof data[field] === 'string')) {
|
|
|
|
if (!(data[field] !== undefined && typeof data[field] === 'string')) {
|
|
|
|
return next();
|
|
|
|
return next();
|
|
|
@ -43,21 +50,20 @@ module.exports = function (User) {
|
|
|
|
data[field] = data[field].trim();
|
|
|
|
data[field] = data[field].trim();
|
|
|
|
|
|
|
|
|
|
|
|
if (field === 'email') {
|
|
|
|
if (field === 'email') {
|
|
|
|
return updateEmail(uid, data.email, next);
|
|
|
|
return updateEmail(updateUid, data.email, next);
|
|
|
|
} else if (field === 'username') {
|
|
|
|
} else if (field === 'username') {
|
|
|
|
return updateUsername(uid, data.username, next);
|
|
|
|
return updateUsername(updateUid, data.username, next);
|
|
|
|
} else if (field === 'fullname') {
|
|
|
|
} else if (field === 'fullname') {
|
|
|
|
return updateFullname(uid, data.fullname, next);
|
|
|
|
return updateFullname(updateUid, data.fullname, next);
|
|
|
|
} else if (field === 'signature') {
|
|
|
|
} else if (field === 'signature') {
|
|
|
|
data[field] = S(data[field]).stripTags().s;
|
|
|
|
data[field] = S(data[field]).stripTags().s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
User.setUserField(uid, field, data[field], next);
|
|
|
|
User.setUserField(updateUid, field, data[field], next);
|
|
|
|
}, next);
|
|
|
|
}, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
plugins.fireHook('action:user.updateProfile', {data: data, uid: uid});
|
|
|
|
User.getUserFields(updateUid, ['email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor'], next);
|
|
|
|
User.getUserFields(uid, ['email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor'], next);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|