From 4ba58c6880c1fdae7f732d0b62a41d8ba7724a8c Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Fri, 7 Oct 2011 10:14:14 +0100 Subject: [PATCH] If an email address is specified for authentication, fill it in and go to the password screen (if address is registered). This finishes up #336, and also gets us ready for a site to be able to specify a preferred email address. close #336. --- .../dialog/controllers/authenticate_controller.js | 15 ++++++++++++--- .../controllers/checkregistration_controller.js | 2 +- .../dialog/controllers/dialog_controller.js | 12 ++++++++---- .../static/dialog/controllers/page_controller.js | 5 +++-- browserid/static/dialog/views/authenticate.ejs | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/browserid/static/dialog/controllers/authenticate_controller.js b/browserid/static/dialog/controllers/authenticate_controller.js index 1472bf4a3..2ebe697ef 100644 --- a/browserid/static/dialog/controllers/authenticate_controller.js +++ b/browserid/static/dialog/controllers/authenticate_controller.js @@ -190,20 +190,29 @@ PageController.extend("Authenticate", {}, { - init: function() { + init: function(el, options) { + options = options || {}; + this._super({ bodyTemplate: "authenticate.ejs", bodyVars: { sitename: identities.getOrigin(), - siteicon: '/i/times.gif' + siteicon: "/i/times.gif", + email: options.email || "" } }); + this.submit = checkEmail; + // If we already have an email address, check if it is valid, if so, show + // password. + if(options.email) { + this.submit(); + } }, "#email keyup": enterEmailState, "#forgotPassword click": forgotPasswordState, - '#cancel_forgot_password click': cancelForgotPassword + "#cancel_forgot_password click": cancelForgotPassword }); }()); diff --git a/browserid/static/dialog/controllers/checkregistration_controller.js b/browserid/static/dialog/controllers/checkregistration_controller.js index 1a6300fe1..e7ec80938 100644 --- a/browserid/static/dialog/controllers/checkregistration_controller.js +++ b/browserid/static/dialog/controllers/checkregistration_controller.js @@ -63,7 +63,7 @@ }); } else if (status === "mustAuth") { - me.close("auth"); + me.close("auth", { email: me.email }); } }, me.getErrorDialog(BrowserID.Errors.registration)); } diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 003e9adf3..748ce8897 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -109,8 +109,12 @@ PageController.extend("Dialog", {}, { self.doNotMe(); }); - hub.subscribe("auth", function() { - self.doAuthenticate(); + hub.subscribe("auth", function(msg, info) { + info = info || {}; + + self.doAuthenticate({ + email: info.email + }); }); hub.subscribe("start", function() { @@ -144,8 +148,8 @@ PageController.extend("Dialog", {}, { this.element.pickemail(); }, - doAuthenticate: function() { - this.element.authenticate(); + doAuthenticate: function(info) { + this.element.authenticate(info); }, doForgotPassword: function(email) { diff --git a/browserid/static/dialog/controllers/page_controller.js b/browserid/static/dialog/controllers/page_controller.js index aee8e85b1..61b9f4d21 100644 --- a/browserid/static/dialog/controllers/page_controller.js +++ b/browserid/static/dialog/controllers/page_controller.js @@ -38,6 +38,7 @@ "use strict"; var bid = BrowserID, + ANIMATION_TIME = 250, identities = bid.Identities; @@ -75,7 +76,7 @@ if (body) { var bodyHtml = $.View("//dialog/views/" + body, body_vars); - $("#dialog").html(bodyHtml).hide().fadeIn(300, function() { + $("#dialog").html(bodyHtml).hide().fadeIn(ANIMATION_TIME, function() { $("#dialog input").eq(0).focus(); }); } @@ -126,7 +127,7 @@ $("body").removeClass("authenticated").addClass("error"); - $("#error_dialog").fadeIn(500); + $("#error_dialog").fadeIn(ANIMATION_TIME); }, /** diff --git a/browserid/static/dialog/views/authenticate.ejs b/browserid/static/dialog/views/authenticate.ejs index 6675f15a5..81150fcba 100644 --- a/browserid/static/dialog/views/authenticate.ejs +++ b/browserid/static/dialog/views/authenticate.ejs @@ -22,7 +22,7 @@ <li> <label for="email" class="serif">Email</label> - <input id="email" class="sans" type="email" autocapitalize="off" autocorrect="off" x-moz-errormessage="an email address is required"> + <input id="email" class="sans" type="email" autocapitalize="off" autocorrect="off" value="<%= email %>" /> <div id="email_format" class="tooltip" for="email"> This field must be an email address. -- GitLab