diff --git a/resources/static/pages/manage_account.js b/resources/static/pages/manage_account.js index 59bc9ccc3154516c4956f224e02b4e13ecff9938..d32521a157c0a7bf064fafd1fabbe2cf5228d47f 100644 --- a/resources/static/pages/manage_account.js +++ b/resources/static/pages/manage_account.js @@ -124,6 +124,8 @@ BrowserID.manageAccount = (function() { user.changePassword(oldPassword, newPassword, function(status) { if(status) { dom.removeClass("#edit_password", "edit"); + dom.setInner("#old_password", ""); + dom.setInner("#new_password", ""); } else { tooltip.showTooltip("#tooltipInvalidPassword"); @@ -141,6 +143,10 @@ BrowserID.manageAccount = (function() { tooltip.showTooltip("#tooltipNewRequired"); complete(false); } + else if(newPassword === oldPassword) { + tooltip.showTooltip("#tooltipPasswordsSame"); + complete(false); + } else if(newPassword.length < 8 || 80 < newPassword.length) { tooltip.showTooltip("#tooltipPasswordLength"); complete(false); diff --git a/resources/static/test/cases/pages/manage_account.js b/resources/static/test/cases/pages/manage_account.js index 5e1ddb2cca1febf5e0cf97fb6230366a44b176ab..fc01f8f09fe5530f120b7353c1868c59b47d6b16 100644 --- a/resources/static/test/cases/pages/manage_account.js +++ b/resources/static/test/cases/pages/manage_account.js @@ -227,6 +227,19 @@ }); }); + asyncTest("changePassword with same old and new password - tooltip", function() { + bid.manageAccount(mocks, function() { + $("#old_password").val("password"); + $("#new_password").val("password"); + + bid.manageAccount.changePassword(function(status) { + equal(status, false, "do not update when old and new passwords are the same"); + testHelpers.testTooltipVisible(); + start(); + }); + }); + }); + asyncTest("changePassword with XHR error - error message", function() { bid.manageAccount(mocks, function() { xhr.useResult("invalid"); @@ -242,7 +255,6 @@ }); asyncTest("changePassword with user authenticated to password level, happy case", function() { - bid.manageAccount(mocks, function() { $("#old_password").val("oldpassword"); $("#new_password").val("newpassword"); @@ -250,6 +262,10 @@ bid.manageAccount.changePassword(function(status) { equal(status, true, "on proper completion, status is true"); equal(tooltip.shown, false, "on proper completion, tooltip is not shown"); + + equal($("#old_password").val(), "", "old_password field is cleared"); + equal($("#new_password").val(), "", "new_password field is cleared"); + start(); }); }); diff --git a/resources/views/index.ejs b/resources/views/index.ejs index 6b1f49aec9e17322ae8d9f2f5d9c3ce2d079850c..ae7f6f49cbdfe1d6b7cd73297986e42ea86c73a7 100644 --- a/resources/views/index.ejs +++ b/resources/views/index.ejs @@ -52,6 +52,7 @@ <div class="tooltip" for="old_password" id="tooltipOldRequired">Old password is required.</div> <div class="tooltip" for="old_password" id="tooltipInvalidPassword">Incorrect old password, password not updated.</div> <div class="tooltip" for="new_password" id="tooltipNewRequired">New password is required.</div> + <div class="tooltip" for="new_password" id="tooltipPasswordsSame">Old and new passwords are the same.</div> <div class="tooltip" for="new_password" id="tooltipPasswordLength">Password must be between 8 and 80 characters long.</div> </form> </section>