settings: Fix webapp password change UI.

Apparently, this has been broken since
dee4e3fb89, due to the beforeSend code
here overriding the default beforeSend function that sets the CSRF
token.  The correct fix was actually to just run the relevant code
directly before the channel.patch call.

Fixes #11938.
This commit is contained in:
Tim Abbott
2019-03-18 22:10:47 -07:00
parent 1fb079d63b
commit 8b739e4d0b

View File

@@ -326,42 +326,33 @@ exports.set_up = function () {
confirm_password: $('#confirm_password').val(),
};
var new_pw_field = $('#new_password');
var new_pw = data.new_password;
if (new_pw !== '') {
var password_ok = common.password_quality(new_pw, undefined, new_pw_field);
if (password_ok === undefined) {
// zxcvbn.js didn't load, for whatever reason.
settings_change_error(
'An internal error occurred; try reloading the page. ' +
'Sorry for the trouble!');
return;
} else if (!password_ok) {
settings_change_error(i18n.t('New password is too weak'));
return;
}
}
channel.patch({
url: "/json/settings",
data: data,
beforeSend: function () {
if (page_params.realm_password_auth_enabled !== false) {
// FIXME: Check that the two password fields match
// FIXME: Use the same jQuery validation plugin as the signup form?
var field = $('#new_password');
var new_pw = $('#new_password').val();
if (new_pw !== '') {
var password_ok = common.password_quality(new_pw, undefined, field);
if (password_ok === undefined) {
// zxcvbn.js didn't load, for whatever reason.
settings_change_error(
'An internal error occurred; try reloading the page. ' +
'Sorry for the trouble!');
return false;
} else if (!password_ok) {
settings_change_error(i18n.t('New password is too weak'));
return false;
}
}
}
return true;
},
success: function () {
settings_change_success(i18n.t("Updated settings!"));
overlays.close_modal('change_password_modal');
},
complete: function () {
// Whether successful or not, clear the password boxes.
// TODO: Clear these earlier, while the request is still pending.
clear_password_change();
},
error: function (xhr) {
ui_report.error(i18n.t("Failed"), xhr, change_password_info);
clear_password_change();
},
});
});