author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js index 01ba122..326022c 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js | |||
@@ -1,173 +1,169 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!"; | 25 | throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | //============================================================================= | 28 | //============================================================================= |
31 | 29 | ||
32 | Clipperz.PM.Proxy.Offline.DataStore = function(args) { | 30 | Clipperz.PM.Proxy.Offline.DataStore = function(args) { |
33 | args = args || {}; | 31 | args = args || {}; |
34 | 32 | ||
35 | this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); | 33 | this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); |
36 | this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); | 34 | this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); |
37 | this._shouldPayTolls = args.shouldPayTolls || false; | 35 | this._shouldPayTolls = args.shouldPayTolls || false; |
38 | 36 | ||
39 | this._tolls = {}; | 37 | this._tolls = {}; |
40 | this._currentStaticConnection = null; | 38 | this._currentStaticConnection = null; |
41 | 39 | ||
42 | return this; | 40 | return this; |
43 | } | 41 | } |
44 | 42 | ||
45 | Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | 43 | Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { |
46 | 44 | ||
47 | //------------------------------------------------------------------------- | 45 | //------------------------------------------------------------------------- |
48 | 46 | ||
49 | 'isReadOnly': function () { | 47 | 'isReadOnly': function () { |
50 | return this._isReadOnly; | 48 | return this._isReadOnly; |
51 | }, | 49 | }, |
52 | 50 | ||
53 | //------------------------------------------------------------------------- | 51 | //------------------------------------------------------------------------- |
54 | 52 | ||
55 | 'shouldPayTolls': function() { | 53 | 'shouldPayTolls': function() { |
56 | return this._shouldPayTolls; | 54 | return this._shouldPayTolls; |
57 | }, | 55 | }, |
58 | 56 | ||
59 | //------------------------------------------------------------------------- | 57 | //------------------------------------------------------------------------- |
60 | 58 | ||
61 | 'data': function () { | 59 | 'data': function () { |
62 | return this._data; | 60 | return this._data; |
63 | }, | 61 | }, |
64 | 62 | ||
65 | //------------------------------------------------------------------------- | 63 | //------------------------------------------------------------------------- |
66 | 64 | ||
67 | 'tolls': function () { | 65 | 'tolls': function () { |
68 | return this._tolls; | 66 | return this._tolls; |
69 | }, | 67 | }, |
70 | 68 | ||
71 | //========================================================================= | 69 | //========================================================================= |
72 | 70 | ||
73 | 'resetData': function() { | 71 | 'resetData': function() { |
74 | this._data = { | 72 | this._data = { |
75 | 'users': { | 73 | 'users': { |
76 | 'catchAllUser': { | 74 | 'catchAllUser': { |
77 | __masterkey_test_value__: 'masterkey', | 75 | __masterkey_test_value__: 'masterkey', |
78 | s: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00', | 76 | s: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00', |
79 | v: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00' | 77 | v: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00' |
80 | } | 78 | } |
81 | } | 79 | } |
82 | }; | 80 | }; |
83 | }, | 81 | }, |
84 | 82 | ||
85 | //------------------------------------------------------------------------- | 83 | //------------------------------------------------------------------------- |
86 | 84 | ||
87 | 'setupWithEncryptedData': function(someData) { | 85 | 'setupWithEncryptedData': function(someData) { |
88 | this._data = Clipperz.Base.deepClone(someData); | 86 | this._data = Clipperz.Base.deepClone(someData); |
89 | }, | 87 | }, |
90 | 88 | ||
91 | //------------------------------------------------------------------------- | 89 | //------------------------------------------------------------------------- |
92 | 90 | ||
93 | 'setupWithData': function(someData) { | 91 | 'setupWithData': function(someData) { |
94 | var deferredResult; | 92 | var deferredResult; |
95 | var resultData; | 93 | var resultData; |
96 | var i, c; | 94 | var i, c; |
97 | 95 | ||
98 | //Clipperz.log(">>> Proxy.Test.setupWithData"); | 96 | //Clipperz.log(">>> Proxy.Test.setupWithData"); |
99 | resultData = this._data; | 97 | resultData = this._data; |
100 | 98 | ||
101 | deferredResult = new Clipperz.Async.Deferred("Proxy.Test.seupWithData", {trace:false}); | 99 | deferredResult = new Clipperz.Async.Deferred("Proxy.Test.seupWithData", {trace:false}); |
102 | c = someData['users'].length; | 100 | c = someData['users'].length; |
103 | 101 | ||
104 | for (i=0; i<c; i++) { | 102 | for (i=0; i<c; i++) { |
105 | varnewConnection; | 103 | varnewConnection; |
106 | varrecordConfiguration; | 104 | varrecordConfiguration; |
107 | 105 | ||
108 | deferredResult.addMethod(this, 'userSerializedEncryptedData', someData['users'][i]); | 106 | deferredResult.addMethod(this, 'userSerializedEncryptedData', someData['users'][i]); |
109 | deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) { | 107 | deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) { |
110 | //console.log("SERIALIZED USER", aUserSerializationContext); | ||
111 | resultData['users'][aUserSerializationContext['credentials']['C']] = { | 108 | resultData['users'][aUserSerializationContext['credentials']['C']] = { |
112 | 's': aUserSerializationContext['credentials']['s'], | 109 | 's': aUserSerializationContext['credentials']['s'], |
113 | 'v': aUserSerializationContext['credentials']['v'], | 110 | 'v': aUserSerializationContext['credentials']['v'], |
114 | 'version': aUserSerializationContext['data']['connectionVersion'], | 111 | 'version': aUserSerializationContext['data']['connectionVersion'], |
115 | 'userDetails': aUserSerializationContext['encryptedData']['user']['header'], | 112 | 'userDetails': aUserSerializationContext['encryptedData']['user']['header'], |
116 | 'userDetailsVersion':aUserSerializationContext['encryptedData']['user']['version'], | 113 | 'userDetailsVersion':aUserSerializationContext['encryptedData']['user']['version'], |
117 | 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'], | 114 | 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'], |
118 | 'lock': aUserSerializationContext['encryptedData']['user']['lock'], | 115 | 'lock': aUserSerializationContext['encryptedData']['user']['lock'], |
119 | 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records']) | 116 | 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records']) |
120 | } | 117 | } |
121 | }, this)); | 118 | }, this)); |
122 | } | 119 | } |
123 | 120 | ||
124 | deferredResult.addCallback(MochiKit.Base.bind(function() { | 121 | deferredResult.addCallback(MochiKit.Base.bind(function() { |
125 | //console.log("this._data", resultData); | ||
126 | this._data = resultData; | 122 | this._data = resultData; |
127 | }, this)); | 123 | }, this)); |
128 | 124 | ||
129 | deferredResult.callback(); | 125 | deferredResult.callback(); |
130 | //Clipperz.log("<<< Proxy.Test.setupWithData"); | 126 | //Clipperz.log("<<< Proxy.Test.setupWithData"); |
131 | 127 | ||
132 | return deferredResult; | 128 | return deferredResult; |
133 | }, | 129 | }, |
134 | 130 | ||
135 | //========================================================================= | 131 | //========================================================================= |
136 | 132 | ||
137 | 'getTollForRequestType': function (aRequestType) { | 133 | 'getTollForRequestType': function (aRequestType) { |
138 | varresult; | 134 | varresult; |
139 | vartargetValue; | 135 | vartargetValue; |
140 | var cost; | 136 | var cost; |
141 | 137 | ||
142 | targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); | 138 | targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); |
143 | switch (aRequestType) { | 139 | switch (aRequestType) { |
144 | case 'REGISTER': | 140 | case 'REGISTER': |
145 | cost = 5; | 141 | cost = 5; |
146 | break; | 142 | break; |
147 | case 'CONNECT': | 143 | case 'CONNECT': |
148 | cost = 5; | 144 | cost = 5; |
149 | break; | 145 | break; |
150 | case 'MESSAGE': | 146 | case 'MESSAGE': |
151 | cost = 2; | 147 | cost = 2; |
152 | break; | 148 | break; |
153 | } | 149 | } |
154 | 150 | ||
155 | result = { | 151 | result = { |
156 | requestType: aRequestType, | 152 | requestType: aRequestType, |
157 | targetValue: targetValue, | 153 | targetValue: targetValue, |
158 | cost: cost | 154 | cost: cost |
159 | } | 155 | } |
160 | 156 | ||
161 | if (this.shouldPayTolls()) { | 157 | if (this.shouldPayTolls()) { |
162 | this.tolls()[targetValue] = result; | 158 | this.tolls()[targetValue] = result; |
163 | } | 159 | } |
164 | 160 | ||
165 | return result; | 161 | return result; |
166 | }, | 162 | }, |
167 | 163 | ||
168 | //------------------------------------------------------------------------- | 164 | //------------------------------------------------------------------------- |
169 | 165 | ||
170 | 'checkToll': function (aFunctionName, someParameters) { | 166 | 'checkToll': function (aFunctionName, someParameters) { |
171 | if (this.shouldPayTolls()) { | 167 | if (this.shouldPayTolls()) { |
172 | var localToll; | 168 | var localToll; |
173 | vartollParameters; | 169 | vartollParameters; |
@@ -350,97 +346,97 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | |||
350 | S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(aConnection['b'], Clipperz.Crypto.SRP.n()); | 346 | S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(aConnection['b'], Clipperz.Crypto.SRP.n()); |
351 | 347 | ||
352 | K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2); | 348 | K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2); |
353 | 349 | ||
354 | M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + aConnection['B'].asString(10) + K)).toHexString().slice(2); | 350 | M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + aConnection['B'].asString(10) + K)).toHexString().slice(2); |
355 | if (someParameters.parameters.M1 == M1) { | 351 | if (someParameters.parameters.M1 == M1) { |
356 | var M2; | 352 | var M2; |
357 | 353 | ||
358 | M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2); | 354 | M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2); |
359 | result['M2'] = M2; | 355 | result['M2'] = M2; |
360 | } else { | 356 | } else { |
361 | throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); | 357 | throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); |
362 | } | 358 | } |
363 | 359 | ||
364 | nextTollRequestType = 'MESSAGE'; | 360 | nextTollRequestType = 'MESSAGE'; |
365 | } else if (someParameters.message == "oneTimePassword") { | 361 | } else if (someParameters.message == "oneTimePassword") { |
366 | var otpData; | 362 | var otpData; |
367 | 363 | ||
368 | otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; | 364 | otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; |
369 | 365 | ||
370 | try { | 366 | try { |
371 | if (typeof(otpData) != 'undefined') { | 367 | if (typeof(otpData) != 'undefined') { |
372 | if (otpData['status'] == 'ACTIVE') { | 368 | if (otpData['status'] == 'ACTIVE') { |
373 | if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { | 369 | if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { |
374 | result = { | 370 | result = { |
375 | 'data': otpData['data'], | 371 | 'data': otpData['data'], |
376 | 'version':otpData['version'] | 372 | 'version':otpData['version'] |
377 | } | 373 | } |
378 | 374 | ||
379 | otpData['status'] = 'REQUESTED'; | 375 | otpData['status'] = 'REQUESTED'; |
380 | } else { | 376 | } else { |
381 | otpData['status'] = 'DISABLED'; | 377 | otpData['status'] = 'DISABLED'; |
382 | throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; | 378 | throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; |
383 | } | 379 | } |
384 | } else { | 380 | } else { |
385 | throw "The requested One Time Password was not active"; | 381 | throw "The requested One Time Password was not active"; |
386 | } | 382 | } |
387 | } else { | 383 | } else { |
388 | throw "The requested One Time Password has not been found" | 384 | throw "The requested One Time Password has not been found" |
389 | } | 385 | } |
390 | } catch (exception) { | 386 | } catch (exception) { |
391 | result = { | 387 | result = { |
392 | 'data': Clipperz.PM.Crypto.randomKey(), | 388 | 'data': Clipperz.PM.Crypto.randomKey(), |
393 | 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion | 389 | 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion |
394 | } | 390 | } |
395 | } | 391 | } |
396 | nextTollRequestType = 'CONNECT'; | 392 | nextTollRequestType = 'CONNECT'; |
397 | } else { | 393 | } else { |
398 | MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); | 394 | Clipperz.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); |
399 | } | 395 | } |
400 | 396 | ||
401 | result = { | 397 | result = { |
402 | result: result, | 398 | result: result, |
403 | toll: this.getTollForRequestType(nextTollRequestType) | 399 | toll: this.getTollForRequestType(nextTollRequestType) |
404 | } | 400 | } |
405 | 401 | ||
406 | return result; | 402 | return result; |
407 | }, | 403 | }, |
408 | 404 | ||
409 | //------------------------------------------------------------------------- | 405 | //------------------------------------------------------------------------- |
410 | 406 | ||
411 | '_message': function(aConnection, someParameters) { | 407 | '_message': function(aConnection, someParameters) { |
412 | var result; | 408 | var result; |
413 | 409 | ||
414 | result = {}; | 410 | result = {}; |
415 | 411 | ||
416 | //===================================================================== | 412 | //===================================================================== |
417 | // | 413 | // |
418 | // R E A D - O N L Y M e t h o d s | 414 | // R E A D - O N L Y M e t h o d s |
419 | // | 415 | // |
420 | //===================================================================== | 416 | //===================================================================== |
421 | if (someParameters.message == 'getUserDetails') { | 417 | if (someParameters.message == 'getUserDetails') { |
422 | var recordsStats; | 418 | var recordsStats; |
423 | var recordReference; | 419 | var recordReference; |
424 | 420 | ||
425 | recordsStats = {}; | 421 | recordsStats = {}; |
426 | for (recordReference in aConnection['userData']['records']) { | 422 | for (recordReference in aConnection['userData']['records']) { |
427 | recordsStats[recordReference] = { | 423 | recordsStats[recordReference] = { |
428 | 'updateDate': aConnection['userData']['records'][recordReference]['updateDate'] | 424 | 'updateDate': aConnection['userData']['records'][recordReference]['updateDate'] |
429 | } | 425 | } |
430 | } | 426 | } |
431 | 427 | ||
432 | result['header'] = this.userDetails(aConnection); | 428 | result['header'] = this.userDetails(aConnection); |
433 | result['statistics'] = this.statistics(aConnection); | 429 | result['statistics'] = this.statistics(aConnection); |
434 | result['maxNumberOfRecords'] = aConnection['userData']['maxNumberOfRecords']; | 430 | result['maxNumberOfRecords'] = aConnection['userData']['maxNumberOfRecords']; |
435 | result['version'] = aConnection['userData']['userDetailsVersion']; | 431 | result['version'] = aConnection['userData']['userDetailsVersion']; |
436 | result['recordsStats'] = recordsStats; | 432 | result['recordsStats'] = recordsStats; |
437 | 433 | ||
438 | if (this.isReadOnly() == false) { | 434 | if (this.isReadOnly() == false) { |
439 | varlock; | 435 | varlock; |
440 | 436 | ||
441 | if (typeof(aConnection['userData']['lock']) == 'undefined') { | 437 | if (typeof(aConnection['userData']['lock']) == 'undefined') { |
442 | aConnection['userData']['lock'] = "<<LOCK>>"; | 438 | aConnection['userData']['lock'] = "<<LOCK>>"; |
443 | } | 439 | } |
444 | 440 | ||
445 | result['lock'] = aConnection['userData']['lock']; | 441 | result['lock'] = aConnection['userData']['lock']; |
446 | } | 442 | } |
@@ -480,325 +476,309 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | |||
480 | //===================================================================== | 476 | //===================================================================== |
481 | // | 477 | // |
482 | // R E A D - W R I T E M e t h o d s | 478 | // R E A D - W R I T E M e t h o d s |
483 | // | 479 | // |
484 | //===================================================================== | 480 | //===================================================================== |
485 | } else if (someParameters.message == 'upgradeUserCredentials') { | 481 | } else if (someParameters.message == 'upgradeUserCredentials') { |
486 | if (this.isReadOnly() == false) { | 482 | if (this.isReadOnly() == false) { |
487 | var parameters; | 483 | var parameters; |
488 | var credentials; | 484 | var credentials; |
489 | 485 | ||
490 | parameters = someParameters['parameters']; | 486 | parameters = someParameters['parameters']; |
491 | credentials = parameters['credentials']; | 487 | credentials = parameters['credentials']; |
492 | 488 | ||
493 | if ((credentials['C'] == null) | 489 | if ((credentials['C'] == null) |
494 | ||(credentials['s'] == null) | 490 | ||(credentials['s'] == null) |
495 | ||(credentials['v'] == null) | 491 | ||(credentials['v'] == null) |
496 | ||(credentials['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) | 492 | ||(credentials['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) |
497 | ) { | 493 | ) { |
498 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; | 494 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; |
499 | } else { | 495 | } else { |
500 | varoldCValue; | 496 | varoldCValue; |
501 | oldCValue = aConnection['C']; | 497 | oldCValue = aConnection['C']; |
502 | 498 | ||
503 | this.data()['users'][credentials['C']] = aConnection['userData']; | 499 | this.data()['users'][credentials['C']] = aConnection['userData']; |
504 | aConnection['C'] = credentials['C']; | 500 | aConnection['C'] = credentials['C']; |
505 | 501 | ||
506 | aConnection['userData']['s'] = credentials['s']; | 502 | aConnection['userData']['s'] = credentials['s']; |
507 | aConnection['userData']['v'] = credentials['v']; | 503 | aConnection['userData']['v'] = credentials['v']; |
508 | aConnection['userData']['version'] = credentials['version']; | 504 | aConnection['userData']['version'] = credentials['version']; |
509 | 505 | ||
510 | aConnection['userData']['userDetails'] = parameters['user']['header']; | 506 | aConnection['userData']['userDetails'] = parameters['user']['header']; |
511 | aConnection['userData']['userDetailsVersion'] = parameters['user']['version']; | 507 | aConnection['userData']['userDetailsVersion'] = parameters['user']['version']; |
512 | aConnection['userData']['statistics'] = parameters['user']['statistics']; | 508 | aConnection['userData']['statistics'] = parameters['user']['statistics']; |
513 | 509 | ||
514 | aConnection['userData']['lock'] = parameters['user']['lock']; | 510 | aConnection['userData']['lock'] = parameters['user']['lock']; |
515 | 511 | ||
516 | delete this.data()['users'][oldCValue]; | 512 | delete this.data()['users'][oldCValue]; |
517 | 513 | ||
518 | result = {result:"done", parameters:parameters}; | 514 | result = {result:"done", parameters:parameters}; |
519 | } | 515 | } |
520 | } else { | 516 | } else { |
521 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 517 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
522 | } | 518 | } |
523 | //===================================================================== | 519 | //===================================================================== |
524 | /* } else if (someParameters.message == 'updateData') { | 520 | /* } else if (someParameters.message == 'updateData') { |
525 | if (this.isReadOnly() == false) { | 521 | if (this.isReadOnly() == false) { |
526 | var i, c; | 522 | var i, c; |
527 | 523 | ||
528 | //console.log("###==============================================================="); | ||
529 | //console.log("###>>>", Clipperz.Base.serializeJSON(someParameters)); | ||
530 | //console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData())); | ||
531 | if (this.userData()['lock']!= someParameters['parameters']['user']['lock']) { | 524 | if (this.userData()['lock']!= someParameters['parameters']['user']['lock']) { |
532 | throw "the lock attribute is not processed correctly" | 525 | throw "the lock attribute is not processed correctly" |
533 | } | 526 | } |
534 | 527 | ||
535 | this.userData()['userDetails'] = someParameters['parameters']['user']['header']; | 528 | this.userData()['userDetails'] = someParameters['parameters']['user']['header']; |
536 | this.userData()['statistics'] = someParameters['parameters']['user']['statistics']; | 529 | this.userData()['statistics'] = someParameters['parameters']['user']['statistics']; |
537 | this.userData()['userDetailsVersions']= someParameters['parameters']['user']['version']; | 530 | this.userData()['userDetailsVersions']= someParameters['parameters']['user']['version']; |
538 | 531 | ||
539 | c = someParameters['parameters']['records'].length; | 532 | c = someParameters['parameters']['records'].length; |
540 | for (i=0; i<c; i++) { | 533 | for (i=0; i<c; i++) { |
541 | var currentRecord; | 534 | var currentRecord; |
542 | var currentRecordData; | 535 | var currentRecordData; |
543 | 536 | ||
544 | currentRecordData = someParameters['parameters']['records'][i]; | 537 | currentRecordData = someParameters['parameters']['records'][i]; |
545 | currentRecord = this.userData()['records'][currentRecordData['record']['reference']]; | 538 | currentRecord = this.userData()['records'][currentRecordData['record']['reference']]; |
546 | 539 | ||
547 | if (currentRecord == null) { | 540 | if (currentRecord == null) { |
548 | } | 541 | } |
549 | 542 | ||
550 | currentRecord['data'] = currentRecordData['record']['data']; | 543 | currentRecord['data'] = currentRecordData['record']['data']; |
551 | currentRecord['version'] = currentRecordData['record']['version']; | 544 | currentRecord['version'] = currentRecordData['record']['version']; |
552 | currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; | 545 | currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; |
553 | 546 | ||
554 | currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { | 547 | currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { |
555 | 'data': currentRecordData['currentRecordVersion']['data'], | 548 | 'data': currentRecordData['currentRecordVersion']['data'], |
556 | 'version': currentRecordData['currentRecordVersion']['version'], | 549 | 'version': currentRecordData['currentRecordVersion']['version'], |
557 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], | 550 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], |
558 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'] | 551 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'] |
559 | } | 552 | } |
560 | } | 553 | } |
561 | 554 | ||
562 | this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); | 555 | this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); |
563 | result['lock'] = this.userData()['lock']; | 556 | result['lock'] = this.userData()['lock']; |
564 | result['result'] = 'done'; | 557 | result['result'] = 'done'; |
565 | //console.log("###<<< userData", Clipperz.Base.serializeJSON(this.userData())); | ||
566 | } else { | 558 | } else { |
567 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 559 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
568 | } | 560 | } |
569 | */ //===================================================================== | 561 | */ //===================================================================== |
570 | } else if (someParameters.message == 'saveChanges') { | 562 | } else if (someParameters.message == 'saveChanges') { |
571 | if (this.isReadOnly() == false) { | 563 | if (this.isReadOnly() == false) { |
572 | var i, c; | 564 | var i, c; |
573 | 565 | ||
574 | //console.log("###==============================================================="); | ||
575 | //console.log("###>>>", someParameters); | ||
576 | //console.log("###>>>", Clipperz.Base.serializeJSON(someParameters)); | ||
577 | //console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData())); | ||
578 | //console.log("###==============================================================="); | ||
579 | //console.log("--- userData.lock ", this.userData()['lock']); | ||
580 | //console.log("--- parameters.lock", someParameters['parameters']['user']['lock']); | ||
581 | if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) { | 566 | if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) { |
582 | throw "the lock attribute is not processed correctly" | 567 | throw "the lock attribute is not processed correctly" |
583 | } | 568 | } |
584 | 569 | ||
585 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; | 570 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; |
586 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; | 571 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; |
587 | aConnection['userData']['userDetailsVersions']= someParameters['parameters']['user']['version']; | 572 | aConnection['userData']['userDetailsVersions']= someParameters['parameters']['user']['version']; |
588 | 573 | ||
589 | c = someParameters['parameters']['records']['updated'].length; | 574 | c = someParameters['parameters']['records']['updated'].length; |
590 | for (i=0; i<c; i++) { | 575 | for (i=0; i<c; i++) { |
591 | var currentRecord; | 576 | var currentRecord; |
592 | var currentRecordData; | 577 | var currentRecordData; |
593 | 578 | ||
594 | currentRecordData = someParameters['parameters']['records']['updated'][i]; | 579 | currentRecordData = someParameters['parameters']['records']['updated'][i]; |
595 | currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; | 580 | currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; |
596 | 581 | ||
597 | if ( | 582 | if ( |
598 | (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') | 583 | (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') |
599 | && | 584 | && |
600 | (typeof(currentRecordData['currentRecordVersion']) == 'undefined') | 585 | (typeof(currentRecordData['currentRecordVersion']) == 'undefined') |
601 | ) { | 586 | ) { |
602 | //console.log("######## SHIT HAPPENS"); | ||
603 | throw "Record added without a recordVersion"; | 587 | throw "Record added without a recordVersion"; |
604 | } | 588 | } |
605 | 589 | ||
606 | if (currentRecord == null) { | 590 | if (currentRecord == null) { |
607 | currentRecord = {}; | 591 | currentRecord = {}; |
608 | currentRecord['versions'] = {}; | 592 | currentRecord['versions'] = {}; |
609 | currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 593 | currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
610 | currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 594 | currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
611 | 595 | ||
612 | aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; | 596 | aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; |
613 | } | 597 | } |
614 | 598 | ||
615 | currentRecord['data'] = currentRecordData['record']['data']; | 599 | currentRecord['data'] = currentRecordData['record']['data']; |
616 | currentRecord['version']= currentRecordData['record']['version']; | 600 | currentRecord['version']= currentRecordData['record']['version']; |
617 | currentRecord['updateDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 601 | currentRecord['updateDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
618 | 602 | ||
619 | if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') { | 603 | if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') { |
620 | currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; | 604 | currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; |
621 | currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { | 605 | currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { |
622 | 'data': currentRecordData['currentRecordVersion']['data'], | 606 | 'data': currentRecordData['currentRecordVersion']['data'], |
623 | 'version': currentRecordData['currentRecordVersion']['version'], | 607 | 'version': currentRecordData['currentRecordVersion']['version'], |
624 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], | 608 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], |
625 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'], | 609 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'], |
626 | 'creationDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), | 610 | 'creationDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), |
627 | 'updateDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), | 611 | 'updateDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), |
628 | 'accessDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()) | 612 | 'accessDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()) |
629 | } | 613 | } |
630 | } | 614 | } |
631 | } | 615 | } |
632 | 616 | ||
633 | c = someParameters['parameters']['records']['deleted'].length; | 617 | c = someParameters['parameters']['records']['deleted'].length; |
634 | for (i=0; i<c; i++) { | 618 | for (i=0; i<c; i++) { |
635 | var currentRecordReference; | 619 | var currentRecordReference; |
636 | 620 | ||
637 | currentRecordReference = someParameters['parameters']['records']['deleted'][i]; | 621 | currentRecordReference = someParameters['parameters']['records']['deleted'][i]; |
638 | //console.log("DELETING records", currentRecordReference); | ||
639 | delete aConnection['userData']['records'][currentRecordReference]; | 622 | delete aConnection['userData']['records'][currentRecordReference]; |
640 | } | 623 | } |
641 | 624 | ||
642 | aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey(); | 625 | aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey(); |
643 | result['lock'] = aConnection['userData']['lock']; | 626 | result['lock'] = aConnection['userData']['lock']; |
644 | result['result'] = 'done'; | 627 | result['result'] = 'done'; |
645 | //console.log("###<<< userData", Clipperz.Base.serializeJSON(this.userData())); | ||
646 | } else { | 628 | } else { |
647 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 629 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
648 | } | 630 | } |
649 | 631 | ||
650 | //===================================================================== | 632 | //===================================================================== |
651 | // | 633 | // |
652 | // U N H A N D L E D M e t h o d | 634 | // U N H A N D L E D M e t h o d |
653 | // | 635 | // |
654 | //===================================================================== | 636 | //===================================================================== |
655 | } else { | 637 | } else { |
656 | MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message); | 638 | Clipperz.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message); |
657 | } | 639 | } |
658 | 640 | ||
659 | result = { | 641 | result = { |
660 | result: result, | 642 | result: result, |
661 | toll: this.getTollForRequestType('MESSAGE') | 643 | toll: this.getTollForRequestType('MESSAGE') |
662 | } | 644 | } |
663 | 645 | ||
664 | // return MochiKit.Async.succeed(result); | 646 | // return MochiKit.Async.succeed(result); |
665 | return result; | 647 | return result; |
666 | }, | 648 | }, |
667 | 649 | ||
668 | //------------------------------------------------------------------------- | 650 | //------------------------------------------------------------------------- |
669 | 651 | ||
670 | '_logout': function(someParameters) { | 652 | '_logout': function(someParameters) { |
671 | // return MochiKit.Async.succeed({result: 'done'}); | 653 | // return MochiKit.Async.succeed({result: 'done'}); |
672 | return {result: 'done'}; | 654 | return {result: 'done'}; |
673 | }, | 655 | }, |
674 | 656 | ||
675 | //========================================================================= | 657 | //========================================================================= |
676 | //######################################################################### | 658 | //######################################################################### |
677 | 659 | ||
678 | 'isTestData': function(aConnection) { | 660 | 'isTestData': function(aConnection) { |
679 | return (typeof(aConnection['userData']['__masterkey_test_value__']) != 'undefined'); | 661 | return (typeof(aConnection['userData']['__masterkey_test_value__']) != 'undefined'); |
680 | }, | 662 | }, |
681 | 663 | ||
682 | 'userDetails': function(aConnection) { | 664 | 'userDetails': function(aConnection) { |
683 | var result; | 665 | var result; |
684 | 666 | ||
685 | if (this.isTestData(aConnection)) { | 667 | if (this.isTestData(aConnection)) { |
686 | var serializedHeader; | 668 | var serializedHeader; |
687 | var version; | 669 | var version; |
688 | 670 | ||
689 | //MochiKit.Logging.logDebug("### test data"); | 671 | //Clipperz.logDebug("### test data"); |
690 | version = aConnection['userData']['userDetailsVersion']; | 672 | version = aConnection['userData']['userDetailsVersion']; |
691 | serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']); | 673 | serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']); |
692 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader); | 674 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader); |
693 | } else { | 675 | } else { |
694 | //MochiKit.Logging.logDebug("### NOT test data"); | 676 | //Clipperz.logDebug("### NOT test data"); |
695 | result = aConnection['userData']['userDetails']; | 677 | result = aConnection['userData']['userDetails']; |
696 | } | 678 | } |
697 | 679 | ||
698 | return result; | 680 | return result; |
699 | }, | 681 | }, |
700 | 682 | ||
701 | 'statistics': function(aConnection) { | 683 | 'statistics': function(aConnection) { |
702 | var result; | 684 | var result; |
703 | 685 | ||
704 | if (aConnection['userData']['statistics'] != null) { | 686 | if (aConnection['userData']['statistics'] != null) { |
705 | if (this.isTestData(aConnection)) { | 687 | if (this.isTestData(aConnection)) { |
706 | var serializedStatistics; | 688 | var serializedStatistics; |
707 | var version; | 689 | var version; |
708 | 690 | ||
709 | version = aConnection['userData']['userDetailsVersion']; | 691 | version = aConnection['userData']['userDetailsVersion']; |
710 | serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']); | 692 | serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']); |
711 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics); | 693 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics); |
712 | } else { | 694 | } else { |
713 | result = aConnection['userData']['statistics']; | 695 | result = aConnection['userData']['statistics']; |
714 | } | 696 | } |
715 | } else { | 697 | } else { |
716 | result = null; | 698 | result = null; |
717 | } | 699 | } |
718 | 700 | ||
719 | return result; | 701 | return result; |
720 | }, | 702 | }, |
721 | 703 | ||
722 | /* | 704 | /* |
723 | 'userSerializedEncryptedData': function(someData) { | 705 | 'userSerializedEncryptedData': function(someData) { |
724 | var deferredResult; | 706 | var deferredResult; |
725 | var deferredContext; | 707 | var deferredContext; |
726 | 708 | ||
727 | deferredContext = { 'data': someData }; | 709 | deferredContext = { 'data': someData }; |
728 | 710 | ||
729 | deferredResult = new Clipperz.Async.Deferred('Proxy.Test.serializeUserEncryptedData', {trace:false}); | 711 | deferredResult = new Clipperz.Async.Deferred('Proxy.Test.serializeUserEncryptedData', {trace:false}); |
730 | deferredResult.addCallback(MochiKit.Base.bind(function(aDeferredContext) { | 712 | deferredResult.addCallback(MochiKit.Base.bind(function(aDeferredContext) { |
731 | aDeferredContext['user'] = this.createUserUsingConfigurationData(aDeferredContext['data']); | 713 | aDeferredContext['user'] = this.createUserUsingConfigurationData(aDeferredContext['data']); |
732 | return aDeferredContext; | 714 | return aDeferredContext; |
733 | }, this)); | 715 | }, this)); |
734 | deferredResult.addCallback(function(aDeferredContext) { | 716 | deferredResult.addCallback(function(aDeferredContext) { |
735 | // return aDeferredContext['user'].encryptedDataUsingVersion(aDeferredContext['data']['version']); | 717 | // return aDeferredContext['user'].encryptedDataUsingVersion(aDeferredContext['data']['version']); |
736 | return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); | 718 | return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); |
737 | }); | 719 | }); |
738 | deferredResult.addCallback(function(aUserEncryptedData) { | 720 | deferredResult.addCallback(function(aUserEncryptedData) { |
739 | deferredContext['encryptedData'] = aUserEncryptedData; | 721 | deferredContext['encryptedData'] = aUserEncryptedData; |
740 | return deferredContext; | 722 | return deferredContext; |
741 | }); | 723 | }); |
742 | deferredResult.addCallback(function(aDeferredContext) { | 724 | deferredResult.addCallback(function(aDeferredContext) { |
743 | var connection; | 725 | var connection; |
744 | 726 | ||
745 | connection = new Clipperz.PM.Connection.communicationProtocol.versions[aDeferredContext['data']['connectionVersion']]() | 727 | connection = new Clipperz.PM.Connection.communicationProtocol.versions[aDeferredContext['data']['connectionVersion']]() |
746 | aDeferredContext['credentials'] = connection.serverSideUserCredentials(aDeferredContext['user'].username(),aDeferredContext['user'].passphrase()); | 728 | aDeferredContext['credentials'] = connection.serverSideUserCredentials(aDeferredContext['user'].username(),aDeferredContext['user'].passphrase()); |
747 | 729 | ||
748 | return aDeferredContext; | 730 | return aDeferredContext; |
749 | }); | 731 | }); |
750 | 732 | ||
751 | // deferredResult.addCallback(function(aDeferredContext) { | 733 | // deferredResult.addCallback(function(aDeferredContext) { |
752 | //console.log("#-#-#-#-#", aDeferredContext); | ||
753 | // return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); | 734 | // return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); |
754 | // }, deferredContext); | 735 | // }, deferredContext); |
755 | // deferredResult.addCallback(function(aUserSerializedData) { | 736 | // deferredResult.addCallback(function(aUserSerializedData) { |
756 | //console.log("USER SERIALIZED DATA", aUserSerializedData); | ||
757 | // }); | 737 | // }); |
758 | // | 738 | // |
759 | // deferredResult.addCallback(MochiKit.Async.succeed, deferredContext); | 739 | // deferredResult.addCallback(MochiKit.Async.succeed, deferredContext); |
760 | deferredResult.callback(deferredContext); | 740 | deferredResult.callback(deferredContext); |
761 | 741 | ||
762 | return deferredResult; | 742 | return deferredResult; |
763 | }, | 743 | }, |
764 | 744 | ||
765 | 'createUserUsingConfigurationData': function(someData) { | 745 | 'createUserUsingConfigurationData': function(someData) { |
766 | var result; | 746 | var result; |
767 | var user; | 747 | var user; |
768 | var recordLabel; | 748 | var recordLabel; |
769 | 749 | ||
770 | user = new Clipperz.PM.DataModel.User(); | 750 | user = new Clipperz.PM.DataModel.User(); |
771 | user.initForTests(); | 751 | user.initForTests(); |
772 | user.setUsername(someData['username']); | 752 | user.setUsername(someData['username']); |
773 | user.setPassphrase(someData['passphrase']); | 753 | user.setPassphrase(someData['passphrase']); |
774 | 754 | ||
775 | for (recordLabel in someData['records']) { | 755 | for (recordLabel in someData['records']) { |
776 | var recordData; | 756 | var recordData; |
777 | var record; | 757 | var record; |
778 | var i, c; | 758 | var i, c; |
779 | 759 | ||
780 | recordData = someData['records'][recordLabel]; | 760 | recordData = someData['records'][recordLabel]; |
781 | record = new Clipperz.PM.DataModel.Record({user:user, label:recordLabel}); | 761 | record = new Clipperz.PM.DataModel.Record({user:user, label:recordLabel}); |
782 | record.setNotes(recordData['notes']); | 762 | record.setNotes(recordData['notes']); |
783 | 763 | ||
784 | c = recordData['fields'].length; | 764 | c = recordData['fields'].length; |
785 | for (i=0; i<c; i++) { | 765 | for (i=0; i<c; i++) { |
786 | var recordField; | 766 | var recordField; |
787 | 767 | ||
788 | recordField = new Clipperz.PM.DataModel.RecordField(); | 768 | recordField = new Clipperz.PM.DataModel.RecordField(); |
789 | recordField.setLabel(recordData['fields'][i]['name']); | 769 | recordField.setLabel(recordData['fields'][i]['name']); |
790 | recordField.setValue(recordData['fields'][i]['value']); | 770 | recordField.setValue(recordData['fields'][i]['value']); |
791 | recordField.setType(recordData['fields'][i]['type']); | 771 | recordField.setType(recordData['fields'][i]['type']); |
792 | record.addField(recordField); | 772 | record.addField(recordField); |
793 | } | 773 | } |
794 | user.addRecord(record, true); | 774 | user.addRecord(record, true); |
795 | } | 775 | } |
796 | 776 | ||
797 | result = user; | 777 | result = user; |
798 | 778 | ||
799 | return result; | 779 | return result; |
800 | }, | 780 | }, |
801 | */ | 781 | */ |
802 | //========================================================================= | 782 | //========================================================================= |
803 | __syntaxFix__: "syntax fix" | 783 | __syntaxFix__: "syntax fix" |
804 | }); | 784 | }); |