diff --git a/browserid/static/dialog/controllers/authenticate_controller.js b/browserid/static/dialog/controllers/authenticate_controller.js index 6bd787e657bd57e878cf396a92b63bf570371bdf..17b9c326f8edb7a9b4fca4f56bbe347f6d86b97e 100644 --- a/browserid/static/dialog/controllers/authenticate_controller.js +++ b/browserid/static/dialog/controllers/authenticate_controller.js @@ -78,7 +78,15 @@ }, "#create click": function(event) { - this.close("authenticate:createuser"); + var self = this, + email = $("#email_input").val(); + + identities.createIdentity(email, function(keypair) { + self.close("createaccount:staged", { + email: email, + keypair: keypair + }); + }, self.getErrorDialog(BrowserIDErrors.createAccount)); }, validate: function() { diff --git a/browserid/static/dialog/controllers/checkregistration_controller.js b/browserid/static/dialog/controllers/checkregistration_controller.js index 99842208c510da0df12f54b18ec092dc2ac0be61..33387c3fa2dfcb56b9807ab60b43fab18870fa1d 100644 --- a/browserid/static/dialog/controllers/checkregistration_controller.js +++ b/browserid/static/dialog/controllers/checkregistration_controller.js @@ -52,48 +52,33 @@ }, close: function() { - if(this.pollTimeout) { - clearTimeout(this.pollTimeout); - this.pollTimeout = null; - } - + BrowserIDNetwork.cancelRegistrationCheck(); this._super.apply(this, arguments); }, setupRegCheck: function() { // now poll every 3s waiting for the user to complete confirmation var self=this; - function setupRegCheck() { - self.pollTimeout = setTimeout(function() { - BrowserIDNetwork.checkRegistration(function(status) { - // registration status checks the status of the last initiated registration, - // it's possible return values are: - // 'complete' - registration has been completed - // 'pending' - a registration is in progress - // 'noRegistration' - no registration is in progress - if (status === 'complete') { - // and tell the user that everything is really quite awesome. - self.find("#waiting_confirmation").hide(); - self.find("#resendit_action").hide(); - self.find("#confirmed_notice").show(); - - // enable button - $('#continue_button').removeClass('disabled'); + BrowserIDNetwork.checkRegistration(function(status) { + // registration status checks the status of the last initiated registration, + // it's possible return values are: + // 'complete' - registration has been completed + // 'pending' - a registration is in progress + // 'noRegistration' - no registration is in progress + if (status === 'complete') { + // and tell the user that everything is really quite awesome. + self.find("#waiting_confirmation").hide(); + self.find("#resendit_action").hide(); + self.find("#confirmed_notice").show(); - self.close("checkregistration:confirmed"); - } else if (status === 'pending') { - // try again, what else can we do? - self.setupRegCheck(); - } else { - self.runErrorDialog(BrowserIDErrors.registration); - } - }, self.getErrorDialog(BrowserIDErrors.registration)); - }, 3000); - } - - // setup the timeout - setupRegCheck(); + // enable button + $('#continue_button').removeClass('disabled'); + self.close("checkregistration:confirmed"); + } else if (status !== 'pending') { + self.runErrorDialog(BrowserIDErrors.registration); + } + }, self.getErrorDialog(BrowserIDErrors.registration)); }, validate: function() { diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 7dd14db5a99bc28febf41569f59f4d1a6108ff8d..441595de811c3d2012257290dd43286ea486b412 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -73,7 +73,7 @@ PageController.extend("Dialog", {}, { stateMachine: function() { var self=this, hub = OpenAjax.hub, el = this.element; - hub.subscribe("createaccount:created", function(msg, info) { + hub.subscribe("createaccount:staged", function(msg, info) { self.doConfirmEmail(info.email); }); @@ -152,7 +152,7 @@ PageController.extend("Dialog", {}, { }, doCreate: function() { - this.element.createaccount(); + //this.element.createaccount(); }, doForgotPassword: function() { diff --git a/browserid/static/dialog/resources/browserid-identities.js b/browserid/static/dialog/resources/browserid-identities.js index 50dc0b96ddceb53c37a2ccc027f5a48628096b7a..8cd537860ae04cb6f0a68fd7d9e22618ce3ba7e9 100644 --- a/browserid/static/dialog/resources/browserid-identities.js +++ b/browserid/static/dialog/resources/browserid-identities.js @@ -160,22 +160,21 @@ var BrowserIDIdentities = (function() { * Stage an identity - this creates an identity that must be verified. * Used when creating a new account or resetting the password of an * existing account. - * FIXME: rename to indicate new account - * @method stageIdentity + * @method createIdentity * @param {string} email - Email address. * @param {function} [onSuccess] - Called on successful completion. * @param {function} [onFailure] - Called on error. */ - stageIdentity: function(email, password, onSuccess, onFailure) { + createIdentity: function(email, onSuccess, onFailure) { var self=this; // FIXME: keysize - var keypair = jwk.KeyPair.generate(vep.params.algorithm, 64); + network.createUser(email, function() { + if (onSuccess) { + var keypair = jwk.KeyPair.generate(vep.params.algorithm, 64); - self.stagedEmail = email; - self.stagedKeypair = keypair; + self.stagedEmail = email; + self.stagedKeypair = keypair; - network.stageUser(email, password, function() { - if (onSuccess) { onSuccess(keypair); } }, onFailure); diff --git a/browserid/static/dialog/resources/browserid-network.js b/browserid/static/dialog/resources/browserid-network.js index 43eca79c147c29a09de3890e2d3fa0a87ed15577..a55938b7f5844c4173fe81275be41cfaa2463bb7 100644 --- a/browserid/static/dialog/resources/browserid-network.js +++ b/browserid/static/dialog/resources/browserid-network.js @@ -159,6 +159,22 @@ var BrowserIDNetwork = (function() { }); }, + /** + * Create a new user. Requires a user to verify identity. + * @method stageUser + * @param {string} email - Email address to prepare. + * @param {string} password - Password for user. + * @param {object} keypair - User's public/private key pair. + * @param {function} [onSuccess] - Callback to call when complete. + * @param {function} [onFailure] - Called on XHR failure. + */ + createUser: function(email, onSuccess, onFailure) { + // XXX fill this in + if (onSuccess) { + onSuccess(); + } + }, + /** * Call with a token to prove an email address ownership. * @method proveEmailOwnership @@ -275,15 +291,44 @@ var BrowserIDNetwork = (function() { * @param {function} [onFailure] - Called on XHR failure. */ checkRegistration: function(onSuccess, onFailure) { - $.ajax({ - url: '/wsapi/registration_status', - success: function(status, textStatus, jqXHR) { - if(onSuccess) { - onSuccess(status); - } - }, - error: onFailure - }); + setTimeout(function() { + onSuccess('complete'); + }, 10000); + /* + var self=this; + function poll() { + $.ajax({ + url: '/wsapi/registration_status', + success: function(status, textStatus, jqXHR) { + self.pollTimeout = null; + + if(status === 'pending') { + self.pollTimeout = setTimeout(poll); + } + if(onSuccess) { + onSuccess(status); + } + }, + error: onFailure + }); + } + */ + }, + + /** + * Cancel the registration check + * @method cancelRegistrationCheck + */ + cancelRegistrationCheck: function(onSuccess, onFailure) { + var self=this; + if (self.pollTimeout) { + clearTimeout(self.pollTimeout); + self.pollTimeout = null; + } + + if (onSuccess) { + onSuccess(); + } }, /** diff --git a/browserid/static/dialog/views/authenticate.ejs b/browserid/static/dialog/views/authenticate.ejs index 1e2338d33c6cb859bf7c32930340406d7b36b0b3..37dd3aec23f855dc392ba046d6bf57302682e37d 100644 --- a/browserid/static/dialog/views/authenticate.ejs +++ b/browserid/static/dialog/views/authenticate.ejs @@ -1,3 +1,10 @@ + <!-- This takes care of the core user creation/authentication. When the user + enters an email address and hits "next", the address will be checked + against the currently registered addresses. If the address exists, + the password container is shown, if the address does not exist, the + option to create a new account is given. + --> + <div class="content"> <p class="prompt">Signing into <span class="sitename bad"><%= sitename %></span>:</p> <img src="<%= siteicon %>" alt="NYTimes Logo" width="75" height="75"/>