diff --git a/browserid/static/dialog/controllers/checkregistration_controller.js b/browserid/static/dialog/controllers/checkregistration_controller.js index 518e6939e3118b497aed3b86c38d0f369bde517f..99842208c510da0df12f54b18ec092dc2ac0be61 100644 --- a/browserid/static/dialog/controllers/checkregistration_controller.js +++ b/browserid/static/dialog/controllers/checkregistration_controller.js @@ -80,7 +80,7 @@ // enable button $('#continue_button').removeClass('disabled'); - self.publish("checkregistration:confirmed"); + self.close("checkregistration:confirmed"); } else if (status === 'pending') { // try again, what else can we do? self.setupRegCheck(); diff --git a/browserid/static/dialog/resources/browserid-network.js b/browserid/static/dialog/resources/browserid-network.js index 11851fbe66bd548a7cd9f0cf57eb05f93a802468..247f32b60109098399aa8048b5d91b754795c4f4 100644 --- a/browserid/static/dialog/resources/browserid-network.js +++ b/browserid/static/dialog/resources/browserid-network.js @@ -159,6 +159,30 @@ var BrowserIDNetwork = (function() { }); }, + /** + * Call with a token to prove an email address ownership. + * @method proveEmailOwnership + * @param {string} token - token proving email ownership. + * @param {function} [onSuccess] - Callback to call when complete. Called + * with one boolean parameter that specifies the validity of the token. + * @param {function} [onFailure] - Called on XHR failure. + */ + proveEmailOwnership: function(token, onSuccess, onFailure) { + $.ajax({ + url: '/wsapi/prove_email_ownership', + data: { + token: token + }, + success: function(status, textStatus, jqXHR) { + if (onSuccess) { + var valid = JSON.parse(status); + onSuccess(valid); + } + }, + error: onFailure + }); + }, + /** * Cancel the current user's account. * @method cancelUser diff --git a/browserid/static/dialog/test/qunit/browserid-network_test.js b/browserid/static/dialog/test/qunit/browserid-network_test.js index 2ce1d4e659b68a13fb9e909f06b7c5ed7e3a53f8..96f9aa2bdec9218bcf08dfe87caa49b75c3efca6 100644 --- a/browserid/static/dialog/test/qunit/browserid-network_test.js +++ b/browserid/static/dialog/test/qunit/browserid-network_test.js @@ -105,6 +105,25 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/browserid-netw stop(); }); + + test("prove_email_ownership with valid login cookie but invalid token", function() { + BrowserIDNetwork.authenticate("testuser@testuser.com", "testuser", function onSuccess(authenticated) { + var token = "badtoken"; + BrowserIDNetwork.proveEmailOwnership(token, function onSuccess(proven) { + equal(proven, false, "bad token could not be proved"); + start(); + }, function onFailure() { + start(); + }); + }); + + stop(); + }); + + test("prove_email_ownership without valid login cookie", function() { + + }); + test("stageUser", function() { ok(true, "stageUser"); }); diff --git a/browserid/views/prove.ejs b/browserid/views/prove.ejs index d3fdddbd3a142ba39bb5faea29332faae4ec3aa6..0ec15a600acbd336a229e5f78ac727cf26d4c741 100644 --- a/browserid/views/prove.ejs +++ b/browserid/views/prove.ejs @@ -31,23 +31,20 @@ function success() { } function failure(why) { - $("div.status").text("Error encountered while attempting to confirm your address. please try again. (error message: " + why + ")"); + $("div.status").text("Error encountered while attempting to confirm your address. Have you previously verified this address?"); } -$(document).ready(function() { - $.ajax({ - url: '/wsapi/prove_email_ownership?token=' + getParameterByName('token'), - success: function(status, textStatus, jqXHR) { - var obj = JSON.parse(status); - if (obj) { +$(function() { + var token = getParameterByName("token"); + BrowserIDNetwork.proveEmailOwnership(token, function onSuccess(valid) { + if (valid) { success(); } else { failure("unknown"); } - }, - error: function() { + + }, function onFailure() { failure("Error Communicating With Server!"); - } }); });