diff --git a/browserid/static/dialog/controllers/authenticate_controller.js b/browserid/static/dialog/controllers/authenticate_controller.js index 8fc2974a3a21c0e489c52b017c809d837e9b64d9..b9164e931e21cc885641a3d80c1154c60f439629 100644 --- a/browserid/static/dialog/controllers/authenticate_controller.js +++ b/browserid/static/dialog/controllers/authenticate_controller.js @@ -40,7 +40,6 @@ var ANIMATION_TIME = 250, bid = BrowserID, user = bid.User, - network = bid.Network, validation = bid.Validation, lastEmail = ""; @@ -98,7 +97,7 @@ return; } - network.authenticate(email, pass, + user.authenticate(email, pass, function onComplete(authenticated) { if (authenticated) { self.close("authenticated", { diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 5583cbd4787e8d19b94267f86a5433b8557c6919..1f369bdba719e4f562bb4a5e57b15fe2f52e9fe8 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -210,7 +210,7 @@ user.checkAuthenticationAndSync(function onSuccess() {}, function onComplete(authenticated) { if (authenticated) { - self.doPickEmail(); + self.doPickEmail(); } else { self.doAuthenticate(); } diff --git a/browserid/static/dialog/resources/user.js b/browserid/static/dialog/resources/user.js index 76ddc7f48742d2ce2e9f3e7e200dc3a12a005cc4..b78bc6fb54c3db1f082e11daf338b165f7b5e814 100644 --- a/browserid/static/dialog/resources/user.js +++ b/browserid/static/dialog/resources/user.js @@ -403,33 +403,18 @@ BrowserID.User = (function() { }, /** - * Authenticate the user with the given email and password, if - * authentication successful, sync addresses with server. - * @method authenticateAndSync + * Authenticate the user with the given email and password. + * @method authenticate * @param {string} email - Email address to authenticate. * @param {string} password - Password. - * @param {function} [onSuccess] - Called whenever authentication succeeds - * but before sync starts. Useful for displaying status messages about the - * sync taking a moment. * @param {function} [onComplete] - Called on sync completion. * @param {function} [onFailure] - Called on failure. */ - authenticateAndSync: function(email, password, onSuccess, onComplete, onFailure) { + authenticate: function(email, password, onComplete, onFailure) { var self=this; network.authenticate(email, password, function(authenticated) { setAuthenticationStatus(authenticated); - if (authenticated) { - if (onSuccess) { - onSuccess(authenticated); - } - - self.syncEmails(function() { - if (onComplete) { - onComplete(authenticated); - } - }, onFailure); - } else if (onComplete) { - // If not authenticated, we have to complete still. + if (onComplete) { onComplete(authenticated); } }, onFailure); 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 3975445ae0cd3048ae5a5ea6972b151b75adcb28..ae2791b7e1d5444961c9965a117cc1dd235adaa7 100644 --- a/browserid/static/dialog/test/qunit/resources/user_unit_test.js +++ b/browserid/static/dialog/test/qunit/resources/user_unit_test.js @@ -329,9 +329,8 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/user", functio }); - test("authenticateAndSync with valid credentials", function() { - lib.authenticateAndSync("testuser@testuser.com", "testuser", function() { - }, function(authenticated) { + test("authenticate with valid credentials", function() { + lib.authenticate("testuser@testuser.com", "testuser", function(authenticated) { equal(true, authenticated, "we are authenticated!"); start(); }, failure("Authentication failure")); @@ -342,11 +341,9 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/user", functio - test("authenticateAndSync with invalid credentials", function() { + test("authenticate with invalid credentials", function() { credentialsValid = false; - lib.authenticateAndSync("testuser@testuser.com", "testuser", function onSuccess(authenticated) { - ok(false, "This should not be called on authentication failure"); - }, function onComplete(authenticated) { + lib.authenticate("testuser@testuser.com", "testuser", function onComplete(authenticated) { equal(false, authenticated, "invalid authentication."); start(); }, failure("Authentication failure")); @@ -406,40 +403,6 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/user", functio stop(); }); - - test("authenticateAndSync with valid authentication", function() { - credentialsValid = true; - keyRefresh = ["testuser@testuser.com"]; - - lib.authenticateAndSync("testuser@testuser.com", "testuser", function() { - }, function(authenticated) { - var identities = lib.getStoredEmailKeypairs(); - ok("testuser@testuser.com" in identities, "authenticateAndSync syncs email addresses"); - ok(authenticated, "we are authenticated") - start(); - }); - - stop(); - }); - - - - test("authenticateAndSync with invalid authentication", function() { - credentialsValid = false; - keyRefresh = ["testuser@testuser.com"]; - - lib.authenticateAndSync("testuser@testuser.com", "testuser", function() { - }, function(authenticated) { - var identities = lib.getStoredEmailKeypairs(); - equal("testuser@testuser.com" in identities, false, "authenticateAndSync does not sync if authentication is invalid"); - equal(authenticated, false, "not authenticated"); - start(); - }); - - stop(); - }); - - test("isEmailRegistered with registered email", function() { lib.isEmailRegistered("registered", function(registered) { ok(registered); @@ -652,6 +615,19 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/user", functio stop(); }); + test("syncEmails with one to refresh", function() { + storage.addEmail("testuser@testuser.com", {pub: pubkey, cert: random_cert}); + keyRefresh = ["testuser@testuser.com"]; + + lib.syncEmails(function onSuccess() { + var identities = lib.getStoredEmailKeypairs(); + ok("testuser@testuser.com" in identities, "refreshed key is synced"); + start(); + }, failure("identity sync failure")); + + stop(); + }); + test("getAssertion with known email that has key", function() { lib.syncEmailKeypair("testuser@testuser.com", function() { @@ -691,19 +667,20 @@ steal.plugins("jquery", "funcunit/qunit").then("/dialog/resources/user", functio credentialsValid = true; keyRefresh = ["testuser@testuser.com"]; - lib.authenticateAndSync("testuser@testuser.com", "testuser", function() { - }, function(authenticated) { - var storedIdentities = storage.getEmails(); - equal(_.size(storedIdentities), 1, "one identity"); + lib.authenticate("testuser@testuser.com", "testuser", function(authenticated) { + lib.syncEmails(function() { + var storedIdentities = storage.getEmails(); + equal(_.size(storedIdentities), 1, "one identity"); - lib.logoutUser(function() { - storedIdentities = storage.getEmails(); - equal(_.size(storedIdentities), 0, "All items have been removed on logout"); + lib.logoutUser(function() { + storedIdentities = storage.getEmails(); + equal(_.size(storedIdentities), 0, "All items have been removed on logout"); - equal(credentialsValid, false, "credentials were invalidated in logout"); - start(); - }); - }); + equal(credentialsValid, false, "credentials were invalidated in logout"); + start(); + }, failure("logoutUser failure")); + }, failure("syncEmails failure")); + }, failure("authenticate failure")); stop(); }); diff --git a/browserid/static/js/pages/signin.js b/browserid/static/js/pages/signin.js index 703413cd3f59411366b6aba697c69e137518e8c9..1df6ec7b827cf0eba6174b7a1d2d9301a58dfee2 100644 --- a/browserid/static/js/pages/signin.js +++ b/browserid/static/js/pages/signin.js @@ -38,7 +38,7 @@ "use strict"; var bid = BrowserID, - network = bid.Network, + user = bid.User, validation = bid.Validation; function prefillEmail() { @@ -66,7 +66,7 @@ var valid = validation.emailAndPassword(email, password); if (valid) { - network.authenticate(email, password, function onSuccess(authenticated) { + user.authenticate(email, password, function onSuccess(authenticated) { if (authenticated) { document.location = "/"; }