From 6a3d801ffc5ecc3c38e695b0c8d18ba1b2adbe9b Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Tue, 10 Jul 2012 10:34:45 +0100 Subject: [PATCH] Update user.createSecondaryUser to use stageAddressVerification. rename stageAddressVerification to handleStageAddressVerificationResponse. --- resources/static/common/js/user.js | 16 +++++----------- resources/static/dialog/js/misc/helpers.js | 2 +- resources/static/pages/js/signup.js | 2 +- resources/static/test/cases/common/js/user.js | 7 +++++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/resources/static/common/js/user.js b/resources/static/common/js/user.js index e0783c165..0f08cc829 100644 --- a/resources/static/common/js/user.js +++ b/resources/static/common/js/user.js @@ -101,7 +101,7 @@ BrowserID.User = (function() { } } - function stageAddressVerification(onComplete, staged) { + function handleStageAddressVerifictionResponse(onComplete, staged) { var status = { success: staged }; if (!staged) status.reason = "throttle"; @@ -349,14 +349,8 @@ BrowserID.User = (function() { * @param {function} [onFailure] - Called on error. */ createSecondaryUser: function(email, password, onComplete, onFailure) { - // set - XXX Use stageAddressVerification to handle the response. - network.createUser(email, password, origin, function(created) { - // Used on the main site when the user verifies - once verification - // is complete, the user is redirected back to the RP and logged in. - var site = User.getReturnTo(); - if (created && site) storage.setReturnTo(site); - complete(onComplete, created); - }, onFailure); + network.createUser(email, password, origin, + handleStageAddressVerifictionResponse.curry(onComplete), onFailure); }, /** @@ -617,7 +611,7 @@ BrowserID.User = (function() { User.isEmailRegistered(email, function(registered) { if (registered) { network.requestPasswordReset(email, password, origin, - stageAddressVerification.curry(onComplete), onFailure); + handleStageAddressVerifictionResponse.curry(onComplete), onFailure); } else if (onComplete) { onComplete({ success: false, reason: "invalid_user" }); @@ -672,7 +666,7 @@ BrowserID.User = (function() { else if (!idInfo.verified) { // this address is unverified, try to reverify it. network.requestEmailReverify(email, origin, - stageAddressVerification.curry(onComplete), onFailure); + handleStageAddressVerifictionResponse.curry(onComplete), onFailure); } }, diff --git a/resources/static/dialog/js/misc/helpers.js b/resources/static/dialog/js/misc/helpers.js index e7626e652..949eac7a2 100644 --- a/resources/static/dialog/js/misc/helpers.js +++ b/resources/static/dialog/js/misc/helpers.js @@ -74,7 +74,7 @@ function createUser(email, password, callback) { var self=this; user.createSecondaryUser(email, password, function(status) { - if (status) { + if (status.success) { var info = { email: email, password: password }; self.publish("user_staged", info, info); complete(callback, true); diff --git a/resources/static/pages/js/signup.js b/resources/static/pages/js/signup.js index d7d4049ba..49677c8e4 100644 --- a/resources/static/pages/js/signup.js +++ b/resources/static/pages/js/signup.js @@ -80,7 +80,7 @@ BrowserID.signUp = (function() { if(valid) { user.createSecondaryUser(this.emailToStage, pass, function(status) { - if(status) { + if(status.success) { pageHelpers.emailSent(oncomplete && oncomplete.curry(true)); } else { diff --git a/resources/static/test/cases/common/js/user.js b/resources/static/test/cases/common/js/user.js index 7138f225a..744368369 100644 --- a/resources/static/test/cases/common/js/user.js +++ b/resources/static/test/cases/common/js/user.js @@ -158,7 +158,7 @@ asyncTest("createSecondaryUser success - callback with true status", function() { lib.createSecondaryUser(TEST_EMAIL, "password", function(status) { - ok(status, "user created"); + ok(status.success, "user created"); start(); }, testHelpers.unexpectedXHRFailure); }); @@ -167,7 +167,10 @@ xhr.useResult("throttle"); lib.createSecondaryUser(TEST_EMAIL, "password", function(status) { - equal(status, false, "user creation refused"); + testObjectValuesEqual(status, { + success: false, + reason: "throttle" + }); start(); }, testHelpers.unexpectedXHRFailure); }); -- GitLab