added a new property to userData "hasPassword", disabling "current password" field in user editing if no password is set (for SSO logins, for example)

v1.18.x
Julian Lam 11 years ago
parent 4a1513eabf
commit e9e53ad95e

@ -189,8 +189,7 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
password_confirm.on('blur', onPasswordConfirmChanged); password_confirm.on('blur', onPasswordConfirmChanged);
$('#changePasswordBtn').on('click', function() { $('#changePasswordBtn').on('click', function() {
if ((passwordvalid && passwordsmatch) || app.isAdmin) {
if (passwordvalid && passwordsmatch && (currentPassword.val() || app.isAdmin)) {
socket.emit('user.changePassword', { socket.emit('user.changePassword', {
'currentPassword': currentPassword.val(), 'currentPassword': currentPassword.val(),
'newPassword': password.val(), 'newPassword': password.val(),

@ -115,7 +115,7 @@
<div class="control-group"> <div class="control-group">
<label class="control-label" for="inputCurrentPassword">[[user:current_password]]</label> <label class="control-label" for="inputCurrentPassword">[[user:current_password]]</label>
<div class="controls"> <div class="controls">
<input class="form-control" type="password" id="inputCurrentPassword" placeholder="Current Password" value=""> <input class="form-control" type="password" id="inputCurrentPassword" placeholder="Current Password" value=""<!-- IF !hasPassword --> disabled<!-- ENDIF !hasPassword-->>
</div> </div>
</div> </div>

@ -185,8 +185,13 @@ var bcrypt = require('bcryptjs'),
return callback(err); return callback(err);
} }
if (data && data.password) { if (data) {
delete data.password; if (data.password) {
delete data.password;
data.hasPassword = true;
} else {
data.hasPassword = false;
}
} }
callback(err, data); callback(err, data);
}); });
@ -467,13 +472,18 @@ var bcrypt = require('bcryptjs'),
return callback(err); return callback(err);
} }
bcrypt.compare(data.currentPassword, currentPassword, function(err, res) { if (currentPassword !== null) {
if (err || !res) { bcrypt.compare(data.currentPassword, currentPassword, function(err, res) {
return callback(err || new Error('Your current password is not correct!')); if (err || !res) {
} return callback(err || new Error('Your current password is not correct!'));
}
hashAndSetPassword(callback);
});
} else {
// No password in account (probably SSO login)
hashAndSetPassword(callback); hashAndSetPassword(callback);
}); }
}); });
} }
}; };

Loading…
Cancel
Save