diff --git a/static/js/settings_account.js b/static/js/settings_account.js index 9edf20c440..2a0814ee8f 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -85,9 +85,10 @@ exports.set_up = function () { clear_password_change(); - $('#pw_change_link').on('click', function (e) { + $('#change_password').on('click', function (e) { e.preventDefault(); - $('#pw_change_link').hide(); + e.stopPropagation(); + overlays.open_modal('change_password_modal'); $('#pw_change_controls').show(); if (page_params.realm_password_auth_enabled !== false) { // zxcvbn.js is pretty big, and is only needed on password @@ -104,6 +105,57 @@ exports.set_up = function () { } }); + $('#change_password_button').on('click', function (e) { + e.preventDefault(); + e.stopPropagation(); + var change_password_info = $('#change_password_modal').find(".change_password_info").expectOne(); + + var data = { + old_password: $('#old_password').val(), + new_password: $('#new_password').val(), + confirm_password: $('#confirm_password').val(), + }; + + channel.patch({ + url: "/json/settings", + data: data, + beforeSubmit: 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); + }, + }); + }); + $('#new_password').on('change keyup', function () { var field = $('#new_password'); common.password_quality(field.val(), $('#pw_strength .bar'), field); @@ -111,39 +163,12 @@ exports.set_up = function () { $("form.your-account-settings").ajaxForm({ dataType: 'json', // This seems to be ignored. We still get back an xhr. - beforeSubmit: 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!")); }, error: function (xhr) { settings_change_error(i18n.t("Error changing settings"), xhr); }, - complete: function () { - // Whether successful or not, clear the password boxes. - // TODO: Clear these earlier, while the request is still pending. - clear_password_change(); - }, }); $('#change_email_button').on('click', function (e) { diff --git a/static/styles/components.css b/static/styles/components.css index a9decad317..179498a2d8 100644 --- a/static/styles/components.css +++ b/static/styles/components.css @@ -73,3 +73,31 @@ a.no-underline:hover { .ps:hover.ps--in-scrolling.ps--y > .ps__scrollbar-y-rail > .ps__scrollbar-y { background-color: #606060; } + +/* -- flex forms -- */ +.flex-row * { + box-sizing: border-box; +} + +.flex-row input[type=text], +.flex-row input[type=password] { + height: auto; + width: 100%; +} + +.flex-row { + display: flex; +} + +.flex-row.normal { + width: 500px; +} + +.flex-row .field { + margin: 10px 10px; + width: 100%; +} + +.flex-row .field + .field { + margin-left: 10px; +} diff --git a/static/styles/settings.css b/static/styles/settings.css index 17d0f1faef..825c03307c 100644 --- a/static/styles/settings.css +++ b/static/styles/settings.css @@ -1092,6 +1092,14 @@ input[type=checkbox].inline-block { cursor: pointer; } +#settings_page #change_password_modal { + width: auto; +} + +#settings_page #change_password_modal .change_password_info { + margin: 10px; +} + #deactivation_user_modal.fade.in { top: calc(50% - 120px); } diff --git a/static/styles/zulip.css b/static/styles/zulip.css index fdd5954454..c2918c67e2 100644 --- a/static/styles/zulip.css +++ b/static/styles/zulip.css @@ -2359,8 +2359,8 @@ button.topic_edit_cancel { /* FIXME: Combine this rule with the one in portico.css somehow? */ #pw_strength { - width: 220px; - height: 25px; + width: 100%; + height: 10px; margin-bottom: 0px; } diff --git a/static/templates/settings/account-settings.handlebars b/static/templates/settings/account-settings.handlebars index 6d0a8e7a42..e4775498e6 100644 --- a/static/templates/settings/account-settings.handlebars +++ b/static/templates/settings/account-settings.handlebars @@ -39,49 +39,62 @@ -