-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Header.js | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Header.js b/frontend/beta/js/Clipperz/PM/DataModel/Header.js index 908d9f4..d577830 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Header.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Header.js @@ -20,129 +20,130 @@ refer to http://www.clipperz.com. License along with Clipperz. If not, see http://www.gnu.org/licenses/. */ if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } //############################################################################# Clipperz.PM.DataModel.Header = function(args) { args = args || {}; this._user = args.user; this._serverData = null; this._serverDataVersion = null; this._jsonEvaledServerData = null; this._decryptedLegacyServerData = null; this._isDecryptingLegacyServerData = false; this._decryptingLegacyServerDataPendingQueue = []; this.resetUpdatedSections(); this._shouldLoadSections = {}; Clipperz.NotificationCenter.register(this.user(), 'updatedSection', this, 'updatedSectionHandler'); return this; } Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { //------------------------------------------------------------------------- 'user': function() { return this._user; }, //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- 'updatedSections': function() { return this._updatedSections; }, 'markSectionAsUpdated': function(aSectionName) { this.updatedSections().push(aSectionName); }, 'resetUpdatedSections': function() { this._updatedSections = [] }, 'hasSectionBeenUpdated': function(aSectionName) { - return (this.updatedSections().join().indexOf(aSectionName) != -1); + return (this.updatedSections().join().indexOf(aSectionName) != -1) + || (this.serverDataVersion() != Clipperz.PM.Crypto.encryptingFunctions.currentVersion); }, 'cachedServerDataSection': function(aSectionName) { return (this.hasSectionBeenUpdated(aSectionName)) ? {} : this.jsonEvaledServerData()[aSectionName]; }, 'updateAllSections': function() { this.resetUpdatedSections(); this.markSectionAsUpdated('records'); this.markSectionAsUpdated('directLogins'); this.markSectionAsUpdated('preferences'); this.markSectionAsUpdated('oneTimePasswords'); return MochiKit.Async.succeed(this); }, 'updatedSectionHandler': function(anEvent) { this.markSectionAsUpdated(anEvent.parameters()); }, //------------------------------------------------------------------------- 'getObjectKeyIndex': function(anObject) { var result; var itemReference; var index; result = {}; index = 0; for (itemReference in anObject) { result[itemReference] = index.toString(); index ++; } return result; }, //------------------------------------------------------------------------- 'serializedDataWithRecordAndDirectLoginIndexes': function(aRecordIndexes, aDirectLoginIndexs) { var result; var records; var recordReference; //MochiKit.Logging.logDebug(">>> Header.serializedData"); result = { 'records': {}, 'directLogins': {} }; records = this.user().records(); for (recordReference in records) { result['records'][aRecordIndexes[recordReference]] = this.user().records()[recordReference].headerData(); } for (directLoginReference in this.user().directLoginReferences()) { var currentDirectLogin; var directLoginData; currentDirectLogin = this.user().directLoginReferences()[directLoginReference]; if (aRecordIndexes[currentDirectLogin.recordReference()] != null) { directLoginData = { // reference: currentDirectLogin.reference(), @@ -351,128 +352,129 @@ Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { //MochiKit.Logging.logDebug("<<< Header.decryptedLegacyServerData"); return deferredResult; }, //------------------------------------------------------------------------- 'serverDataFormat': function() { var result; //MochiKit.Logging.logDebug(">>> Header.serverDataFormat"); if (this.serverData().charAt(0) == '{') { var serverData; serverData = Clipperz.Base.evalJSON(this.serverData()); result = serverData['version']; } else { result = 'LEGACY'; } //MochiKit.Logging.logDebug("<<< Header.serverDataFormat"); return result; }, //------------------------------------------------------------------------- 'extractHeaderDataFromUserDetails': function(someUserDetails) { if (this.serverData() == null) { this.setServerData(someUserDetails['header']); this.setServerDataVersion(someUserDetails['version']) } }, //------------------------------------------------------------------------- 'extractDataWithKey': function(aKey) { var deferredResult; //MochiKit.Logging.logDebug(">>> Header.extractDataWithKey"); deferredResult = new MochiKit.Async.Deferred(); switch (this.serverDataFormat()) { case 'LEGACY': //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 1: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); deferredResult.addCallback(MochiKit.Base.method(this, 'decryptedLegacyServerData')); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 2: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); deferredResult.addCallback(function(someDecryptedValues) { return someDecryptedValues[aKey] || {}; }) //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 3: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); break; case '0.1': var data; //# data = Clipperz.Base.evalJSON(this.serverData()); data = this.jsonEvaledServerData(); if (typeof(data[aKey]) != 'undefined') { //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 4: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_decryptingUserData'); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 5: "/* + res*/); return res;}); +//deferredResult.addBoth(function(res) {console.log("aKey: " + aKey); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.user().passphrase(), data[aKey]['data'], this.serverDataVersion()); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); deferredResult.addCallback(function(/*anHeader,*/ aKey, aData, aRecordIndex, aValue) { var result; //MochiKit.Logging.logDebug(">>> [start] ==============================================="); //MochiKit.Logging.logDebug("--- extractDataWithKey - 0 [" + aKey + "]: " + Clipperz.Base.serializeJSON(aValue)); //MochiKit.Logging.logDebug("<<< [end] ================================================="); if (aKey == 'records') { var recordKey; result = {}; for (recordKey in aData['index']) { result[recordKey] = aValue[aData['index'][recordKey]]; } } else if (aKey == 'directLogins') { var recordKeyReversedIndex; var recordKey; var directLoginKey; result = {}; recordKeyReversedIndex = {}; for (recordKey in aRecordIndex) { recordKeyReversedIndex[aRecordIndex[recordKey]] = recordKey; } //MochiKit.Logging.logDebug("--- extractDataWithKey - 1 - aData['index']: " + Clipperz.Base.serializeJSON(aData['index'])); for (directLoginKey in aData['index']) { try { if ((aData['index'][directLoginKey] != null) && (aValue[aData['index'][directLoginKey]] != null)) { result[directLoginKey] = aValue[aData['index'][directLoginKey]]; result[directLoginKey]['record'] = recordKeyReversedIndex[result[directLoginKey]['record']]; } } catch(exception) { // result[directLoginKey] has no properties MochiKit.Logging.logDebug("[Header 391] EXCEPTION: " + exception); throw exception; } } //MochiKit.Logging.logDebug("--- extractDataWithKey - 2"); } else { result = aValue; } return result; }, /*this,*/ aKey, data[aKey], data['records']['index']); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); } else { //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 7: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); deferredResult.addCallback(MochiKit.Async.succeed, {}); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 8: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); } break; } //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 9: "/* + res*/); return res;}); //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); deferredResult.callback(); //MochiKit.Logging.logDebug("<<< Header.extractDataWithKey"); |