From 28ae101d90d77d0d272d4ca9951bd904c5ab3828 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 22 Oct 2015 17:37:24 -0400 Subject: [PATCH] allow changing username if user has no password set, ie sso login --- src/socket.io/user/profile.js | 11 ++++------- src/user/password.js | 6 ++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 396fb0b265..1661eac92c 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -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]]')); } diff --git a/src/user/password.js b/src/user/password.js index 0c15cd07e7..b326313be4 100644 --- a/src/user/password.js +++ b/src/user/password.js @@ -25,4 +25,10 @@ module.exports = function(User) { }); }; + User.hasPassword = function(uid, callback) { + db.getObjectField('user:' + uid, 'password', function(err, hashedPassword) { + callback(err, !!hashedPassword); + }); + }; + }; \ No newline at end of file