diff --git a/browserid/static/dialog/controllers/authenticate_controller.js b/browserid/static/dialog/controllers/authenticate_controller.js index e816a60cba5bc3ffb9073ada5e60f2e12ae686de..9ffc168d51870e4d0e4432a1a7829121561deba6 100644 --- a/browserid/static/dialog/controllers/authenticate_controller.js +++ b/browserid/static/dialog/controllers/authenticate_controller.js @@ -81,31 +81,42 @@ $(".newuser").fadeIn(ANIMATION_TIME); }); } - }) + }); }); }, - "#signInButton click": function(event) { + "#signInButton click": function(el, event) { + event.preventDefault(); + this.submit(); }, - "#forgotpassword click": function(event) { + "#forgotpassword click": function(el, event) { + event.preventDefault(); + var email = $("#email").val(); this.close("forgotpassword", { email: email }); }, - "#create click": function(event) { + "#create click": function(el, event) { + event.preventDefault(); + var self = this, email = $("#email").val(); identities.createUser(email, function(keypair) { + if(keypair) { self.close("user_staged", { email: email, keypair: keypair }); - }, self.getErrorDialog(BrowserIDErrors.createAccount)); + } + else { + // XXX can't register this email address. + } + }, self.getErrorDialog(BrowserIDErrors.createAccount)); }, validate: function() { @@ -121,22 +132,25 @@ var email = $("#email").val(); var pass = $("#password").val(); - var self = this; - identities.authenticateAndSync(email, pass, - function onAuthenticate(authenticated) { - if (authenticated) { - self.doWait(BrowserIDWait.authentication); - } - }, - function onComplete(authenticated) { - if (authenticated) { - self.close("authenticated"); - } else { - //self.find("#cannot_authenticate").hide().fadeIn(400); - } - }, - self.getErrorDialog(BrowserIDErrors.authentication) - ); + // XXX need a better check here, some mini-state machine. + if (email && pass) { + var self = this; + identities.authenticateAndSync(email, pass, + function onAuthenticate(authenticated) { + if (authenticated) { + self.doWait(BrowserIDWait.authentication); + } + }, + function onComplete(authenticated) { + if (authenticated) { + self.close("authenticated"); + } else { + //self.find("#cannot_authenticate").hide().fadeIn(400); + } + }, + self.getErrorDialog(BrowserIDErrors.authentication) + ); + } } }); diff --git a/browserid/static/dialog/controllers/checkregistration_controller.js b/browserid/static/dialog/controllers/checkregistration_controller.js index 780078fbfeb15eec73b5c852600b79a57251bbbb..51c4ad933e7cb23df1a3f3a5291a94f41e3228a2 100644 --- a/browserid/static/dialog/controllers/checkregistration_controller.js +++ b/browserid/static/dialog/controllers/checkregistration_controller.js @@ -39,54 +39,41 @@ PageController.extend("Checkregistration", {}, { init: function(el, options) { - this._super({ + var me=this; + me._super({ bodyTemplate: "confirmemail.ejs", bodyVars: { email: options.email } }); - $('#continue_button').addClass('disabled'); - this.setupRegCheck(); - }, - - close: function() { - BrowserIDNetwork.cancelRegistrationCheck(); - this._super.apply(this, arguments); + me.setupRegCheck(); + me.email = options.email; }, setupRegCheck: function() { - // now poll every 3s waiting for the user to complete confirmation - var self=this; - 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(); + // Try this every 3 seconds until registration is good. + var me=this, + poll = function() { + BrowserIDNetwork.checkUserRegistration(me.email, 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') { + me.close("checkregistration:confirmed"); + } else if (status === 'pending') { + setTimeout(poll, 3000); + } + else { + me.runErrorDialog(BrowserIDErrors.registration); + } + }, me.getErrorDialog(BrowserIDErrors.registration)); + }; - self.close("checkregistration:confirmed"); - } else if (status !== 'pending') { - self.runErrorDialog(BrowserIDErrors.registration); - } - }, self.getErrorDialog(BrowserIDErrors.registration)); - }/*, - - validate: function() { - var valid = !$("#continue_button").hasClass("disabled"); - return valid; - }, + poll(); - submit: function() { - var self=this; - self.publish("checkregistration:complete"); - self._super(); } -*/ });