From 8608fb4253bb6501398f66ad5a09d406558cb521 Mon Sep 17 00:00:00 2001 From: Giulio Cesare Solaroli Date: Tue, 27 Oct 2015 14:31:39 +0100 Subject: [PATCH] Fixed lock/unlock issue and removed console.log --- .../delta/js/Clipperz/PM/DataModel/Record.js | 4 ++-- frontend/delta/js/Clipperz/PM/DataModel/User.js | 2 +- .../PM/Proxy/Proxy.Offline.DataStore.js | 2 +- .../Clipperz/PM/UI/Components/Cards/TextArea.js | 1 - .../delta/js/Clipperz/PM/UI/MainController.js | 16 ++++++++++++---- .../tests/Clipperz/PM/DataModel/User.test.js | 17 +++++++++-------- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/frontend/delta/js/Clipperz/PM/DataModel/Record.js b/frontend/delta/js/Clipperz/PM/DataModel/Record.js index 3d6b150..a617096 100644 --- a/frontend/delta/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/delta/js/Clipperz/PM/DataModel/Record.js @@ -581,7 +581,7 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.Encrypt result = someFilteredResults[0]; break; default: -console.log("Warning: Record.fieldWithLabel('" + aLabel + "') is returning more than one result: " + someFilteredResults.length); +Clipperz.log("Warning: Record.fieldWithLabel('" + aLabel + "') is returning more than one result: " + someFilteredResults.length); result = someFilteredResults[0]; break; } @@ -607,7 +607,7 @@ console.log("Warning: Record.fieldWithLabel('" + aLabel + "') is returning more var transientStateKey; if (typeof(aVersionReference) == 'undefined') { - console.log("ERROR; getVersionKey aVersionReference is undefined"); + Clipperz.log("ERROR; getVersionKey aVersionReference is undefined"); } transientStateKey = 'versionKeys' + '.' + aVersionReference; diff --git a/frontend/delta/js/Clipperz/PM/DataModel/User.js b/frontend/delta/js/Clipperz/PM/DataModel/User.js index 8f0f18b..f87d356 100644 --- a/frontend/delta/js/Clipperz/PM/DataModel/User.js +++ b/frontend/delta/js/Clipperz/PM/DataModel/User.js @@ -695,7 +695,7 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { result = someFilteredResults[0]; break; default: -console.log("Warning: User.recordWithLabel('" + aLabel + "') is returning more than one result: " + someFilteredResults.length); +Clipperz.log("Warning: User.recordWithLabel('" + aLabel + "') is returning more than one result: " + someFilteredResults.length); result = someFilteredResults[0]; break; } diff --git a/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js index de274f3..00469c0 100644 --- a/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js +++ b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js @@ -295,7 +295,7 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { 's': someParameters['credentials']['s'], 'v': someParameters['credentials']['v'], 'version': someParameters['credentials']['version'], -// 'lock': Clipperz.Crypto.Base.generateRandomSeed(), + 'lock': Clipperz.PM.Crypto.randomKey(), 'userDetails': someParameters['user']['header'], 'statistics': someParameters['user']['statistics'], 'userDetailsVersion': someParameters['user']['version'], diff --git a/frontend/delta/js/Clipperz/PM/UI/Components/Cards/TextArea.js b/frontend/delta/js/Clipperz/PM/UI/Components/Cards/TextArea.js index 93f40a6..31dcea1 100644 --- a/frontend/delta/js/Clipperz/PM/UI/Components/Cards/TextArea.js +++ b/frontend/delta/js/Clipperz/PM/UI/Components/Cards/TextArea.js @@ -63,7 +63,6 @@ Clipperz.PM.UI.Components.Cards.TextAreaClass = React.createClass({ handleKeyDown: function (anEvent) { switch (anEvent.keyCode) { case 27: // escape - console.log("ESCAPE"); Mousetrap.trigger('esc'); break; } diff --git a/frontend/delta/js/Clipperz/PM/UI/MainController.js b/frontend/delta/js/Clipperz/PM/UI/MainController.js index c18adae..0e732bb 100644 --- a/frontend/delta/js/Clipperz/PM/UI/MainController.js +++ b/frontend/delta/js/Clipperz/PM/UI/MainController.js @@ -424,19 +424,27 @@ Clipperz.log("THE BROWSER IS OFFLINE"); unlock_handler: function(aCredential, aCredentialType) { var deferredResult; - var passphrase; + var user, passphrase, getPassphraseDelegate; - var user = this.user(); + // var user = this.user(); + var oldUser = this.user(); var unlockPage = this.pages()['unlockPage']; var overlay = this.overlay(); overlay.show("validating…"); passphrase = (aCredentialType=='PIN') ? Clipperz.PM.PIN.credentialsWithPIN(aCredential)['passphrase'] : aCredential; - deferredResult = new Clipperz.Async.Deferred('MainController.unlock_handler', {trace:false}); + getPassphraseDelegate = MochiKit.Base.partial(MochiKit.Async.succeed, passphrase); + user = new Clipperz.PM.DataModel.User({'username':oldUser.username(), 'getPassphraseFunction':getPassphraseDelegate}); + + deferredResult = new Clipperz.Async.Deferred('MainController.unlock_handler', {trace:true}); + deferredResult.addMethod(unlockPage, 'setProps', {'disabled': true}); - deferredResult.addMethod(user, 'unlock', function() { return MochiKit.Async.succeed(passphrase); }); + deferredResult.addMethod(user, 'login'); + deferredResult.addMethod(this, 'setUser', user); + // deferredResult.addMethod(user, 'unlock', MochiKit.Base.partial(MochiKit.Async.succeed, passphrase)); + deferredResult.addErrback(MochiKit.Base.bind(function (aValue) { var innerDeferredResult; var errorMessage; diff --git a/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js b/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js index 0093837..80dba3e 100644 --- a/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js +++ b/frontend/delta/tests/tests/Clipperz/PM/DataModel/User.test.js @@ -1893,18 +1893,19 @@ var tests = { SimpleTest.is(MochiKit.Base.keys(someDirectLogins).length, 22, "The user has 22 direct logins"); }); - deferredResult.addMethod(proxy, 'shouldNotReceiveAnyFurtherRequest'); - deferredResult.addCallback(function () { currentPasswordFunction = failPassword; }); + // User.lock() actually sends a `logout` request. + // deferredResult.addMethod(proxy, 'shouldNotReceiveAnyFurtherRequest'); + // deferredResult.addCallback(function () { currentPasswordFunction = failPassword; }); deferredResult.addMethod(user, 'lock'); deferredResult.shouldSucceed("Locking out should not trigger an exception"); - deferredResult.addMethod(proxy, 'unexpectedRequests'); - deferredResult.addCallback(MochiKit.Base.itemgetter('length')); - deferredResult.addTest(0, "The proxy should have not received any extra request"); -//deferredResult.addCallback(function (aValue) { console.log("PROXY.unexpectedRequests", Clipperz.Base.serializeJSON(proxy.unexpectedRequests())); return aValue; }); - deferredResult.addMethod(proxy, 'mayReceiveMoreRequests'); - deferredResult.addCallback(function () { currentPasswordFunction = returnPassword; }); +// deferredResult.addMethod(proxy, 'unexpectedRequests'); +// deferredResult.addCallback(MochiKit.Base.itemgetter('length')); +// deferredResult.addTest(0, "The proxy should have not received any extra request"); +// deferredResult.addCallback(function (aValue) { console.log("PROXY.unexpectedRequests", Clipperz.Base.serializeJSON(proxy.unexpectedRequests())); return aValue; }); +// deferredResult.addMethod(proxy, 'mayReceiveMoreRequests'); + // deferredResult.addCallback(function () { currentPasswordFunction = returnPassword; }); deferredResult.callback();