From 1e98a78f3ca66d13708e028dc8e7af9ad6b45cee Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Thu, 20 Oct 2011 17:13:05 +0100 Subject: [PATCH] Adding "getHostname" to user, which filters out the port and protocol. Add's to Lloyd's pull request by keeping the extra info from being displayed to the user. issue #82 --- .../static/dialog/controllers/authenticate_controller.js | 2 +- browserid/static/dialog/controllers/dialog_controller.js | 2 +- browserid/static/dialog/resources/user.js | 9 +++++++++ .../static/dialog/test/qunit/resources/user_unit_test.js | 8 ++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/browserid/static/dialog/controllers/authenticate_controller.js b/browserid/static/dialog/controllers/authenticate_controller.js index b9164e931..0054f37c3 100644 --- a/browserid/static/dialog/controllers/authenticate_controller.js +++ b/browserid/static/dialog/controllers/authenticate_controller.js @@ -192,7 +192,7 @@ this._super(el, { bodyTemplate: "authenticate.ejs", bodyVars: { - sitename: user.getOrigin(), + sitename: user.getHostname(), email: options.email || "" } }); diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 1f369bdba..491d983fa 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -63,7 +63,7 @@ user.setOrigin(origin_url); // get the cleaned origin. - $("#sitename").text(user.getOrigin()); + $("#sitename").text(user.getHostname()); this.doCheckAuth(); diff --git a/browserid/static/dialog/resources/user.js b/browserid/static/dialog/resources/user.js index 57a491795..27105f7f4 100644 --- a/browserid/static/dialog/resources/user.js +++ b/browserid/static/dialog/resources/user.js @@ -210,6 +210,15 @@ BrowserID.User = (function() { return origin; }, + /** + * Get the hostname for the set origin + * @method getHostname + * @returns {string} + */ + getHostname: function() { + return origin.replace(/^.*:\/\//, "").replace(/:\d*$/, ""); + }, + /** * Create a user account - this creates an user account that must be verified. * @method createUser diff --git a/browserid/static/dialog/test/qunit/resources/user_unit_test.js b/browserid/static/dialog/test/qunit/resources/user_unit_test.js index ae2791b7e..7e0b15155 100644 --- a/browserid/static/dialog/test/qunit/resources/user_unit_test.js +++ b/browserid/static/dialog/test/qunit/resources/user_unit_test.js @@ -221,6 +221,14 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/user", functio equal(lib.getOrigin(), testOrigin); }); + test("setOrigin, getHostname", function() { + var origin = "http://testorigin.com:10001"; + lib.setOrigin(origin); + + var hostname = lib.getHostname(); + equal(hostname, "testorigin.com", "getHostname returns only the hostname"); + }); + test("getStoredEmailKeypairs", function() { var identities = lib.getStoredEmailKeypairs(); equal("object", typeof identities, "we have some identities"); -- GitLab