diff --git a/resources/static/dialog/controllers/authenticate_controller.js b/resources/static/dialog/controllers/authenticate_controller.js index 380fa48ed9e5224b005d2b30a71ccec2bcfba81c..c025f0e65cb942f13be574f18f970f5ef6d595de 100644 --- a/resources/static/dialog/controllers/authenticate_controller.js +++ b/resources/static/dialog/controllers/authenticate_controller.js @@ -75,18 +75,9 @@ cancelEvent(event); - if (!validation.email(email)) return; - - user.createUser(email, function(staged) { - if (staged) { - self.close("user_staged", { - email: email - }); - } - else { - tooltip.showTooltip("#could_not_add"); - } - }, self.getErrorDialog(errors.createUser)); + if(email) { + helpers.createUser.call(self, email); + } } function authenticate(el, event) { @@ -106,16 +97,13 @@ } function resetPassword(el, event) { - var email = getEmail(), - self=this; + var email = getEmail(); cancelEvent(event); - user.requestPasswordReset(email, function() { - self.close("reset_password", { - email: email - }); - }, self.getErrorDialog(errors.requestPasswordReset)); + if(email) { + helpers.resetPassword.call(this, email); + } } function animateSwap(fadeOutSelector, fadeInSelector, callback) { diff --git a/resources/static/dialog/controllers/page_controller.js b/resources/static/dialog/controllers/page_controller.js index 8634c4a6721be594a4ae0ce0f859505e042cb369..816724e04acd5596d6c7c68911ab34edbcfc5c07 100644 --- a/resources/static/dialog/controllers/page_controller.js +++ b/resources/static/dialog/controllers/page_controller.js @@ -102,7 +102,7 @@ $("#error").stop().css('opacity', 1).hide().fadeIn(ANIMATION_TIME); /** - * TODO What a big steaming pile, use CSS animations for this! + * TODO XXX - Use the error-display for this. */ dom.bindEvent("#openMoreInfo", "click", function(event) { event.preventDefault(); diff --git a/resources/static/dialog/controllers/pickemail_controller.js b/resources/static/dialog/controllers/pickemail_controller.js index c11253376646e6191085c949567e6df05dc044b5..987756cd63d4c935447c9c11d7c4ab02fee3da3a 100644 --- a/resources/static/dialog/controllers/pickemail_controller.js +++ b/resources/static/dialog/controllers/pickemail_controller.js @@ -129,18 +129,7 @@ bid.Tooltip.showTooltip("#already_taken"); } else { - user.addEmail(email, function(added) { - if (added) { - self.close("email_staged", { - email: email - }); - } - else { - bid.Tooltip.showTooltip("#could_not_add"); - } - }, function onFailure() { - bid.Tooltip.showTooltip("#could_not_add"); - }); + helpers.addEmail.call(self, email); } }, self.getErrorDialog(errors.isEmailRegistered)); } diff --git a/resources/static/dialog/controllers/required_email_controller.js b/resources/static/dialog/controllers/required_email_controller.js index 3cb3dc26db70fed0dd58f608fb780bce7c724361..0e6dfea3d017d9e529c3a51e9f32f4ef46eb8595 100644 --- a/resources/static/dialog/controllers/required_email_controller.js +++ b/resources/static/dialog/controllers/required_email_controller.js @@ -74,15 +74,41 @@ } function verifyAddress(event) { - event.preventDefault(); + // By being in the verifyAddress, we know that the current user has not + // been shown the password box and we have to do a verification of some + // sort. This will be either an add email to the current account or a new + // registration. + + event && event.preventDefault(); + var self=this; + if(self.authenticated) { + // If we are veryifying an address and the user is authenticated, it + // means that the current user does not have control of the address. + // If the address is registered, it means another account has control of + // the address and we are consolidating. If the email is not registered + // then it means add the address to the current user's account. + helpers.addEmail.call(self, self.email); + } + else { + helpers.createUser.call(self, self.email); + } } function forgotPassword(event) { - event.preventDefault(); + event && event.preventDefault(); + + var self=this; + helpers.resetPassword.call(self, self.email); } + function cancel(event) { + event && event.preventDefault(); + + this.close("cancel"); + } + PageController.extend("Requiredemail", {}, { start: function(options) { var self=this, @@ -121,6 +147,7 @@ dom.bindEvent("#sign_in", "click", signIn.bind(self)); dom.bindEvent("#verify_address", "click", verifyAddress.bind(self)); dom.bindEvent("#forgotPassword", "click", forgotPassword.bind(self)); + dom.bindEvent("#cancel", "click", cancel.bind(self)); } self._super(); @@ -130,13 +157,15 @@ dom.unbindEvent("#sign_in", "click"); dom.unbindEvent("#verify_address", "click"); dom.unbindEvent("#forgotPassword", "click"); + dom.unbindEvent("#cancel", "click"); this._super(); }, signIn: signIn, verifyAddress: verifyAddress, - forgotPassword: forgotPassword + forgotPassword: forgotPassword, + cancel: cancel }); }()); diff --git a/resources/static/dialog/views/requiredemail.ejs b/resources/static/dialog/views/requiredemail.ejs index f1741c602bc81b23c8565d19503600c5a3031133..20c55295941d6c9f268d36526e53eef57dccd0fe 100644 --- a/resources/static/dialog/views/requiredemail.ejs +++ b/resources/static/dialog/views/requiredemail.ejs @@ -24,6 +24,10 @@ <div id="cannot_authenticate" class="tooltip" for="password"> 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> <% } %> @@ -36,6 +40,6 @@ <button id="verify_address" tabindex="3">verify email</button> <% } %> - <button id="cancel_stage" tabindex="4">cancel</button> + <button id="cancel" tabindex="4">cancel</button> </div> </div> diff --git a/resources/static/shared/helpers.js b/resources/static/shared/helpers.js index 4deabe88ceb5cfadb03c8ede9cad1c49a31fb121..7a709f62d4ee1cc54256818ceaaa980113e3d83d 100644 --- a/resources/static/shared/helpers.js +++ b/resources/static/shared/helpers.js @@ -112,6 +112,45 @@ }, self.getErrorDialog(errors.authenticate)); } + function createUser(email) { + var self=this; + user.createUser(email, function(staged) { + if (staged) { + self.close("user_staged", { + email: email + }); + } + else { + tooltip.showTooltip("#could_not_add"); + } + }, self.getErrorDialog(errors.createUser)); + } + + function resetPassword(email) { + var self=this; + user.requestPasswordReset(email, function() { + self.close("reset_password", { + email: email + }); + }, self.getErrorDialog(errors.requestPasswordReset)); + } + + function addEmail(email) { + var self=this; + user.addEmail(email, function(added) { + if (added) { + self.close("email_staged", { + email: email + }); + } + else { + bid.Tooltip.showTooltip("#could_not_add"); + } + }, function onFailure() { + bid.Tooltip.showTooltip("#could_not_add"); + }); + } + extend(helpers, { /** * Extend an object with the properties of another object. Overwrites @@ -138,8 +177,15 @@ */ getAndValidatePassword: getAndValidatePassword, + /** + * XXX Get from here down out of here and into a specific dialog helpers + * module. + */ getAssertion: getAssertion, - authenticateUser: authenticateUser + authenticateUser: authenticateUser, + createUser: createUser, + addEmail: addEmail, + resetPassword: resetPassword }); 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 67319c9a7596a66e4e9a2b4dc2810e199e4fd2cd..3234b358f5a09c70fe78e13d895955ab5f9dfa9b 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 @@ -168,19 +168,19 @@ steal.then(function() { testSignIn(email, testNoPasswordSection); }); - test("user who is authenticated, email does not belong to user", function() { + test("user who is authenticated, email belongs to another user", function() { xhr.setContextInfo({ authenticated: true }); var email = "registered@testuser.com"; - user.removeEmail(email, function() { - controller = el.requiredemail({ - email: email, - authenticated: true - }).controller(); - }); + controller = el.requiredemail({ + email: email, + authenticated: true + }).controller(); + // This means the current user is going to take the address from the other + // account. testVerify(email); }); @@ -278,5 +278,87 @@ steal.then(function() { stop(); }); + function testMessageReceived(email, message) { + var authenticated = true; + + xhr.setContextInfo({ + authenticated: authenticated + }); + + controller = el.requiredemail({ + email: email, + authenticated: authenticated + }).controller(); + + + subscribe(message, function(item, info) { + equal(info.email, email, message + " received with correct email"); + start(); + }); + + controller.verifyAddress(); + stop(); + } + + test("verifyAddress of authenticated user, address belongs to another user", function() { + var email = "registered@testuser.com"; + + testMessageReceived(email, "email_staged"); + }); + + test("verifyAddress of authenticated user, unknown address", function() { + var email = "unregistered@testuser.com"; + + testMessageReceived(email, "email_staged"); + }); + + test("verifyAddress of un-authenticated user, forgot password", 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) { + equal(info.email, email, message + " received with correct email"); + start(); + }); + + controller.forgotPassword(); + stop(); + }); + + test("cancel raises the cancel message", function() { + var email = "registered@testuser.com", + message = "cancel", + authenticated = false; + + xhr.setContextInfo({ + authenticated: authenticated + }); + + controller = el.requiredemail({ + email: email, + authenticated: authenticated + }).controller(); + + + subscribe(message, function(item, info) { + ok(true, message + " received"); + start(); + }); + + controller.cancel(); + stop(); + }); + });