From dce02e3f23c94129d4c14f80587e2bf5f654a637 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Wed, 10 Aug 2011 13:43:43 -0700 Subject: [PATCH] Starting on the forgot password controller. --- .../controllers/authenticate_controller.js | 8 ++ .../checkregistration_controller.js | 9 +-- .../controllers/createaccount_controller.js | 4 +- .../dialog/controllers/dialog_controller.js | 26 ++++--- .../controllers/forgotpassword_controller.js | 78 +++++++++++++++++++ browserid/static/dialog/dialog.js | 3 +- 6 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 browserid/static/dialog/controllers/forgotpassword_controller.js diff --git a/browserid/static/dialog/controllers/authenticate_controller.js b/browserid/static/dialog/controllers/authenticate_controller.js index f9e966525..2e4616578 100644 --- a/browserid/static/dialog/controllers/authenticate_controller.js +++ b/browserid/static/dialog/controllers/authenticate_controller.js @@ -13,6 +13,14 @@ }); }, + "#forgotpassword click": function(event) { + this.close("authenticate:forgotpassword"); + }, + + "#create click": function(event) { + this.close("authenticate:createuser"); + }, + validate: function() { var email = $("#email_input").val(); var pass = $("#password_input").val(); diff --git a/browserid/static/dialog/controllers/checkregistration_controller.js b/browserid/static/dialog/controllers/checkregistration_controller.js index 6e8aaab68..7211dacf9 100644 --- a/browserid/static/dialog/controllers/checkregistration_controller.js +++ b/browserid/static/dialog/controllers/checkregistration_controller.js @@ -34,9 +34,6 @@ // 'pending' - a registration is in progress // 'noRegistration' - no registration is in progress if (status === 'complete') { - // this is a secondary registration from browserid.org, persist - // email, keypair, and that fact - // and tell the user that everything is really quite awesome. self.find("#waiting_confirmation").hide(); self.find("#resendit_action").hide(); @@ -46,7 +43,6 @@ $('#continue_button').removeClass('disabled'); self.publish("checkregistration:confirmed"); - } else if (status === 'pending') { // try again, what else can we do? self.setupRegCheck(); @@ -66,13 +62,14 @@ }, validate: function() { - return !$("#continue_button").hasClass("disabled"); + var valid = !$("#continue_button").hasClass("disabled"); + return valid; }, submit: function() { var self=this; - self._super(); self.publish("checkregistration:confirmed"); + self._super(); } }); diff --git a/browserid/static/dialog/controllers/createaccount_controller.js b/browserid/static/dialog/controllers/createaccount_controller.js index 26d2b0e67..591acc512 100644 --- a/browserid/static/dialog/controllers/createaccount_controller.js +++ b/browserid/static/dialog/controllers/createaccount_controller.js @@ -13,7 +13,7 @@ $('#create_continue').addClass('disabled'); // watch input dialogs - this.checkEmail(); + this.setupWatchers(); }, validate: function() { @@ -45,7 +45,7 @@ }, - checkEmail: function() { + setupWatchers: function() { var checkedEmails = {}; var emailCheckState = null; var nextEmailToCheck = null; diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 972cc9c9d..043787c89 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -1,4 +1,4 @@ -/*jshint browser:true, jQuery: true, forin: true, laxbreak:true */ +/*jshint brgwser:true, jQuery: true, forin: true, laxbreak:true */ /*global Channel:true, CryptoStubs:true, alert:true, errorOut:true, setupChannel:true, getEmails:true, clearEmails: true, console: true, _: true, pollTimeout: true, addEmail: true, removeEmail:true, BrowserIDNetwork: true, BrowserIDWait:true, BrowserIDErrors: true, runErrorDialog:true */ // // a JMVC controller for the browserid dialog @@ -85,6 +85,7 @@ $.Controller("Dialog", {}, { BrowserIDNetwork.logout(this.doAuthenticate.bind(this)); }, + /* "#create click": function(event) { this.doCreate(); }, @@ -92,7 +93,7 @@ $.Controller("Dialog", {}, { "#forgotpassword click": function(event) { this.doForgotPassword(); }, - + */ "#cancel click": function(event) { this.onerror("canceled"); }, @@ -101,13 +102,6 @@ $.Controller("Dialog", {}, { this.doStart(); }, - /* - "#continue_button click": function(event) { - if (!$("#continue_button").hasClass('disabled')) { - this.doSignIn(); - } - }, -*/ getVerifiedEmail: function(origin_url, onsuccess, onerror) { this.onsuccess = onsuccess; this.onerror = onerror; @@ -134,7 +128,18 @@ $.Controller("Dialog", {}, { self.syncIdentities(); }); + hub.subscribe("authenticate:createuser", function() { + self.doCreate(); + }); + + hub.subscribe("authenticate:forgotpassword", function() { + self.doForgotPassword(); + }); + + hub.subscribe("checkregistration:confirmed", function() { + // this is a secondary registration from browserid.org, persist + // email, keypair, and that fact self.persistAddressAndKeyPair(self.confirmEmail, self.confirmKeypair, "browserid.org:443"); self.syncidentities(); @@ -188,6 +193,8 @@ $.Controller("Dialog", {}, { }, doForgotPassword: function() { + this.element.forgotpassword(); +/* this.renderTemplates("forgotpassword.ejs", {}, "bottom-continue.ejs", {}); @@ -218,6 +225,7 @@ $.Controller("Dialog", {}, { // do a check at load time, in case the user is using the back button (enables the continue button!) checkInput(); + */ }, doWait: function(info) { diff --git a/browserid/static/dialog/controllers/forgotpassword_controller.js b/browserid/static/dialog/controllers/forgotpassword_controller.js new file mode 100644 index 000000000..bb5805c6d --- /dev/null +++ b/browserid/static/dialog/controllers/forgotpassword_controller.js @@ -0,0 +1,78 @@ +(function() { + "use strict"; + + PageController.extend("Forgotpassword", {}, { + init: function() { + this._super({ + bodyTemplate: "forgotpassword.ejs", + bodyVars: {}, + footerTemplate: "bottom-continue.ejs", + footerVars: {} + }); + + $("#create_continue").addClass("disabled"); + + this.setupWatchers(); + }, + + setupWatchers: function() { + var self=this; + function checkInput() { + var pass = $("#password_input").val(); + var match = pass === $("#password_verify_input").val(); + self.find(".passwordnote").hide(); + $("#create_continue").addClass("disabled"); + if (!match) { + self.find("#passwords_different").show(); + } else { + if (!pass) { + self.find("#enter_a_password").show(); + } else if (pass.length < 5) { + self.find("#password_too_short").show(); + } else { + self.find("#password_ok").show(); + $("#create_continue").removeClass("disabled"); + } + } + } + + // watch input dialogs + self.find("input").unbind("keyup").bind("keyup", checkInput); + + // do a check at load time, in case the user is using the back button (enables the continue button!) + checkInput(); + + }, + + validate: function() { + if ($("#create_continue").hasClass("disabled")) + return false; + return true; + }, + + submit: function() { + // now we need to actually try to stage the creation of this account. + var email = this.find("#email_input").val(); + var pass = this.find("#password_input").val(); + var keypair = CryptoStubs.genKeyPair(); + + this.doWait(BrowserIDWait.createAccount); + + var self = this; + BrowserIDNetwork.stageUser(email, pass, keypair, function() { + self.close("createaccount:created", { + email: email, + keypair: keypair + }); + }, + function() { + self.runErrorDialog(BrowserIDErrors.createAccount); + } + ); + } + + }); + +}()); + + diff --git a/browserid/static/dialog/dialog.js b/browserid/static/dialog/dialog.js index 52f97f8d1..b1efa30d6 100644 --- a/browserid/static/dialog/dialog.js +++ b/browserid/static/dialog/dialog.js @@ -24,7 +24,8 @@ steal.plugins( 'page', 'authenticate', 'createaccount', - 'checkregistration') // loads files in controllers folder + 'checkregistration', + 'forgotpassword') // loads files in controllers folder .views('authenticate.ejs', 'addemail.ejs', -- GitLab