mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-23 17:00:24 +01:00
closes #6124
This commit is contained in:
@@ -196,7 +196,7 @@ module.exports = function (User) {
|
|||||||
|
|
||||||
function updateUsername(uid, newUsername, callback) {
|
function updateUsername(uid, newUsername, callback) {
|
||||||
if (!newUsername) {
|
if (!newUsername) {
|
||||||
return callback();
|
return setImmediate(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -204,6 +204,9 @@ module.exports = function (User) {
|
|||||||
User.getUserFields(uid, ['username', 'userslug'], next);
|
User.getUserFields(uid, ['username', 'userslug'], next);
|
||||||
},
|
},
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
|
if (userData.username === newUsername) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function (next) {
|
function (next) {
|
||||||
updateUidMapping('username', uid, newUsername, userData.username, next);
|
updateUidMapping('username', uid, newUsername, userData.username, next);
|
||||||
|
|||||||
13
test/user.js
13
test/user.js
@@ -627,6 +627,19 @@ describe('User', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not update a user\'s username if it did not change', function (done) {
|
||||||
|
socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, username: 'updatedAgain', password: '123456' }, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
db.getSortedSetRevRange('user:' + uid + ':usernames', 0, -1, function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
console.log(data);
|
||||||
|
assert(data[0].startsWith('updatedAgain'));
|
||||||
|
assert(data[1].startsWith('updatedUserName'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should change email', function (done) {
|
it('should change email', function (done) {
|
||||||
socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, email: 'updatedAgain@me.com', password: '123456' }, function (err) {
|
socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, email: 'updatedAgain@me.com', password: '123456' }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user