diff --git a/resources/static/dialog/views/requiredemail.ejs b/resources/static/dialog/views/requiredemail.ejs index da1a1fc86aa194a1895d90e702eeac485d84d81e..932a600a33def4056e98456223b69d41e1c5ee03 100644 --- a/resources/static/dialog/views/requiredemail.ejs +++ b/resources/static/dialog/views/requiredemail.ejs @@ -4,16 +4,18 @@ The site requested you sign in with <div id="required_email"><%= email %></div> + <div id="could_not_add" class="tooltip" for="required_email"> + We just sent an email to that address! If you really want to send another, wait a minute or two and try again. + </div> <% if (showPassword) { %> <li id="password_section"> - <label for="password" class="half serif">Password</label> <div class="half right"> <a id="forgotPassword" href="#" tabindex="4">forgot your password?</a> </div> - <input id="password" class="sans" type="password" maxlength="80" tabindex="2" /> + <input id="password" class="sans" type="password" maxlength="80" tabindex="2" /> <div id="password_required" class="tooltip" for="password"> The password field is required. @@ -23,9 +25,6 @@ The account cannot be logged in with this username and password. </div> - <div id="could_not_add" class="tooltip" for="password"> - We just sent an email to that address! If you really want to send another, wait a minute or two and try again. - </div> </li> <% } %> diff --git a/resources/static/shared/helpers.js b/resources/static/shared/helpers.js index 7a709f62d4ee1cc54256818ceaaa980113e3d83d..339211313ae841c31b5f31793291f63d94175bc9 100644 --- a/resources/static/shared/helpers.js +++ b/resources/static/shared/helpers.js @@ -40,6 +40,7 @@ dom = bid.DOM, user = bid.User, errors = bid.Errors, + tooltip = bid.Tooltip, validation = bid.Validation, helpers = bid.Helpers = bid.Helpers || {}; @@ -107,7 +108,7 @@ if (authenticated) { callback(); } else { - bid.Tooltip.showTooltip("#cannot_authenticate"); + tooltip.showTooltip("#cannot_authenticate"); } }, self.getErrorDialog(errors.authenticate)); } @@ -128,10 +129,15 @@ function resetPassword(email) { var self=this; - user.requestPasswordReset(email, function() { - self.close("reset_password", { - email: email - }); + user.requestPasswordReset(email, function(status) { + if(status.success) { + self.close("reset_password", { + email: email + }); + } + else { + tooltip.showTooltip("#could_not_add"); + } }, self.getErrorDialog(errors.requestPasswordReset)); } @@ -144,10 +150,10 @@ }); } else { - bid.Tooltip.showTooltip("#could_not_add"); + tooltip.showTooltip("#could_not_add"); } }, function onFailure() { - bid.Tooltip.showTooltip("#could_not_add"); + tooltip.showTooltip("#could_not_add"); }); } diff --git a/resources/static/shared/tooltip.js b/resources/static/shared/tooltip.js index 8800b6ceafe47aed1e30d334685c369b37af45c6..de21963fa670744a98dfcefd1dcc443da7d6f4d9 100644 --- a/resources/static/shared/tooltip.js +++ b/resources/static/shared/tooltip.js @@ -43,7 +43,8 @@ BrowserID.Tooltip = (function() { READ_WPM = 200, bid = BrowserID, dom = bid.DOM, - renderer = bid.Renderer; + renderer = bid.Renderer, + lastTooltip; function createTooltip(el) { var contents = el.html(); @@ -71,9 +72,13 @@ BrowserID.Tooltip = (function() { var wordTimeMS = (words / READ_WPM) * 60 * 1000; var displayTimeMS = Math.max(wordTimeMS, TOOLTIP_DISPLAY); + bid.Tooltip.shown = true; el.fadeIn(ANIMATION_TIME, function() { setTimeout(function() { - el.fadeOut(ANIMATION_TIME, complete); + el.fadeOut(ANIMATION_TIME, function() { + bid.Tooltip.shown = false; + if(complete) complete(); + }); }, displayTimeMS); }); } diff --git a/resources/static/test/qunit/controllers/required_email_controller_unit_test.js b/resources/static/test/qunit/controllers/required_email_controller_unit_test.js index 3234b358f5a09c70fe78e13d895955ab5f9dfa9b..cb9463994026fc308b5f2e3a69de921fdbceda8c 100644 --- a/resources/static/test/qunit/controllers/required_email_controller_unit_test.js +++ b/resources/static/test/qunit/controllers/required_email_controller_unit_test.js @@ -69,6 +69,7 @@ steal.then(function() { xhr.setContextInfo({ authenticated: false }); + $("#required_email").text(""); }, teardown: function() { @@ -92,7 +93,7 @@ steal.then(function() { equal($("#verify_address").length, 0, "verify address not shows"); cb && cb(); start(); - }, 100); + }, 200); stop(); } @@ -104,7 +105,7 @@ steal.then(function() { testNoPasswordSection(); cb && cb(); start(); - }, 100); + }, 200); stop(); } @@ -336,6 +337,35 @@ steal.then(function() { stop(); }); + test("verifyAddress of un-authenticated user, forgot password, mail throttled", function() { + var email = "registered@testuser.com", + authenticated = false, + message = "reset_password"; + + xhr.setContextInfo({ + authenticated: authenticated + }); + + controller = el.requiredemail({ + email: email, + authenticated: authenticated + }).controller(); + + + subscribe(message, function(item, info) { + ok(false, "throttling should have prevented close from happening"); + }); + + xhr.useResult("throttle"); + controller.forgotPassword(); + + setTimeout(function() { + ok(bid.Tooltip.shown, "tooltip is shown"); + start(); + }, 100); + stop(); + }); + test("cancel raises the cancel message", function() { var email = "registered@testuser.com", message = "cancel", diff --git a/resources/static/test/qunit/shared/tooltip_unit_test.js b/resources/static/test/qunit/shared/tooltip_unit_test.js index 3dde6b3d3cef4d66069524f68549c9fc3ac442c5..70eaf5a5f86dd7a993f3e326f6c4b32486833ab5 100644 --- a/resources/static/test/qunit/shared/tooltip_unit_test.js +++ b/resources/static/test/qunit/shared/tooltip_unit_test.js @@ -56,9 +56,13 @@ steal.then(function() { var diff = endTime - startTime; ok(2000 <= diff && diff <= 3000, diff + " - minimum of 2 seconds, max of 3 seconds"); + equal(tooltip.shown, false, "tooltip says it is no longer shown"); + start(); }); + equal(tooltip.shown, true, "tooltip says that it is shown"); + stop(); });