allow changing username if user has no password set, ie sso login

This commit is contained in:
barisusakli
2015-10-22 17:37:24 -04:00
parent 0210c033ee
commit 28ae101d90
2 changed files with 10 additions and 7 deletions

View File

@@ -25,12 +25,9 @@ module.exports = function(SocketUser) {
function isAdminOrSelfAndPasswordMatch(uid, data, callback) {
async.parallel({
isAdmin: function(next) {
user.isAdministrator(uid, next);
},
passwordMatch: function(next) {
user.isPasswordCorrect(data.uid, data.password, next);
}
isAdmin: async.apply(user.isAdministrator, uid),
hasPassword: async.apply(user.hasPassword, data.uid),
passwordMatch: async.apply(user.isPasswordCorrect, data.uid, data.password)
}, function(err, results) {
if (err) {
return callback(err);
@@ -41,7 +38,7 @@ module.exports = function(SocketUser) {
return callback(new Error('[[error:no-privileges]]'));
}
if (self && !results.passwordMatch) {
if (self && results.hasPassword && !results.passwordMatch) {
return callback(new Error('[[error:invalid-password]]'));
}

View File

@@ -25,4 +25,10 @@ module.exports = function(User) {
});
};
User.hasPassword = function(uid, callback) {
db.getObjectField('user:' + uid, 'password', function(err, hashedPassword) {
callback(err, !!hashedPassword);
});
};
};