author | Clipperz <info@clipperz.com> | 2013-01-08 15:17:30 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-08 15:17:30 (UTC) |
commit | 267603e3aa3cf0029411e67ae14018b52344c296 (patch) (unidiff) | |
tree | 055e8f8d8543ed6bfa342dbf4641fea308c2ec5a /frontend | |
parent | b6a11a37ec3271bd44fc23b9da00c5b052b0d8b9 (diff) | |
download | clipperz-267603e3aa3cf0029411e67ae14018b52344c296.zip clipperz-267603e3aa3cf0029411e67ae14018b52344c296.tar.gz clipperz-267603e3aa3cf0029411e67ae14018b52344c296.tar.bz2 |
Fixed corrupted card problem
Changes that check for a weird condition that was causing cards to get corrupted.
A similar change has been applied also to /gamma (in a different commit, though)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Connection.js | 9 | ||||
-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Record.js | 12 | ||||
-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/User.js | 17 |
3 files changed, 24 insertions, 14 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Connection.js b/frontend/beta/js/Clipperz/PM/Connection.js index 85aea21..e81c7a6 100644 --- a/frontend/beta/js/Clipperz/PM/Connection.js +++ b/frontend/beta/js/Clipperz/PM/Connection.js | |||
@@ -107,475 +107,480 @@ MochiKit.Logging.logError("### Connection.defaultErrorHandler: " + anErrorString | |||
107 | 'sharedSecret': function() { | 107 | 'sharedSecret': function() { |
108 | throw Clipperz.Base.exception.AbstractMethod; | 108 | throw Clipperz.Base.exception.AbstractMethod; |
109 | }, | 109 | }, |
110 | 110 | ||
111 | 'serverSideUserCredentials': function() { | 111 | 'serverSideUserCredentials': function() { |
112 | throw Clipperz.Base.exception.AbstractMethod; | 112 | throw Clipperz.Base.exception.AbstractMethod; |
113 | }, | 113 | }, |
114 | 114 | ||
115 | //========================================================================= | 115 | //========================================================================= |
116 | 116 | ||
117 | 'connectionId': function() { | 117 | 'connectionId': function() { |
118 | return this._connectionId; | 118 | return this._connectionId; |
119 | }, | 119 | }, |
120 | 120 | ||
121 | 'setConnectionId': function(aValue) { | 121 | 'setConnectionId': function(aValue) { |
122 | this._connectionId = aValue; | 122 | this._connectionId = aValue; |
123 | }, | 123 | }, |
124 | 124 | ||
125 | //========================================================================= | 125 | //========================================================================= |
126 | 126 | ||
127 | 'oneTimePassword': function() { | 127 | 'oneTimePassword': function() { |
128 | return this._oneTimePassword; | 128 | return this._oneTimePassword; |
129 | }, | 129 | }, |
130 | 130 | ||
131 | 'setOneTimePassword': function(aValue) { | 131 | 'setOneTimePassword': function(aValue) { |
132 | this._oneTimePassword = aValue; | 132 | this._oneTimePassword = aValue; |
133 | }, | 133 | }, |
134 | 134 | ||
135 | //========================================================================= | 135 | //========================================================================= |
136 | __syntaxFix__: "syntax fix" | 136 | __syntaxFix__: "syntax fix" |
137 | 137 | ||
138 | } | 138 | } |
139 | ); | 139 | ); |
140 | 140 | ||
141 | 141 | ||
142 | if (typeof(Clipperz.PM.Connection.SRP) == 'undefined') { Clipperz.PM.Connection.SRP = {}; } | 142 | if (typeof(Clipperz.PM.Connection.SRP) == 'undefined') { Clipperz.PM.Connection.SRP = {}; } |
143 | //----------------------------------------------------------------------------- | 143 | //----------------------------------------------------------------------------- |
144 | // | 144 | // |
145 | // S R P [ 1 . 0 ] C O N N E C T I O N class | 145 | // S R P [ 1 . 0 ] C O N N E C T I O N class |
146 | // | 146 | // |
147 | //----------------------------------------------------------------------------- | 147 | //----------------------------------------------------------------------------- |
148 | 148 | ||
149 | Clipperz.PM.Connection.SRP['1.0'] = function (args) { | 149 | Clipperz.PM.Connection.SRP['1.0'] = function (args) { |
150 | args = args || {}; | 150 | args = args || {}; |
151 | Clipperz.PM.Connection.call(this, args); | 151 | Clipperz.PM.Connection.call(this, args); |
152 | 152 | ||
153 | this._C = null; | 153 | this._C = null; |
154 | this._P = null; | 154 | this._P = null; |
155 | this._srpConnection = null; | 155 | this._srpConnection = null; |
156 | 156 | ||
157 | return this; | 157 | return this; |
158 | } | 158 | } |
159 | 159 | ||
160 | Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection(), { | 160 | Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection(), { |
161 | 161 | ||
162 | 'version': function() { | 162 | 'version': function() { |
163 | return '1.0'; | 163 | return '1.0'; |
164 | }, | 164 | }, |
165 | 165 | ||
166 | //========================================================================= | 166 | //========================================================================= |
167 | 167 | ||
168 | 'register': function(anInvitationCode) { | 168 | 'register': function(anInvitationCode) { |
169 | var deferredResult; | 169 | var deferredResult; |
170 | varparameters; | 170 | varparameters; |
171 | 171 | ||
172 | //MochiKit.Logging.logError(">>> Connection.register: " + this); | 172 | //MochiKit.Logging.logError(">>> Connection.register: " + this); |
173 | parameters = {}; | 173 | parameters = {}; |
174 | deferredResult = new MochiKit.Async.Deferred(); | 174 | deferredResult = new MochiKit.Async.Deferred(); |
175 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 1: " + res); return res;}); | 175 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 1: " + res); return res;}); |
176 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_verify'); | 176 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_verify'); |
177 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 2: " + res); return res;}); | 177 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 2: " + res); return res;}); |
178 | deferredResult.addCallback(function(aConnection, anInvitationCode) { | 178 | deferredResult.addCallback(function(aConnection, anInvitationCode) { |
179 | var args; | 179 | var args; |
180 | 180 | ||
181 | args = {}; | 181 | args = {}; |
182 | args.message = 'register'; | 182 | args.message = 'register'; |
183 | args.version = aConnection.clipperz_pm_crypto_version(); | 183 | args.version = aConnection.clipperz_pm_crypto_version(); |
184 | args.invitationCode = anInvitationCode; | 184 | args.invitationCode = anInvitationCode; |
185 | 185 | ||
186 | return args; | 186 | return args; |
187 | }, this); | 187 | }, this); |
188 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 3: " + res); return res;}); | 188 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 3: " + res); return res;}); |
189 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_sendingCredentials'); | 189 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_sendingCredentials'); |
190 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 4: " + res); return res;}); | 190 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 4: " + res); return res;}); |
191 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); | 191 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); |
192 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 5: " + res); return res;}); | 192 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 5: " + res); return res;}); |
193 | deferredResult.addCallback(function(someParameters, anUser, anEncryptedData) { | 193 | deferredResult.addCallback(function(someParameters, anUser, anEncryptedData) { |
194 | var currentVersionConnection; | 194 | var currentVersionConnection; |
195 | var args; | 195 | var args; |
196 | 196 | ||
197 | currentVersionConnection = new Clipperz.PM.Crypto.communicationProtocol.versions['current']({user:anUser}); | 197 | currentVersionConnection = new Clipperz.PM.Crypto.communicationProtocol.versions['current']({user:anUser}); |
198 | 198 | ||
199 | args = someParameters | 199 | args = someParameters |
200 | args.credentials = currentVersionConnection.serverSideUserCredentials(); | 200 | args.credentials = currentVersionConnection.serverSideUserCredentials(); |
201 | args.user = anEncryptedData; | 201 | args.user = anEncryptedData; |
202 | args.version = args.credentials.version; | 202 | args.version = args.credentials.version; |
203 | args.message = "completeRegistration"; | 203 | args.message = "completeRegistration"; |
204 | 204 | ||
205 | return args; | 205 | return args; |
206 | }, parameters, this.user()); | 206 | }, parameters, this.user()); |
207 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 6: " + res); return res;}); | 207 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 6: " + res); return res;}); |
208 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'registration')); | 208 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'registration')); |
209 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 7: " + Clipperz.Base.serializeJSON(res)); return res;}); | 209 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 7: " + Clipperz.Base.serializeJSON(res)); return res;}); |
210 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | 210 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { |
211 | this.user().setLock(res['lock']); | 211 | this.user().setLock(res['lock']); |
212 | 212 | ||
213 | return res; | 213 | return res; |
214 | }, this)); | 214 | }, this)); |
215 | deferredResult.callback(anInvitationCode); | 215 | deferredResult.callback(anInvitationCode); |
216 | //MochiKit.Logging.logError("<<< Connection.register"); | 216 | //MochiKit.Logging.logError("<<< Connection.register"); |
217 | 217 | ||
218 | return deferredResult; | 218 | return deferredResult; |
219 | }, | 219 | }, |
220 | 220 | ||
221 | //========================================================================= | 221 | //========================================================================= |
222 | 222 | ||
223 | 'login': function(isReconnecting) { | 223 | 'login': function(isReconnecting) { |
224 | vardeferredResult; | 224 | vardeferredResult; |
225 | 225 | ||
226 | //MochiKit.Logging.logDebug(">>> Connection.login: "/* + this*/); | 226 | //MochiKit.Logging.logDebug(">>> Connection.login: "/* + this*/); |
227 | //MochiKit.Logging.logDebug("--- Connection.login - isReconnecting: " + (isReconnecting == true)); | 227 | //MochiKit.Logging.logDebug("--- Connection.login - isReconnecting: " + (isReconnecting == true)); |
228 | deferredResult = new MochiKit.Async.Deferred(); | 228 | deferredResult = new MochiKit.Async.Deferred(); |
229 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.1 - Connection.login - 1: "/* + res*/); return res;}); | 229 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.1 - Connection.login - 1: "/* + res*/); return res;}); |
230 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 230 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
231 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_sendingCredentials'); | 231 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_sendingCredentials'); |
232 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.2 - Connection.login - 2: "/* + res*/); return res;}); | 232 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.2 - Connection.login - 2: "/* + res*/); return res;}); |
233 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 233 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
234 | deferredResult.addCallback(function(aConnection) { | 234 | deferredResult.addCallback(function(aConnection) { |
235 | var args; | 235 | var args; |
236 | 236 | ||
237 | args = {}; | 237 | args = {}; |
238 | args.message = 'connect'; | 238 | args.message = 'connect'; |
239 | args.version = aConnection.clipperz_pm_crypto_version(); | 239 | args.version = aConnection.clipperz_pm_crypto_version(); |
240 | args.parameters = {}; | 240 | args.parameters = {}; |
241 | //MochiKit.Logging.logDebug("=== Connection.login - username: " + aConnection.srpConnection().C()); | 241 | //MochiKit.Logging.logDebug("=== Connection.login - username: " + aConnection.srpConnection().C()); |
242 | args.parameters['C'] = aConnection.srpConnection().C(); | 242 | args.parameters['C'] = aConnection.srpConnection().C(); |
243 | args.parameters['A'] = aConnection.srpConnection().A().asString(16); | 243 | args.parameters['A'] = aConnection.srpConnection().A().asString(16); |
244 | 244 | ||
245 | if (isReconnecting == true) { | 245 | if (isReconnecting == true) { |
246 | //MochiKit.Logging.logDebug("--- Connection.login - reconnecting"); | 246 | //MochiKit.Logging.logDebug("--- Connection.login - reconnecting"); |
247 | //# args.parameters['reconnecting'] = "yes"; | 247 | //# args.parameters['reconnecting'] = "yes"; |
248 | args.parameters['reconnecting'] = aConnection.connectionId(); | 248 | args.parameters['reconnecting'] = aConnection.connectionId(); |
249 | } | 249 | } |
250 | //MochiKit.Logging.logDebug("--- Connection.login - args: " + Clipperz.Base.serializeJSON(args)); | 250 | //MochiKit.Logging.logDebug("--- Connection.login - args: " + Clipperz.Base.serializeJSON(args)); |
251 | //MochiKit.Logging.logDebug("--- Connection.login - srp.a: " + aConnection.srpConnection().a().asString(16)); | 251 | //MochiKit.Logging.logDebug("--- Connection.login - srp.a: " + aConnection.srpConnection().a().asString(16)); |
252 | 252 | ||
253 | return args; | 253 | return args; |
254 | }); | 254 | }); |
255 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.3 - Connection.login - 3: "/* + res*/); return res;}); | 255 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.3 - Connection.login - 3: "/* + res*/); return res;}); |
256 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 256 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
257 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); | 257 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); |
258 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.4 - Connection.login - 4: "/* + res*/); return res;}); | 258 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.4 - Connection.login - 4: "/* + res*/); return res;}); |
259 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 259 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
260 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_credentialVerification'); | 260 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_credentialVerification'); |
261 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.5 - Connection.login - 5: "/* + res*/); return res;}); | 261 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.5 - Connection.login - 5: "/* + res*/); return res;}); |
262 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 262 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
263 | deferredResult.addErrback(MochiKit.Base.bind(function(res) {MochiKit.Logging.logDebug("ERROR - c: " + this.srpConnection().C() + " # version: " + this.clipperz_pm_crypto_version()); return res;}, this)); | 263 | deferredResult.addErrback(MochiKit.Base.bind(function(res) {MochiKit.Logging.logDebug("ERROR - c: " + this.srpConnection().C() + " # version: " + this.clipperz_pm_crypto_version()); return res;}, this)); |
264 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { | 264 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { |
265 | var args; | 265 | var args; |
266 | 266 | ||
267 | this.srpConnection().set_s(new Clipperz.Crypto.BigInt(someParameters['s'], 16)); | 267 | this.srpConnection().set_s(new Clipperz.Crypto.BigInt(someParameters['s'], 16)); |
268 | this.srpConnection().set_B(new Clipperz.Crypto.BigInt(someParameters['B'], 16)); | 268 | this.srpConnection().set_B(new Clipperz.Crypto.BigInt(someParameters['B'], 16)); |
269 | 269 | ||
270 | if (typeof(someParameters['oneTimePassword']) != 'undefined') { | 270 | if (typeof(someParameters['oneTimePassword']) != 'undefined') { |
271 | this.setOneTimePassword(someParameters['oneTimePassword']); | 271 | this.setOneTimePassword(someParameters['oneTimePassword']); |
272 | } | 272 | } |
273 | 273 | ||
274 | args = {}; | 274 | args = {}; |
275 | args.message = 'credentialCheck'; | 275 | args.message = 'credentialCheck'; |
276 | args.version = this.clipperz_pm_crypto_version(); | 276 | args.version = this.clipperz_pm_crypto_version(); |
277 | args.parameters = {}; | 277 | args.parameters = {}; |
278 | args.parameters['M1'] = this.srpConnection().M1(); | 278 | args.parameters['M1'] = this.srpConnection().M1(); |
279 | 279 | ||
280 | return args; | 280 | return args; |
281 | }, this)); | 281 | }, this)); |
282 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.6 - Connection.login - 6: "/* + res*/); return res;}); | 282 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.6 - Connection.login - 6: "/* + res*/); return res;}); |
283 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 283 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
284 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); | 284 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); |
285 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.7 - Connection.login - 7: "/* + res*/); return res;}); | 285 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.7 - Connection.login - 7: "/* + res*/); return res;}); |
286 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 286 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
287 | //# deferredResult.addCallback(MochiKit.Base.method(this, 'loginDone')); | 287 | //# deferredResult.addCallback(MochiKit.Base.method(this, 'loginDone')); |
288 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { | 288 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { |
289 | var result; | 289 | var result; |
290 | 290 | ||
291 | //MochiKit.Logging.logDebug(">>> Connection.loginDone: " + this + " (M2: " + this.srpConnection().M2() + ")"); | 291 | //MochiKit.Logging.logDebug(">>> Connection.loginDone: " + this + " (M2: " + this.srpConnection().M2() + ")"); |
292 | if (someParameters['M2'] == this.srpConnection().M2()) { | 292 | if (someParameters['M2'] == this.srpConnection().M2()) { |
293 | result = new MochiKit.Async.Deferred(); | 293 | result = new MochiKit.Async.Deferred(); |
294 | 294 | ||
295 | //MochiKit.Logging.logDebug("--- Connection.loginDone - someParameters: " + Clipperz.Base.serializeJSON(someParameters)); | 295 | //MochiKit.Logging.logDebug("--- Connection.loginDone - someParameters: " + Clipperz.Base.serializeJSON(someParameters)); |
296 | this.setConnectionId(someParameters['connectionId']); | 296 | this.setConnectionId(someParameters['connectionId']); |
297 | this.user().setLoginInfo(someParameters['loginInfo']); | 297 | this.user().setLoginInfo(someParameters['loginInfo']); |
298 | this.user().setShouldDownloadOfflineCopy(someParameters['offlineCopyNeeded']); | 298 | this.user().setShouldDownloadOfflineCopy(someParameters['offlineCopyNeeded']); |
299 | this.user().setLock(someParameters['lock']); | 299 | |
300 | if ((isReconnecting == true) && (this.user().lock() != someParameters['lock'])) { | ||
301 | throw Clipperz.PM.Connection.exception.StaleData; | ||
302 | } | ||
300 | 303 | ||
301 | if (this.oneTimePassword() != null) { | 304 | if (this.oneTimePassword() != null) { |
302 | result.addCallback(MochiKit.Base.method(this.user().oneTimePasswordManager(), 'archiveOneTimePassword', this.oneTimePassword())); | 305 | result.addCallback(MochiKit.Base.method(this.user().oneTimePasswordManager(), 'archiveOneTimePassword', this.oneTimePassword())); |
303 | } | 306 | } |
307 | |||
304 | result.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_loggedIn'); | 308 | result.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_loggedIn'); |
305 | result.addCallback(MochiKit.Async.succeed, someParameters); | 309 | result.addCallback(MochiKit.Async.succeed, someParameters); |
306 | 310 | ||
307 | result.callback(); | 311 | result.callback(); |
308 | //MochiKit.Logging.logDebug("--- Connection.loginDone - 1 - result: "/* + Clipperz.Base.serializeJSON(result)*/); | 312 | //MochiKit.Logging.logDebug("--- Connection.loginDone - 1 - result: "/* + Clipperz.Base.serializeJSON(result)*/); |
309 | } else { | 313 | } else { |
310 | //MochiKit.Logging.logDebug("--- Connection.loginDone - 2 - ERROR"); | 314 | //MochiKit.Logging.logDebug("--- Connection.loginDone - 2 - ERROR"); |
311 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 315 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
312 | result = MochiKit.Async.fail(Clipperz.PM.Connection.exception.WrongChecksum); | 316 | result = MochiKit.Async.fail(Clipperz.PM.Connection.exception.WrongChecksum); |
313 | } | 317 | } |
314 | //MochiKit.Logging.logDebug("<<< Connection.loginDone - result: " + Clipperz.Base.serializeJSON(result)); | 318 | //MochiKit.Logging.logDebug("<<< Connection.loginDone - result: " + Clipperz.Base.serializeJSON(result)); |
315 | 319 | ||
316 | return result; | 320 | return result; |
317 | }, this)); | 321 | }, this)); |
318 | 322 | ||
319 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.8 - Connection.login - 8: "/* + res*/); return res;}); | 323 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.8 - Connection.login - 8: "/* + res*/); return res;}); |
320 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 324 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
321 | deferredResult.callback(this); | 325 | deferredResult.callback(this); |
322 | //MochiKit.Logging.logDebug("<<< Connection.login"); | 326 | //MochiKit.Logging.logDebug("<<< Connection.login"); |
323 | 327 | ||
324 | return deferredResult; | 328 | return deferredResult; |
325 | }, | 329 | }, |
326 | 330 | ||
327 | //========================================================================= | 331 | //========================================================================= |
328 | 332 | ||
329 | 'logout': function() { | 333 | 'logout': function() { |
330 | var deferredResult; | 334 | var deferredResult; |
331 | 335 | ||
332 | //MochiKit.Logging.logDebug(">>> Connection.logout: " + this); | 336 | //MochiKit.Logging.logDebug(">>> Connection.logout: " + this); |
333 | deferredResult = new MochiKit.Async.Deferred(); | 337 | deferredResult = new MochiKit.Async.Deferred(); |
334 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 1: " + res); return res;}); | 338 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 1: " + res); return res;}); |
335 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'logout'), {}); | 339 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'logout'), {}); |
336 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 2: " + res); return res;}); | 340 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 2: " + res); return res;}); |
337 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection')); | 341 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection')); |
338 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 3: " + res); return res;}); | 342 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 3: " + res); return res;}); |
339 | deferredResult.callback(); | 343 | deferredResult.callback(); |
340 | //MochiKit.Logging.logDebug("<<< Connection.logout"); | 344 | //MochiKit.Logging.logDebug("<<< Connection.logout"); |
341 | 345 | ||
342 | return deferredResult; | 346 | return deferredResult; |
343 | }, | 347 | }, |
344 | 348 | ||
345 | //========================================================================= | 349 | //========================================================================= |
346 | 350 | ||
347 | 'message': function(aMessageName, someParameters) { | 351 | 'message': function(aMessageName, someParameters) { |
348 | var args; | 352 | var args; |
349 | var deferredResult; | 353 | var deferredResult; |
350 | 354 | ||
351 | //MochiKit.Logging.logDebug(">>> Connection.message: " + this); | 355 | //MochiKit.Logging.logDebug(">>> Connection.message: " + this); |
352 | args = {} | 356 | args = {} |
353 | args['message'] = aMessageName; | 357 | args['message'] = aMessageName; |
354 | args['srpSharedSecret'] = this.srpConnection().K(); | 358 | args['srpSharedSecret'] = this.srpConnection().K(); |
355 | // args['lock'] = this.user().lock(); | 359 | // args['lock'] = this.user().lock(); |
356 | 360 | ||
357 | if (someParameters != null) { | 361 | if (someParameters != null) { |
358 | args['parameters'] = someParameters; | 362 | args['parameters'] = someParameters; |
359 | } else { | 363 | } else { |
360 | args['parameters'] = {}; | 364 | args['parameters'] = {}; |
361 | } | 365 | } |
362 | //MochiKit.Logging.logDebug("--- Connection.message - args: " + Clipperz.Base.serializeJSON(args)); | 366 | //MochiKit.Logging.logDebug("--- Connection.message - args: " + Clipperz.Base.serializeJSON(args)); |
363 | 367 | ||
364 | // deferredResult = new MochiKit.Async.Deferred(); //### ????????????? | 368 | // deferredResult = new MochiKit.Async.Deferred(); //### ????????????? |
365 | 369 | ||
366 | return this.sendMessage(args); | 370 | return this.sendMessage(args); |
367 | }, | 371 | }, |
368 | 372 | ||
369 | //------------------------------------------------------------------------- | 373 | //------------------------------------------------------------------------- |
370 | 374 | ||
371 | 'sendMessage': function(someArguments) { | 375 | 'sendMessage': function(someArguments) { |
372 | vardeferredResult; | 376 | vardeferredResult; |
373 | 377 | ||
374 | //MochiKit.Logging.logDebug(">>> Connection.sendMessage: " + this); | 378 | //MochiKit.Logging.logDebug(">>> Connection.sendMessage: " + this); |
375 | deferredResult = new MochiKit.Async.Deferred(); | 379 | deferredResult = new MochiKit.Async.Deferred(); |
376 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 1: " + res); return res;}); | 380 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 1: " + res); return res;}); |
377 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'message'), someArguments); | 381 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'message'), someArguments); |
378 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 2: " + res); return res;}); | 382 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 2: " + res); return res;}); |
379 | 383 | ||
380 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | 384 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { |
381 | if (typeof(res['lock']) != 'undefined') { | 385 | if (typeof(res['lock']) != 'undefined') { |
382 | this.user().setLock(res['lock']); | 386 | this.user().setLock(res['lock']); |
383 | } | 387 | } |
384 | return res; | 388 | return res; |
385 | }, this)); | 389 | }, this)); |
386 | 390 | ||
387 | deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments); | 391 | deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments); |
388 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + res); return res;}); | 392 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + res); return res;}); |
389 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); | 393 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); |
390 | deferredResult.callback(); | 394 | deferredResult.callback(); |
391 | //MochiKit.Logging.logDebug("<<< Connection.sendMessage"); | 395 | //MochiKit.Logging.logDebug("<<< Connection.sendMessage"); |
392 | 396 | ||
393 | return deferredResult | 397 | return deferredResult |
394 | }, | 398 | }, |
395 | 399 | ||
396 | //------------------------------------------------------------------------- | 400 | //------------------------------------------------------------------------- |
397 | 401 | ||
398 | 'messageExceptionHandler': function(anOriginalMessageArguments, anError) { | 402 | 'messageExceptionHandler': function(anOriginalMessageArguments, anError) { |
399 | var result; | 403 | var result; |
400 | 404 | ||
401 | //MochiKit.Logging.logDebug(">>> Connection.messageExceptionHandler - this: " + this + ", anError: " + anError); | 405 | //MochiKit.Logging.logDebug(">>> Connection.messageExceptionHandler - this: " + this + ", anError: " + anError); |
402 | if (anError instanceof MochiKit.Async.CancelledError) { | 406 | if (anError instanceof MochiKit.Async.CancelledError) { |
403 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 1"); | 407 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 1"); |
404 | result = anError; | 408 | result = anError; |
405 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 2"); | 409 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 2"); |
406 | } else { | 410 | } else { |
407 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 3 - anError.name: " + anError.name + ", message: " + anError.message); | 411 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 3 - anError.name: " + anError.name + ", message: " + anError.message); |
408 | if ((anError.message == 'Trying to communicate without an active connection')|| | 412 | if ((anError.message == 'Trying to communicate without an active connection')|| |
409 | (anError.message == 'No tollManager available for current session') | 413 | (anError.message == 'No tollManager available for current session') |
410 | ) { | 414 | ) { |
411 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 4"); | 415 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 4"); |
412 | result = this.reestablishConnection(anOriginalMessageArguments); | 416 | result = this.reestablishConnection(anOriginalMessageArguments); |
413 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5"); | 417 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5"); |
414 | } else if (anError.message == 'Session with stale data') { | 418 | } else if (anError.message == 'Session with stale data') { |
415 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.1"); | 419 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.1"); |
416 | Clipperz.NotificationCenter.notify(this, 'EXCEPTION'); | 420 | Clipperz.NotificationCenter.notify(this, 'EXCEPTION'); |
417 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.2"); | 421 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.2"); |
418 | } else { | 422 | } else { |
419 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 6"); | 423 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 6"); |
420 | result = anError; | 424 | result = anError; |
421 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 7"); | 425 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 7"); |
422 | } | 426 | } |
423 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 8"); | 427 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 8"); |
424 | } | 428 | } |
425 | //MochiKit.Logging.logDebug("<<< Connection.messageExceptionHandler"); | 429 | //MochiKit.Logging.logDebug("<<< Connection.messageExceptionHandler"); |
426 | 430 | ||
427 | return result;; | 431 | return result;; |
428 | }, | 432 | }, |
429 | 433 | ||
430 | //========================================================================= | 434 | //========================================================================= |
431 | 435 | ||
432 | 'reestablishConnection': function(anOriginalMessageArguments) { | 436 | 'reestablishConnection': function(anOriginalMessageArguments) { |
433 | var deferredResult; | 437 | var deferredResult; |
434 | 438 | ||
435 | //MochiKit.Logging.logDebug("+++ Connection.reestablishConnection: " + Clipperz.Base.serializeJSON(anOriginalMessageArguments)); | 439 | //MochiKit.Logging.logDebug("+++ Connection.reestablishConnection: " + Clipperz.Base.serializeJSON(anOriginalMessageArguments)); |
436 | 440 | ||
437 | //MochiKit.Logging.logDebug(">>> Connection.reestablishConnection: " + this); | 441 | //MochiKit.Logging.logDebug(">>> Connection.reestablishConnection: " + this); |
438 | deferredResult = new MochiKit.Async.Deferred(); | 442 | deferredResult = new MochiKit.Async.Deferred(); |
439 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 1: " + res); return res;}); | 443 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 1: " + res); return res;}); |
440 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection')); | 444 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection')); |
441 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 2: " + res); return res;}); | 445 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 2: " + res); return res;}); |
442 | deferredResult.addCallback(MochiKit.Base.method(this, 'login'), true); | 446 | deferredResult.addCallback(MochiKit.Base.method(this, 'login'), true); |
443 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 3: " + res); return res;}); | 447 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 3: " + res); return res;}); |
444 | deferredResult.addCallback(MochiKit.Base.bind(function(aMessage) { | 448 | deferredResult.addCallback(MochiKit.Base.bind(function(aMessage) { |
445 | aMessage['srpSharedSecret'] = this.srpConnection().K(); | 449 | aMessage['srpSharedSecret'] = this.srpConnection().K(); |
446 | return aMessage; | 450 | return aMessage; |
447 | }, this), anOriginalMessageArguments); | 451 | }, this), anOriginalMessageArguments); |
448 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 4: " + Clipperz.Base.serializeJSON(res)); return res;}); | 452 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 4: " + Clipperz.Base.serializeJSON(res)); return res;}); |
449 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage')); | 453 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage')); |
450 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 5: " + res); return res;}); | 454 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 5: " + res); return res;}); |
451 | deferredResult.addErrback(Clipperz.NotificationCenter.deferredNotification, this, 'EXCEPTION', null); | 455 | deferredResult.addErrback(Clipperz.NotificationCenter.deferredNotification, this, 'EXCEPTION', null); |
452 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 6: " + res); return res;}); | 456 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 6: " + res); return res;}); |
453 | deferredResult.callback(); | 457 | deferredResult.callback(); |
454 | //MochiKit.Logging.logDebug("<<< Connection.reestablishConnection"); | 458 | //MochiKit.Logging.logDebug("<<< Connection.reestablishConnection"); |
455 | 459 | ||
456 | return deferredResult; | 460 | return deferredResult; |
457 | }, | 461 | }, |
458 | 462 | ||
459 | //========================================================================= | 463 | //========================================================================= |
460 | 464 | ||
461 | 'sharedSecret': function() { | 465 | 'sharedSecret': function() { |
462 | return this.srpConnection().K(); | 466 | return this.srpConnection().K(); |
463 | }, | 467 | }, |
464 | 468 | ||
465 | //========================================================================= | 469 | //========================================================================= |
466 | 470 | ||
467 | 'serverSideUserCredentials': function() { | 471 | 'serverSideUserCredentials': function() { |
468 | varresult; | 472 | varresult; |
469 | varnewSrpConnection; | 473 | varnewSrpConnection; |
470 | 474 | ||
471 | //MochiKit.Logging.logDebug(">>> Connection.serverSideUserCredentials"); | 475 | //MochiKit.Logging.logDebug(">>> Connection.serverSideUserCredentials"); |
472 | newSrpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() }); | 476 | newSrpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() }); |
473 | result = newSrpConnection.serverSideCredentials(); | 477 | result = newSrpConnection.serverSideCredentials(); |
474 | result['version'] = this.clipperz_pm_crypto_version(); | 478 | result['version'] = this.clipperz_pm_crypto_version(); |
475 | 479 | ||
476 | //MochiKit.Logging.logDebug("<<< Connection.serverSideUserCredentials - result: " + Clipperz.Base.serializeJSON(result)); | 480 | //MochiKit.Logging.logDebug("<<< Connection.serverSideUserCredentials - result: " + Clipperz.Base.serializeJSON(result)); |
477 | return result; | 481 | return result; |
478 | }, | 482 | }, |
479 | 483 | ||
480 | //========================================================================= | 484 | //========================================================================= |
481 | 485 | ||
482 | 'C': function() { | 486 | 'C': function() { |
483 | if (this._C == null) { | 487 | if (this._C == null) { |
484 | this._C = this.hash()(new Clipperz.ByteArray(this.user().username())).toHexString().substring(2); | 488 | this._C = this.hash()(new Clipperz.ByteArray(this.user().username())).toHexString().substring(2); |
485 | } | 489 | } |
486 | 490 | ||
487 | return this._C; | 491 | return this._C; |
488 | }, | 492 | }, |
489 | 493 | ||
490 | //----------------------------------------------------------------------------- | 494 | //----------------------------------------------------------------------------- |
491 | 495 | ||
492 | 'P': function() { | 496 | 'P': function() { |
493 | if (this._P == null) { | 497 | if (this._P == null) { |
494 | this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2); | 498 | this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2); |
495 | } | 499 | } |
496 | 500 | ||
497 | return this._P; | 501 | return this._P; |
498 | }, | 502 | }, |
499 | 503 | ||
500 | //----------------------------------------------------------------------------- | 504 | //----------------------------------------------------------------------------- |
501 | 505 | ||
502 | 'hash': function() { | 506 | 'hash': function() { |
503 | return Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].hash; | 507 | return Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].hash; |
504 | }, | 508 | }, |
505 | 509 | ||
506 | //----------------------------------------------------------------------------- | 510 | //----------------------------------------------------------------------------- |
507 | 511 | ||
508 | 'srpConnection': function() { | 512 | 'srpConnection': function() { |
509 | if (this._srpConnection == null) { | 513 | if (this._srpConnection == null) { |
510 | this._srpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() }); | 514 | this._srpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() }); |
511 | } | 515 | } |
512 | 516 | ||
513 | return this._srpConnection; | 517 | return this._srpConnection; |
514 | }, | 518 | }, |
515 | 519 | ||
516 | 'resetSrpConnection': function() { | 520 | 'resetSrpConnection': function() { |
517 | this._C = null; | 521 | this._C = null; |
518 | this._P = null; | 522 | this._P = null; |
519 | this._srpConnection = null; | 523 | this._srpConnection = null; |
520 | }, | 524 | }, |
521 | 525 | ||
522 | //----------------------------------------------------------------------------- | 526 | //----------------------------------------------------------------------------- |
523 | __syntaxFix__: "syntax fix" | 527 | __syntaxFix__: "syntax fix" |
524 | 528 | ||
525 | }); | 529 | }); |
526 | 530 | ||
527 | 531 | ||
528 | 532 | ||
529 | //----------------------------------------------------------------------------- | 533 | //----------------------------------------------------------------------------- |
530 | // | 534 | // |
531 | // S R P [ 1 . 1 ] C O N N E C T I O N class | 535 | // S R P [ 1 . 1 ] C O N N E C T I O N class |
532 | // | 536 | // |
533 | //----------------------------------------------------------------------------- | 537 | //----------------------------------------------------------------------------- |
534 | 538 | ||
535 | Clipperz.PM.Connection.SRP['1.1'] = function (args) { | 539 | Clipperz.PM.Connection.SRP['1.1'] = function (args) { |
536 | args = args || {}; | 540 | args = args || {}; |
537 | Clipperz.PM.Connection.SRP['1.0'].call(this, args); | 541 | Clipperz.PM.Connection.SRP['1.0'].call(this, args); |
538 | 542 | ||
539 | return this; | 543 | return this; |
540 | } | 544 | } |
541 | 545 | ||
542 | Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection.SRP['1.0'](), { | 546 | Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection.SRP['1.0'](), { |
543 | 547 | ||
544 | 'version': function() { | 548 | 'version': function() { |
545 | return '1.1'; | 549 | return '1.1'; |
546 | }, | 550 | }, |
547 | 551 | ||
548 | //----------------------------------------------------------------------------- | 552 | //----------------------------------------------------------------------------- |
549 | 553 | ||
550 | 'C': function() { | 554 | 'C': function() { |
551 | if (this._C == null) { | 555 | if (this._C == null) { |
552 | this._C = this.hash()(new Clipperz.ByteArray(this.user().username() + this.user().passphrase())).toHexString().substring(2); | 556 | this._C = this.hash()(new Clipperz.ByteArray(this.user().username() + this.user().passphrase())).toHexString().substring(2); |
553 | } | 557 | } |
554 | 558 | ||
555 | return this._C; | 559 | return this._C; |
556 | }, | 560 | }, |
557 | 561 | ||
558 | //----------------------------------------------------------------------------- | 562 | //----------------------------------------------------------------------------- |
559 | 563 | ||
560 | 'P': function() { | 564 | 'P': function() { |
561 | if (this._P == null) { | 565 | if (this._P == null) { |
562 | this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2); | 566 | this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2); |
563 | } | 567 | } |
564 | 568 | ||
565 | return this._P; | 569 | return this._P; |
566 | }, | 570 | }, |
567 | 571 | ||
568 | //----------------------------------------------------------------------------- | 572 | //----------------------------------------------------------------------------- |
569 | 573 | ||
570 | 'hash': function() { | 574 | 'hash': function() { |
571 | return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash; | 575 | return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash; |
572 | }, | 576 | }, |
573 | 577 | ||
574 | //----------------------------------------------------------------------------- | 578 | //----------------------------------------------------------------------------- |
575 | __syntaxFix__: "syntax fix" | 579 | __syntaxFix__: "syntax fix" |
576 | 580 | ||
577 | }); | 581 | }); |
578 | 582 | ||
579 | Clipperz.PM.Connection.exception = { | 583 | Clipperz.PM.Connection.exception = { |
580 | WrongChecksum: new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.InvalidValue") | 584 | WrongChecksum: new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.InvalidValue"), |
585 | StaleData: new MochiKit.Base.NamedError("Stale data") | ||
581 | }; | 586 | }; |
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Record.js b/frontend/beta/js/Clipperz/PM/DataModel/Record.js index ffb45de..ecb6c37 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Record.js | |||
@@ -450,312 +450,314 @@ console.log("Record.processData - currentVersionParameters", currentVersionParam | |||
450 | return this._removedDirectLogins; | 450 | return this._removedDirectLogins; |
451 | }, | 451 | }, |
452 | 452 | ||
453 | 'resetRemovedDirectLogins': function() { | 453 | 'resetRemovedDirectLogins': function() { |
454 | this._removedDirectLogins = []; | 454 | this._removedDirectLogins = []; |
455 | }, | 455 | }, |
456 | 456 | ||
457 | //------------------------------------------------------------------------- | 457 | //------------------------------------------------------------------------- |
458 | 458 | ||
459 | 'serverData': function() { | 459 | 'serverData': function() { |
460 | return this._serverData; | 460 | return this._serverData; |
461 | }, | 461 | }, |
462 | 462 | ||
463 | 'setServerData': function(aValue) { | 463 | 'setServerData': function(aValue) { |
464 | this._serverData = aValue; | 464 | this._serverData = aValue; |
465 | this.setShouldLoadData(false); | 465 | this.setShouldLoadData(false); |
466 | return aValue; | 466 | return aValue; |
467 | }, | 467 | }, |
468 | 468 | ||
469 | //------------------------------------------------------------------------- | 469 | //------------------------------------------------------------------------- |
470 | 470 | ||
471 | 'decryptedData': function() { | 471 | 'decryptedData': function() { |
472 | return this._decryptedData; | 472 | return this._decryptedData; |
473 | }, | 473 | }, |
474 | 474 | ||
475 | 'setDecryptedData': function(aValue) { | 475 | 'setDecryptedData': function(aValue) { |
476 | this._decryptedData = aValue; | 476 | this._decryptedData = aValue; |
477 | this.setShouldDecryptData(false); | 477 | this.setShouldDecryptData(false); |
478 | return aValue; | 478 | return aValue; |
479 | }, | 479 | }, |
480 | 480 | ||
481 | //------------------------------------------------------------------------- | 481 | //------------------------------------------------------------------------- |
482 | 482 | ||
483 | 'cachedData': function() { | 483 | 'cachedData': function() { |
484 | return this._cachedData; | 484 | return this._cachedData; |
485 | }, | 485 | }, |
486 | 486 | ||
487 | 'setCachedData': function(aValue) { | 487 | 'setCachedData': function(aValue) { |
488 | //MochiKit.Logging.logDebug(">>> Record.setCachedData"); | 488 | //MochiKit.Logging.logDebug(">>> Record.setCachedData"); |
489 | //MochiKit.Logging.logDebug("--- Record.setCachedData - aValue: " + Clipperz.Base.serializeJSON(aValue)); | 489 | //MochiKit.Logging.logDebug("--- Record.setCachedData - aValue: " + Clipperz.Base.serializeJSON(aValue)); |
490 | this._cachedData = aValue; | 490 | this._cachedData = aValue; |
491 | this.setShouldProcessData(false); | 491 | this.setShouldProcessData(false); |
492 | //MochiKit.Logging.logDebug("<<< Record.setCachedData"); | 492 | //MochiKit.Logging.logDebug("<<< Record.setCachedData"); |
493 | 493 | ||
494 | return aValue; | 494 | return aValue; |
495 | }, | 495 | }, |
496 | 496 | ||
497 | //------------------------------------------------------------------------- | 497 | //------------------------------------------------------------------------- |
498 | 498 | ||
499 | 'hasPendingChanges': function() { | 499 | 'hasPendingChanges': function() { |
500 | var result; | 500 | var result; |
501 | 501 | ||
502 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); | 502 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); |
503 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + this.cachedData()); | 503 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + this.cachedData()); |
504 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); | 504 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); |
505 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + this.currentDataSnapshot()); | 505 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + this.currentDataSnapshot()); |
506 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + Clipperz.Base.serializeJSON(this.currentDataSnapshot())); | 506 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + Clipperz.Base.serializeJSON(this.currentDataSnapshot())); |
507 | //console.log(">>> Record.hasPendingChanges - cachedData: %o", this.cachedData()); | 507 | //console.log(">>> Record.hasPendingChanges - cachedData: %o", this.cachedData()); |
508 | //console.log(">>> Record.hasPendingChanges - currentSnapshot: %o", this.currentDataSnapshot()); | 508 | //console.log(">>> Record.hasPendingChanges - currentSnapshot: %o", this.currentDataSnapshot()); |
509 | result = (MochiKit.Base.compare(this.cachedData(), this.currentDataSnapshot()) != 0); | 509 | result = (MochiKit.Base.compare(this.cachedData(), this.currentDataSnapshot()) != 0); |
510 | //MochiKit.Logging.logDebug("<<< Record.hasPendingChanges - " + result); | 510 | //MochiKit.Logging.logDebug("<<< Record.hasPendingChanges - " + result); |
511 | 511 | ||
512 | if ((result == false) && this.isBrandNew() && (this.label() != Clipperz.PM.Strings['newRecordTitleLabel'])) { | 512 | if ((result == false) && this.isBrandNew() && (this.label() != Clipperz.PM.Strings['newRecordTitleLabel'])) { |
513 | result = true; | 513 | result = true; |
514 | } | 514 | } |
515 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); | 515 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); |
516 | 516 | ||
517 | return result; | 517 | return result; |
518 | }, | 518 | }, |
519 | 519 | ||
520 | //------------------------------------------------------------------------- | 520 | //------------------------------------------------------------------------- |
521 | 521 | ||
522 | 'currentDataSnapshot': function() { | 522 | 'currentDataSnapshot': function() { |
523 | varresult; | 523 | varresult; |
524 | 524 | ||
525 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); | 525 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); |
526 | result = { | 526 | result = { |
527 | 'label': this.label(), | 527 | 'label': this.label(), |
528 | 'data': this.serializedData(), | 528 | 'data': this.serializedData(), |
529 | 'currentVersion': this.currentVersion().currentDataSnapshot() | 529 | 'currentVersion': this.currentVersion().currentDataSnapshot() |
530 | }; | 530 | }; |
531 | 531 | ||
532 | // result['data']['data'] = this.notes(); | 532 | // result['data']['data'] = this.notes(); |
533 | result = Clipperz.Base.serializeJSON(result); | 533 | result = Clipperz.Base.serializeJSON(result); |
534 | 534 | ||
535 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); | 535 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); |
536 | //MochiKit.Logging.logDebug("<<< Record.currentDataSnapshot"); | 536 | //MochiKit.Logging.logDebug("<<< Record.currentDataSnapshot"); |
537 | 537 | ||
538 | return result; | 538 | return result; |
539 | }, | 539 | }, |
540 | 540 | ||
541 | //......................................................................... | 541 | //......................................................................... |
542 | 542 | ||
543 | 'takeSnapshotOfCurrentData': function() { | 543 | 'takeSnapshotOfCurrentData': function() { |
544 | this.setCachedData(this.currentDataSnapshot()); | 544 | this.setCachedData(this.currentDataSnapshot()); |
545 | }, | 545 | }, |
546 | 546 | ||
547 | //------------------------------------------------------------------------- | 547 | //------------------------------------------------------------------------- |
548 | 548 | ||
549 | 'headerData': function() { | 549 | 'headerData': function() { |
550 | var result; | 550 | var result; |
551 | 551 | ||
552 | result = { | 552 | result = { |
553 | 'label': this.label(), | 553 | 'label': this.label(), |
554 | 'key': this.key() | 554 | 'key': this.key() |
555 | }; | 555 | }; |
556 | 556 | ||
557 | if (this.headerNotes() != null) { | 557 | if (this.headerNotes() != null) { |
558 | result['headerNotes'] = this.headerNotes(); | 558 | result['headerNotes'] = this.headerNotes(); |
559 | } | 559 | } |
560 | 560 | ||
561 | return result; | 561 | return result; |
562 | }, | 562 | }, |
563 | 563 | ||
564 | //------------------------------------------------------------------------- | 564 | //------------------------------------------------------------------------- |
565 | 565 | ||
566 | 'serializedData': function() { | 566 | 'serializedData': function() { |
567 | var result; | 567 | var result; |
568 | var directLoginReference; | 568 | var directLoginReference; |
569 | 569 | ||
570 | result = {}; | 570 | result = {}; |
571 | result['currentVersionKey'] = this.currentVersion().key(); | 571 | result['currentVersionKey'] = this.currentVersion().key(); |
572 | 572 | ||
573 | result['directLogins'] = {}; | 573 | result['directLogins'] = {}; |
574 | for (directLoginReference in this.directLogins()) { | 574 | for (directLoginReference in this.directLogins()) { |
575 | result['directLogins'][directLoginReference] = this.directLogins()[directLoginReference].serializedData(); | 575 | result['directLogins'][directLoginReference] = this.directLogins()[directLoginReference].serializedData(); |
576 | } | 576 | } |
577 | result['notes'] = this.notes(); | 577 | result['notes'] = this.notes(); |
578 | 578 | ||
579 | return result; | 579 | return result; |
580 | }, | 580 | }, |
581 | 581 | ||
582 | //------------------------------------------------------------------------- | 582 | //------------------------------------------------------------------------- |
583 | 583 | ||
584 | 'encryptedData': function() { | 584 | 'encryptedData': function() { |
585 | var deferredResult; | 585 | var deferredResult; |
586 | varresult; | 586 | varresult; |
587 | 587 | ||
588 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.encryptedData"); | 588 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.encryptedData"); |
589 | result = {} | 589 | result = {} |
590 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 1"); | 590 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 1"); |
591 | deferredResult = new MochiKit.Async.Deferred(); | 591 | deferredResult = new MochiKit.Async.Deferred(); |
592 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 2"); | 592 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 2"); |
593 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 1: " + res); return res;}); | 593 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 1: " + res); return res;}); |
594 | deferredResult.addCallback(function(aResult, aRecord) { | 594 | deferredResult.addCallback(function(aResult, aRecord) { |
595 | aResult['reference'] = aRecord.reference(); | 595 | aResult['reference'] = aRecord.reference(); |
596 | return aResult; | 596 | return aResult; |
597 | }, result, this); | 597 | }, result, this); |
598 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 3"); | 598 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 3"); |
599 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 2: " + res); return res;}); | 599 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 2: " + res); return res;}); |
600 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.key(), this.serializedData()); | 600 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.key(), this.serializedData()); |
601 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 4"); | 601 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 4"); |
602 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 3: " + res); return res;}); | 602 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 3: " + res); return res;}); |
603 | deferredResult.addCallback(function(aResult, res) { | 603 | deferredResult.addCallback(function(aResult, res) { |
604 | aResult['data'] = res; | 604 | aResult['data'] = res; |
605 | return aResult; | 605 | return aResult; |
606 | }, result); | 606 | }, result); |
607 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 5"); | 607 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 5"); |
608 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 4: " + res); return res;}); | 608 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 4: " + res); return res;}); |
609 | deferredResult.addCallback(function(aResult) { | 609 | deferredResult.addCallback(function(aResult) { |
610 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; | 610 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; |
611 | return aResult; | 611 | return aResult; |
612 | }, result); | 612 | }, result); |
613 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 6"); | 613 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 6"); |
614 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 5: " + res); return res;}); | 614 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 5: " + res); return res;}); |
615 | deferredResult.callback(); | 615 | deferredResult.callback(); |
616 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.encryptedData"); | 616 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.encryptedData"); |
617 | 617 | ||
618 | return deferredResult; | 618 | return deferredResult; |
619 | }, | 619 | }, |
620 | 620 | ||
621 | //------------------------------------------------------------------------- | 621 | //------------------------------------------------------------------------- |
622 | 622 | ||
623 | 'syncDirectLoginReferenceValues': function() { | 623 | 'syncDirectLoginReferenceValues': function() { |
624 | //MochiKit.Logging.logDebug(">>> Record.syncDirectLoginReferenceValues"); | 624 | //MochiKit.Logging.logDebug(">>> Record.syncDirectLoginReferenceValues"); |
625 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), function(aDirectLogin) { | 625 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), function(aDirectLogin) { |
626 | aDirectLogin.record().user().synchronizeDirectLogin(aDirectLogin); | 626 | aDirectLogin.record().user().synchronizeDirectLogin(aDirectLogin); |
627 | }); | 627 | }); |
628 | 628 | ||
629 | MochiKit.Iter.forEach(this.removedDirectLogins(), function(aDirectLogin) { | 629 | MochiKit.Iter.forEach(this.removedDirectLogins(), function(aDirectLogin) { |
630 | aDirectLogin.record().user().removeDirectLogin(aDirectLogin); | 630 | aDirectLogin.record().user().removeDirectLogin(aDirectLogin); |
631 | }); | 631 | }); |
632 | 632 | ||
633 | this.resetRemovedDirectLogins(); | 633 | this.resetRemovedDirectLogins(); |
634 | //MochiKit.Logging.logDebug("<<< Record.syncDirectLoginReferenceValues"); | 634 | //MochiKit.Logging.logDebug("<<< Record.syncDirectLoginReferenceValues"); |
635 | }, | 635 | }, |
636 | 636 | ||
637 | //------------------------------------------------------------------------- | 637 | //------------------------------------------------------------------------- |
638 | 638 | ||
639 | 'saveChanges': function() { | 639 | 'saveChanges': function() { |
640 | var result; | 640 | var result; |
641 | 641 | ||
642 | if (this.isBrandNew() == false) { | 642 | // if (this.isBrandNew() == false) { |
643 | result = this.user().saveRecords([this], 'updateData'); | 643 | // result = this.user().saveRecords([this], 'updateData'); |
644 | } else { | 644 | // } else { |
645 | result = this.user().saveRecords([this], 'addNewRecords'); | 645 | // result = this.user().saveRecords([this], 'addNewRecords'); |
646 | } | 646 | // } |
647 | |||
648 | result = this.user().saveRecords([this]); | ||
647 | 649 | ||
648 | return result; | 650 | return result; |
649 | }, | 651 | }, |
650 | 652 | ||
651 | /* | 653 | /* |
652 | 'saveChanges': function() { | 654 | 'saveChanges': function() { |
653 | var deferredResult; | 655 | var deferredResult; |
654 | varresult; | 656 | varresult; |
655 | 657 | ||
656 | Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'records', true); | 658 | Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'records', true); |
657 | //MochiKit.Logging.logDebug(">>> Record.saveChanges"); | 659 | //MochiKit.Logging.logDebug(">>> Record.saveChanges"); |
658 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.saveChanges"); | 660 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.saveChanges"); |
659 | if (this.headerNotes() != null) { | 661 | if (this.headerNotes() != null) { |
660 | this.setNotes(this.headerNotes()); | 662 | this.setNotes(this.headerNotes()); |
661 | } | 663 | } |
662 | this.syncDirectLoginReferenceValues(); | 664 | this.syncDirectLoginReferenceValues(); |
663 | this.currentVersion().createNewVersion(); | 665 | this.currentVersion().createNewVersion(); |
664 | 666 | ||
665 | result = {'records': [{}]}; | 667 | result = {'records': [{}]}; |
666 | 668 | ||
667 | deferredResult = new MochiKit.Async.Deferred(); | 669 | deferredResult = new MochiKit.Async.Deferred(); |
668 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); | 670 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); |
669 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateKey')); | 671 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateKey')); |
670 | 672 | ||
671 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); | 673 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); |
672 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); | 674 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); |
673 | deferredResult.addCallback(function(aResult, res) { | 675 | deferredResult.addCallback(function(aResult, res) { |
674 | aResult['user'] = res; | 676 | aResult['user'] = res; |
675 | return aResult; | 677 | return aResult; |
676 | }, result); | 678 | }, result); |
677 | 679 | ||
678 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); | 680 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); |
679 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 681 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
680 | deferredResult.addCallback(function(aResult, res) { | 682 | deferredResult.addCallback(function(aResult, res) { |
681 | //# aResult['record'] = res; | 683 | //# aResult['record'] = res; |
682 | aResult['records'][0]['record'] = res; | 684 | aResult['records'][0]['record'] = res; |
683 | return aResult; | 685 | return aResult; |
684 | }, result); | 686 | }, result); |
685 | 687 | ||
686 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordVersions'); | 688 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordVersions'); |
687 | deferredResult.addCallback(MochiKit.Base.method(this.currentVersion(), 'encryptedData')); | 689 | deferredResult.addCallback(MochiKit.Base.method(this.currentVersion(), 'encryptedData')); |
688 | deferredResult.addCallback(function(aResult, res) { | 690 | deferredResult.addCallback(function(aResult, res) { |
689 | // aResult['currentRecordVersion'] = res; | 691 | // aResult['currentRecordVersion'] = res; |
690 | aResult['records'][0]['currentRecordVersion'] = res; | 692 | aResult['records'][0]['currentRecordVersion'] = res; |
691 | return aResult; | 693 | return aResult; |
692 | }, result); | 694 | }, result); |
693 | 695 | ||
694 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData'); | 696 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData'); |
695 | if (this.isBrandNew() == false) { | 697 | if (this.isBrandNew() == false) { |
696 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'updateData'); | 698 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'updateData'); |
697 | } else { | 699 | } else { |
698 | //# deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecord'); | 700 | //# deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecord'); |
699 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecords'); | 701 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecords'); |
700 | } | 702 | } |
701 | 703 | ||
702 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); | 704 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); |
703 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_updatingInterface'); | 705 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_updatingInterface'); |
704 | deferredResult.addCallback(MochiKit.Base.method(this, 'setIsBrandNew'), false); | 706 | deferredResult.addCallback(MochiKit.Base.method(this, 'setIsBrandNew'), false); |
705 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated'); | 707 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated'); |
706 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated'); | 708 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated'); |
707 | deferredResult.callback(); | 709 | deferredResult.callback(); |
708 | 710 | ||
709 | return deferredResult; | 711 | return deferredResult; |
710 | }, | 712 | }, |
711 | */ | 713 | */ |
712 | //------------------------------------------------------------------------- | 714 | //------------------------------------------------------------------------- |
713 | 715 | ||
714 | 'cancelChanges': function() { | 716 | 'cancelChanges': function() { |
715 | //MochiKit.Logging.logDebug(">>> Record.cancelChanges"); | 717 | //MochiKit.Logging.logDebug(">>> Record.cancelChanges"); |
716 | //MochiKit.Logging.logDebug("--- Record.cancelChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); | 718 | //MochiKit.Logging.logDebug("--- Record.cancelChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); |
717 | if (this.isBrandNew()) { | 719 | if (this.isBrandNew()) { |
718 | this.user().removeRecord(this); | 720 | this.user().removeRecord(this); |
719 | } else { | 721 | } else { |
720 | this.restoreValuesFromSnapshot(this.cachedData()); | 722 | this.restoreValuesFromSnapshot(this.cachedData()); |
721 | } | 723 | } |
722 | //MochiKit.Logging.logDebug("<<< Record.cancelChanges"); | 724 | //MochiKit.Logging.logDebug("<<< Record.cancelChanges"); |
723 | }, | 725 | }, |
724 | 726 | ||
725 | //------------------------------------------------------------------------- | 727 | //------------------------------------------------------------------------- |
726 | 728 | ||
727 | 'restoreValuesFromSnapshot': function(someSnapshotData) { | 729 | 'restoreValuesFromSnapshot': function(someSnapshotData) { |
728 | varsnapshotData; | 730 | varsnapshotData; |
729 | 731 | ||
730 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); | 732 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); |
731 | snapshotData = Clipperz.Base.evalJSON(someSnapshotData); | 733 | snapshotData = Clipperz.Base.evalJSON(someSnapshotData); |
732 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData (1): " + Clipperz.Base.serializeJSON(someSnapshotData)); | 734 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData (1): " + Clipperz.Base.serializeJSON(someSnapshotData)); |
733 | this.setLabel(snapshotData['label']); | 735 | this.setLabel(snapshotData['label']); |
734 | this.resetDirectLogins(); | 736 | this.resetDirectLogins(); |
735 | this.setShouldProcessData(true); | 737 | this.setShouldProcessData(true); |
736 | this.processData(snapshotData); | 738 | this.processData(snapshotData); |
737 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - snapshotData: (2)" + Clipperz.Base.serializeJSON(snapshotData)); | 739 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - snapshotData: (2)" + Clipperz.Base.serializeJSON(snapshotData)); |
738 | 740 | ||
739 | this.resetRemovedDirectLogins(); | 741 | this.resetRemovedDirectLogins(); |
740 | 742 | ||
741 | { | 743 | { |
742 | var currentSnapshot; | 744 | var currentSnapshot; |
743 | varcomparisonResult; | 745 | varcomparisonResult; |
744 | 746 | ||
745 | currentSnapshot = this.currentDataSnapshot(); | 747 | currentSnapshot = this.currentDataSnapshot(); |
746 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - 1"); | 748 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - 1"); |
747 | //console.log("snapshot data: %o", someSnapshotData.currentVersion); | 749 | //console.log("snapshot data: %o", someSnapshotData.currentVersion); |
748 | //console.log("current data: %o", currentSnapshot.currentVersion); | 750 | //console.log("current data: %o", currentSnapshot.currentVersion); |
749 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData: " + Clipperz.Base.serializeJSON(someSnapshotData.currentVersion)); | 751 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData: " + Clipperz.Base.serializeJSON(someSnapshotData.currentVersion)); |
750 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - currentSnapshot: " + Clipperz.Base.serializeJSON(currentSnapshot.currentVersion)); | 752 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - currentSnapshot: " + Clipperz.Base.serializeJSON(currentSnapshot.currentVersion)); |
751 | comparisonResult = MochiKit.Base.compare(someSnapshotData.currentVersion, currentSnapshot.currentVersion); | 753 | comparisonResult = MochiKit.Base.compare(someSnapshotData.currentVersion, currentSnapshot.currentVersion); |
752 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - " + comparisonResult); | 754 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - " + comparisonResult); |
753 | } | 755 | } |
754 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); | 756 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); |
755 | }, | 757 | }, |
756 | 758 | ||
757 | //------------------------------------------------------------------------- | 759 | //------------------------------------------------------------------------- |
758 | __syntaxFix__: "syntax fix" | 760 | __syntaxFix__: "syntax fix" |
759 | }); | 761 | }); |
760 | 762 | ||
761 | 763 | ||
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/User.js b/frontend/beta/js/Clipperz/PM/DataModel/User.js index dbbe9a0..b065557 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/User.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/User.js | |||
@@ -96,548 +96,551 @@ Clipperz.PM.DataModel.User.prototype = MochiKit.Base.update(null, { | |||
96 | 'maxNumberOfRecords': function() { | 96 | 'maxNumberOfRecords': function() { |
97 | return this._maxNumberOfRecords; | 97 | return this._maxNumberOfRecords; |
98 | }, | 98 | }, |
99 | 99 | ||
100 | 'setMaxNumberOfRecords': function(aValue) { | 100 | 'setMaxNumberOfRecords': function(aValue) { |
101 | this._maxNumberOfRecords = aValue; | 101 | this._maxNumberOfRecords = aValue; |
102 | }, | 102 | }, |
103 | 103 | ||
104 | //------------------------------------------------------------------------- | 104 | //------------------------------------------------------------------------- |
105 | 105 | ||
106 | 'errorHandler': function(anErrorString, anException) { | 106 | 'errorHandler': function(anErrorString, anException) { |
107 | MochiKit.Logging.logError("- User.errorHandler: " + anErrorString + " (" + anException + ")"); | 107 | MochiKit.Logging.logError("- User.errorHandler: " + anErrorString + " (" + anException + ")"); |
108 | }, | 108 | }, |
109 | 109 | ||
110 | //------------------------------------------------------------------------- | 110 | //------------------------------------------------------------------------- |
111 | 111 | ||
112 | 'connectionVersion': function() { | 112 | 'connectionVersion': function() { |
113 | return this._connectionVersion; | 113 | return this._connectionVersion; |
114 | }, | 114 | }, |
115 | 115 | ||
116 | 'setConnectionVersion': function(aValue) { | 116 | 'setConnectionVersion': function(aValue) { |
117 | this._connectionVersion = aValue; | 117 | this._connectionVersion = aValue; |
118 | }, | 118 | }, |
119 | 119 | ||
120 | //------------------------------------------------------------------------- | 120 | //------------------------------------------------------------------------- |
121 | 121 | ||
122 | 'connection': function() { | 122 | 'connection': function() { |
123 | if ((this._connection == null) && (this.connectionVersion() != null) ){ | 123 | if ((this._connection == null) && (this.connectionVersion() != null) ){ |
124 | this._connection = new Clipperz.PM.Crypto.communicationProtocol.versions[this.connectionVersion()]({user:this}); | 124 | this._connection = new Clipperz.PM.Crypto.communicationProtocol.versions[this.connectionVersion()]({user:this}); |
125 | } | 125 | } |
126 | 126 | ||
127 | return this._connection; | 127 | return this._connection; |
128 | }, | 128 | }, |
129 | 129 | ||
130 | 'resetConnection': function(aValue) { | 130 | 'resetConnection': function(aValue) { |
131 | this._connection = null; | 131 | this._connection = null; |
132 | }, | 132 | }, |
133 | 133 | ||
134 | //========================================================================= | 134 | //========================================================================= |
135 | 135 | ||
136 | 'register': function(anInvitationCode) { | 136 | 'register': function(anInvitationCode) { |
137 | vardeferredResult; | 137 | vardeferredResult; |
138 | var prng; | 138 | var prng; |
139 | 139 | ||
140 | //MochiKit.Logging.logError(">>> User.register: " + this); | 140 | //MochiKit.Logging.logError(">>> User.register: " + this); |
141 | prng = Clipperz.Crypto.PRNG.defaultRandomGenerator(); | 141 | prng = Clipperz.Crypto.PRNG.defaultRandomGenerator(); |
142 | 142 | ||
143 | deferredResult = new MochiKit.Async.Deferred() | 143 | deferredResult = new MochiKit.Async.Deferred() |
144 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 1: " + res); return res;}); | 144 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 1: " + res); return res;}); |
145 | deferredResult.addCallback(MochiKit.Base.method(prng, 'deferredEntropyCollection')); | 145 | deferredResult.addCallback(MochiKit.Base.method(prng, 'deferredEntropyCollection')); |
146 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 2: " + res); return res;}); | 146 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 2: " + res); return res;}); |
147 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'updateAllSections'), anInvitationCode); | 147 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'updateAllSections'), anInvitationCode); |
148 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 2.1: " + res); return res;}); | 148 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 2.1: " + res); return res;}); |
149 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'register'), anInvitationCode); | 149 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'register'), anInvitationCode); |
150 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 3: " + res); return res;}); | 150 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 3: " + res); return res;}); |
151 | deferredResult.callback(); | 151 | deferredResult.callback(); |
152 | //MochiKit.Logging.logError("<<< User.register"); | 152 | //MochiKit.Logging.logError("<<< User.register"); |
153 | 153 | ||
154 | return deferredResult; | 154 | return deferredResult; |
155 | }, | 155 | }, |
156 | 156 | ||
157 | //========================================================================= | 157 | //========================================================================= |
158 | 158 | ||
159 | 'connect': function(aValue) { | 159 | 'connect': function(aValue) { |
160 | vardeferredResult; | 160 | vardeferredResult; |
161 | var prng; | 161 | var prng; |
162 | 162 | ||
163 | prng = Clipperz.Crypto.PRNG.defaultRandomGenerator(); | 163 | prng = Clipperz.Crypto.PRNG.defaultRandomGenerator(); |
164 | 164 | ||
165 | //MochiKit.Logging.logDebug(">>> User.connect"); | 165 | //MochiKit.Logging.logDebug(">>> User.connect"); |
166 | deferredResult = new MochiKit.Async.Deferred(); | 166 | deferredResult = new MochiKit.Async.Deferred(); |
167 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.1 - User.connect - 1: "/* + res*/); return res;}); | 167 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.1 - User.connect - 1: "/* + res*/); return res;}); |
168 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 168 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
169 | deferredResult.addCallback(MochiKit.Base.method(prng, 'deferredEntropyCollection')); | 169 | deferredResult.addCallback(MochiKit.Base.method(prng, 'deferredEntropyCollection')); |
170 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.2 - User.connect - 2: "/* + res*/); return res;}); | 170 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.2 - User.connect - 2: "/* + res*/); return res;}); |
171 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 171 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
172 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'login')); | 172 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'login')); |
173 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.3 - User.connect - 3: "/* + res*/); return res;}); | 173 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.3 - User.connect - 3: "/* + res*/); return res;}); |
174 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 174 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
175 | 175 | ||
176 | // TODO:add an addErrback call here to manage a wrong login. Any error after this point is due to some other causes. | 176 | // TODO:add an addErrback call here to manage a wrong login. Any error after this point is due to some other causes. |
177 | // possibly the same exact 'handleConnectionFallback use at the end of this same method. | 177 | // possibly the same exact 'handleConnectionFallback use at the end of this same method. |
178 | 178 | ||
179 | if (this.connectionVersion() != 'current') { | 179 | if (this.connectionVersion() != 'current') { |
180 | varcurrentConnection; | 180 | varcurrentConnection; |
181 | 181 | ||
182 | currentVersionConnection = new Clipperz.PM.Crypto.communicationProtocol.versions['current']({user:this}); | 182 | currentVersionConnection = new Clipperz.PM.Crypto.communicationProtocol.versions['current']({user:this}); |
183 | 183 | ||
184 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.4 - User.connect - 4: "/* + res*/); return res;}); | 184 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.4 - User.connect - 4: "/* + res*/); return res;}); |
185 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 185 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
186 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_upgrading'); | 186 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_upgrading'); |
187 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.5 - User.connect - 5: "/* + res*/); return res;}); | 187 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.5 - User.connect - 5: "/* + res*/); return res;}); |
188 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 188 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
189 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'upgradeUserCredentials', currentVersionConnection.serverSideUserCredentials()); | 189 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'upgradeUserCredentials', currentVersionConnection.serverSideUserCredentials()); |
190 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.6 - User.connect - 6: "/* + res*/); return res;}); | 190 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.6 - User.connect - 6: "/* + res*/); return res;}); |
191 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 191 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
192 | } | 192 | } |
193 | 193 | ||
194 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.7 - User.connect - 7: "/* + res*/); return res;}); | 194 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.7 - User.connect - 7: "/* + res*/); return res;}); |
195 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 195 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
196 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'userConnected', null); | 196 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'userConnected', null); |
197 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.8 - User.connect - 8: "/* + res*/); return res;}); | 197 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.8 - User.connect - 8: "/* + res*/); return res;}); |
198 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 198 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
199 | deferredResult.addErrback(MochiKit.Base.method(this, 'handleConnectionFallback')); | 199 | deferredResult.addErrback(MochiKit.Base.method(this, 'handleConnectionFallback')); |
200 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.9 - User.connect - 9: "/* + res*/); return res;}); | 200 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.9 - User.connect - 9: "/* + res*/); return res;}); |
201 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 201 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
202 | 202 | ||
203 | deferredResult.callback(aValue); | 203 | deferredResult.callback(aValue); |
204 | //MochiKit.Logging.logDebug("<<< User.connect"); | 204 | //MochiKit.Logging.logDebug("<<< User.connect"); |
205 | 205 | ||
206 | return deferredResult; | 206 | return deferredResult; |
207 | }, | 207 | }, |
208 | 208 | ||
209 | //......................................................................... | 209 | //......................................................................... |
210 | 210 | ||
211 | 'handleConnectionFallback': function(aValue) { | 211 | 'handleConnectionFallback': function(aValue) { |
212 | var result; | 212 | var result; |
213 | //MochiKit.Logging.logDebug(">>> User.handleConnectionFallback"); | 213 | //MochiKit.Logging.logDebug(">>> User.handleConnectionFallback"); |
214 | if (aValue instanceof MochiKit.Async.CancelledError) { | 214 | if (aValue instanceof MochiKit.Async.CancelledError) { |
215 | //MochiKit.Logging.logDebug("--- User.handleConnectionFallback - operation cancelled"); | 215 | //MochiKit.Logging.logDebug("--- User.handleConnectionFallback - operation cancelled"); |
216 | result = aValue; | 216 | result = aValue; |
217 | } else { | 217 | } else { |
218 | 218 | ||
219 | //MochiKit.Logging.logDebug("--- User.handleConnectionFallback - an ERROR has occurred - " + aValue); | 219 | //MochiKit.Logging.logDebug("--- User.handleConnectionFallback - an ERROR has occurred - " + aValue); |
220 | this.resetConnection(); | 220 | this.resetConnection(); |
221 | this.setConnectionVersion(Clipperz.PM.Crypto.communicationProtocol.fallbackVersions[this.connectionVersion()]); | 221 | this.setConnectionVersion(Clipperz.PM.Crypto.communicationProtocol.fallbackVersions[this.connectionVersion()]); |
222 | 222 | ||
223 | if (this.connectionVersion() != null) { | 223 | if (this.connectionVersion() != null) { |
224 | result = new MochiKit.Async.Deferred(); | 224 | result = new MochiKit.Async.Deferred(); |
225 | 225 | ||
226 | result.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_tryOlderSchema'); | 226 | result.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_tryOlderSchema'); |
227 | result.addCallback(MochiKit.Base.method(this, 'connect')); | 227 | result.addCallback(MochiKit.Base.method(this, 'connect')); |
228 | result.callback(); | 228 | result.callback(); |
229 | } else { | 229 | } else { |
230 | result = MochiKit.Async.fail(Clipperz.PM.DataModel.User.exception.LoginFailed); | 230 | result = MochiKit.Async.fail(Clipperz.PM.DataModel.User.exception.LoginFailed); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | //MochiKit.Logging.logDebug("<<< User.handleConnectionFallback"); | 233 | //MochiKit.Logging.logDebug("<<< User.handleConnectionFallback"); |
234 | return result; | 234 | return result; |
235 | }, | 235 | }, |
236 | 236 | ||
237 | //========================================================================= | 237 | //========================================================================= |
238 | 238 | ||
239 | 'header': function() { | 239 | 'header': function() { |
240 | if (this._header == null) { | 240 | if (this._header == null) { |
241 | this._header = new Clipperz.PM.DataModel.Header({user:this}); | 241 | this._header = new Clipperz.PM.DataModel.Header({user:this}); |
242 | } | 242 | } |
243 | return this._header; | 243 | return this._header; |
244 | }, | 244 | }, |
245 | 245 | ||
246 | //------------------------------------------------------------------------- | 246 | //------------------------------------------------------------------------- |
247 | 247 | ||
248 | 'statistics': function() { | 248 | 'statistics': function() { |
249 | if (this._statistics == null) { | 249 | if (this._statistics == null) { |
250 | this._statistics = new Clipperz.PM.DataModel.Statistics({user:this}); | 250 | this._statistics = new Clipperz.PM.DataModel.Statistics({user:this}); |
251 | } | 251 | } |
252 | return this._statistics; | 252 | return this._statistics; |
253 | }, | 253 | }, |
254 | 254 | ||
255 | //------------------------------------------------------------------------- | 255 | //------------------------------------------------------------------------- |
256 | 256 | ||
257 | 'records': function() { | 257 | 'records': function() { |
258 | return this._records; | 258 | return this._records; |
259 | }, | 259 | }, |
260 | 260 | ||
261 | //......................................................................... | 261 | //......................................................................... |
262 | 262 | ||
263 | 'addRecord': function(aValue, isBatchUpdate) { | 263 | 'addRecord': function(aValue, isBatchUpdate) { |
264 | this.records()[aValue.reference()] = aValue; | 264 | this.records()[aValue.reference()] = aValue; |
265 | 265 | ||
266 | if (isBatchUpdate != true) { | 266 | if (isBatchUpdate != true) { |
267 | Clipperz.NotificationCenter.notify(aValue, 'recordAdded', null, true); | 267 | Clipperz.NotificationCenter.notify(aValue, 'recordAdded', null, true); |
268 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); | 268 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); |
269 | } | 269 | } |
270 | }, | 270 | }, |
271 | 271 | ||
272 | //----------------------------------------------------------------------------- | 272 | //----------------------------------------------------------------------------- |
273 | 273 | ||
274 | 'addNewRecord': function() { | 274 | 'addNewRecord': function() { |
275 | varrecord; | 275 | varrecord; |
276 | 276 | ||
277 | //MochiKit.Logging.logDebug(">>> User.addNewRecord"); | 277 | //MochiKit.Logging.logDebug(">>> User.addNewRecord"); |
278 | record = new Clipperz.PM.DataModel.Record({user:this}); | 278 | record = new Clipperz.PM.DataModel.Record({user:this}); |
279 | this.addRecord(record); | 279 | this.addRecord(record); |
280 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); | 280 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); |
281 | //MochiKit.Logging.logDebug("<<< User.addNewRecord"); | 281 | //MochiKit.Logging.logDebug("<<< User.addNewRecord"); |
282 | 282 | ||
283 | return record; | 283 | return record; |
284 | }, | 284 | }, |
285 | 285 | ||
286 | //------------------------------------------------------------------------- | 286 | //------------------------------------------------------------------------- |
287 | 287 | ||
288 | 'saveRecords': function(someRecords, aMethodName) { | 288 | 'saveRecords': function(someRecords /*, aMethodName*/) { |
289 | var deferredResult; | 289 | var deferredResult; |
290 | var methodName; | 290 | // var methodName; |
291 | varresult; | 291 | varresult; |
292 | var i,c; | 292 | var i,c; |
293 | 293 | ||
294 | //console.log("User.saveRecords - someRecords", someRecords); | 294 | //console.log("User.saveRecords - someRecords", someRecords); |
295 | methodName = aMethodName || 'addNewRecords'; | 295 | // methodName = aMethodName || 'addNewRecords'; |
296 | 296 | ||
297 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); | 297 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); |
298 | //MochiKit.Logging.logDebug(">>> User.saveRecords"); | 298 | //MochiKit.Logging.logDebug(">>> User.saveRecords"); |
299 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] User.saveRecords"); | 299 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] User.saveRecords"); |
300 | /* | 300 | /* |
301 | MochiKit.Logging.logDebug("--- User.saveRecords - 1"); | 301 | MochiKit.Logging.logDebug("--- User.saveRecords - 1"); |
302 | MochiKit.Iter.forEach(someRecords, function(aRecord) { | 302 | MochiKit.Iter.forEach(someRecords, function(aRecord) { |
303 | if (aRecord.headerNotes() != null) { | 303 | if (aRecord.headerNotes() != null) { |
304 | aRecord.setNotes(aRecord.headerNotes()); | 304 | aRecord.setNotes(aRecord.headerNotes()); |
305 | } | 305 | } |
306 | aRecord.syncDirectLoginReferenceValues(); | 306 | aRecord.syncDirectLoginReferenceValues(); |
307 | aRecord.currentVersion().createNewVersion(); | 307 | aRecord.currentVersion().createNewVersion(); |
308 | aRecord.updateKey(); | 308 | aRecord.updateKey(); |
309 | }); | 309 | }); |
310 | MochiKit.Logging.logDebug("--- User.saveRecords - 2"); | 310 | MochiKit.Logging.logDebug("--- User.saveRecords - 2"); |
311 | */ | 311 | */ |
312 | 312 | ||
313 | result = {'records': []}; | 313 | result = {'records': []}; |
314 | 314 | ||
315 | deferredResult = new MochiKit.Async.Deferred(); | 315 | deferredResult = new MochiKit.Async.Deferred(); |
316 | c = someRecords.length; | 316 | c = someRecords.length; |
317 | for (i=0; i<c; i++) { | 317 | for (i=0; i<c; i++) { |
318 | deferredResult.addCallback(function(aRecord) { | 318 | deferredResult.addCallback(function(aRecord) { |
319 | if (aRecord.headerNotes() != null) { | 319 | if (aRecord.headerNotes() != null) { |
320 | aRecord.setNotes(aRecord.headerNotes()); | 320 | aRecord.setNotes(aRecord.headerNotes()); |
321 | } | 321 | } |
322 | aRecord.syncDirectLoginReferenceValues(); | 322 | aRecord.syncDirectLoginReferenceValues(); |
323 | aRecord.currentVersion().createNewVersion(); | 323 | aRecord.currentVersion().createNewVersion(); |
324 | aRecord.updateKey(); | 324 | aRecord.updateKey(); |
325 | }, someRecords[i]); | 325 | }, someRecords[i]); |
326 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | 326 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); |
327 | } | 327 | } |
328 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 1 " + res); return res;}); | 328 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 1 " + res); return res;}); |
329 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); | 329 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); |
330 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 2 " + res); return res;}); | 330 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 2 " + res); return res;}); |
331 | 331 | ||
332 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); | 332 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); |
333 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 3 " + res); return res;}); | 333 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 3 " + res); return res;}); |
334 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 334 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
335 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 4 " + res); return res;}); | 335 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 4 " + res); return res;}); |
336 | deferredResult.addCallback(function(aResult, res) { | 336 | deferredResult.addCallback(function(aResult, res) { |
337 | aResult['user'] = res; | 337 | aResult['user'] = res; |
338 | return aResult; | 338 | return aResult; |
339 | }, result); | 339 | }, result); |
340 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 5 " + res); return res;}); | 340 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 5 " + res); return res;}); |
341 | 341 | ||
342 | c = someRecords.length; | 342 | c = someRecords.length; |
343 | for (i=0; i<c; i++) { | 343 | for (i=0; i<c; i++) { |
344 | var recordData; | 344 | var recordData; |
345 | 345 | ||
346 | recordData = {}; | 346 | recordData = {}; |
347 | 347 | ||
348 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.1 " + res); return res;}); | 348 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.1 " + res); return res;}); |
349 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); | 349 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); |
350 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.2 " + res); return res;}); | 350 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.2 " + res); return res;}); |
351 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'encryptedData')); | 351 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'encryptedData')); |
352 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.3 " + res); return res;}); | 352 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.3 " + res); return res;}); |
353 | deferredResult.addCallback(function(aResult, res) { | 353 | deferredResult.addCallback(function(aResult, res) { |
354 | aResult['record'] = res; | 354 | aResult['record'] = res; |
355 | return aResult; | 355 | return aResult; |
356 | }, recordData); | 356 | }, recordData); |
357 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.4 " + res); return res;}); | 357 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.4 " + res); return res;}); |
358 | 358 | ||
359 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {} /*'saveCard_encryptRecordVersions'*/); | 359 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {} /*'saveCard_encryptRecordVersions'*/); |
360 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.5 " + res); return res;}); | 360 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.5 " + res); return res;}); |
361 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i].currentVersion(), 'encryptedData')); | 361 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i].currentVersion(), 'encryptedData')); |
362 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.6 " + res); return res;}); | 362 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.6 " + res); return res;}); |
363 | deferredResult.addCallback(function(aResult, res) { | 363 | deferredResult.addCallback(function(aResult, res) { |
364 | aResult['currentRecordVersion'] = res; | 364 | aResult['currentRecordVersion'] = res; |
365 | return aResult; | 365 | return aResult; |
366 | }, recordData); | 366 | }, recordData); |
367 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.7 " + res); return res;}); | 367 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.7 " + res); return res;}); |
368 | 368 | ||
369 | deferredResult.addCallback(function(aResult, res) { | 369 | deferredResult.addCallback(function(aResult, res) { |
370 | aResult['records'].push(res); | 370 | aResult['records'] = { 'updated': [res] }; |
371 | return aResult; | 371 | return aResult; |
372 | }, result); | 372 | }, result); |
373 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.8 " + res); return res;}); | 373 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.8 " + res); return res;}); |
374 | } | 374 | } |
375 | 375 | ||
376 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 7 " + res); return res;}); | 376 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 7 " + res); return res;}); |
377 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData'); | 377 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData'); |
378 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 8 " + res); return res;}); | 378 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 8 " + res); return res;}); |
379 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), methodName); | 379 | // deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), methodName); |
380 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'saveChanges'); | ||
380 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9 " + res); return res;}); | 381 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9 " + res); return res;}); |
381 | 382 | ||
382 | for (i=0; i<c; i++) { | 383 | for (i=0; i<c; i++) { |
383 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.1 " + res); return res;}); | 384 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.1 " + res); return res;}); |
384 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'takeSnapshotOfCurrentData')); | 385 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'takeSnapshotOfCurrentData')); |
385 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.2 " + res); return res;}); | 386 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.2 " + res); return res;}); |
386 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'setIsBrandNew'), false); | 387 | deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'setIsBrandNew'), false); |
387 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.3 " + res); return res;}); | 388 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.3 " + res); return res;}); |
388 | } | 389 | } |
389 | 390 | ||
390 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 10 " + res); return res;}); | 391 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 10 " + res); return res;}); |
391 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated'); | 392 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated'); |
392 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 11 " + res); return res;}); | 393 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 11 " + res); return res;}); |
393 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated'); | 394 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated'); |
394 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 12 " + res); return res;}); | 395 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 12 " + res); return res;}); |
395 | deferredResult.callback(); | 396 | deferredResult.callback(); |
396 | 397 | ||
397 | return deferredResult; | 398 | return deferredResult; |
398 | }, | 399 | }, |
399 | 400 | ||
400 | //------------------------------------------------------------------------- | 401 | //------------------------------------------------------------------------- |
401 | 402 | ||
402 | 'removeRecord': function(aRecord) { | 403 | 'removeRecord': function(aRecord) { |
403 | //MochiKit.Logging.logDebug(">>> User.removeRecord"); | 404 | //MochiKit.Logging.logDebug(">>> User.removeRecord"); |
404 | delete this.records()[aRecord.reference()]; | 405 | delete this.records()[aRecord.reference()]; |
405 | //MochiKit.Logging.logDebug("--- User.removeRecord - 1"); | 406 | //MochiKit.Logging.logDebug("--- User.removeRecord - 1"); |
406 | Clipperz.NotificationCenter.notify(aRecord, 'recordRemoved', null, false); | 407 | Clipperz.NotificationCenter.notify(aRecord, 'recordRemoved', null, false); |
407 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); | 408 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true); |
408 | //MochiKit.Logging.logDebug("<<< User.removeRecord"); | 409 | //MochiKit.Logging.logDebug("<<< User.removeRecord"); |
409 | }, | 410 | }, |
410 | 411 | ||
411 | //------------------------------------------------------------------------- | 412 | //------------------------------------------------------------------------- |
412 | 413 | ||
413 | 'deleteRecordsAction': function(someRecords) { | 414 | 'deleteRecordsAction': function(someRecords) { |
414 | vardeferredResult; | 415 | vardeferredResult; |
415 | var parameters; | 416 | var parameters; |
416 | 417 | ||
417 | //MochiKit.Logging.logDebug(">>> User.deleteRecordsAction - someRecords.length: " + someRecords.length); | 418 | //MochiKit.Logging.logDebug(">>> User.deleteRecordsAction - someRecords.length: " + someRecords.length); |
418 | parameters = {}; | 419 | parameters = {}; |
419 | deferredResult = new MochiKit.Async.Deferred(); | 420 | deferredResult = new MochiKit.Async.Deferred(); |
420 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 1 " + res); return res;}); | 421 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 1 " + res); return res;}); |
421 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_collectData'); | 422 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_collectData'); |
422 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 2 " + res); return res;}); | 423 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 2 " + res); return res;}); |
423 | deferredResult.addCallback(function(someParameters, someRecords) { | 424 | deferredResult.addCallback(function(someParameters, someRecords) { |
424 | var recordReferences; | 425 | var recordReferences; |
425 | 426 | ||
426 | recordReferences = MochiKit.Base.map(function(aRecord) { | 427 | recordReferences = MochiKit.Base.map(function(aRecord) { |
427 | var result; | 428 | var result; |
428 | 429 | ||
429 | result = aRecord.reference(); | 430 | result = aRecord.reference(); |
430 | aRecord.remove(); | 431 | aRecord.remove(); |
431 | 432 | ||
432 | return result; | 433 | return result; |
433 | }, someRecords); | 434 | }, someRecords); |
434 | someParameters.recordReferences = recordReferences; | 435 | // someParameters.recordReferences = recordReferences; |
436 | someParameters['records'] = { 'deleted': recordReferences}; | ||
435 | 437 | ||
436 | return someParameters; | 438 | return someParameters; |
437 | }, parameters); | 439 | }, parameters); |
438 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 3 " + res); return res;}); | 440 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 3 " + res); return res;}); |
439 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_encryptData'); | 441 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_encryptData'); |
440 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 4 " + res); return res;}); | 442 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 4 " + res); return res;}); |
441 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 443 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
442 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 5 " + res); return res;}); | 444 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 5 " + res); return res;}); |
443 | deferredResult.addCallback(function(someParameters, anUserEncryptedData) { | 445 | deferredResult.addCallback(function(someParameters, anUserEncryptedData) { |
444 | someParameters.user = anUserEncryptedData; | 446 | someParameters.user = anUserEncryptedData; |
445 | return someParameters; | 447 | return someParameters; |
446 | }, parameters); | 448 | }, parameters); |
447 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 6 " + res); return res;}); | 449 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 6 " + res); return res;}); |
448 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_sendingData'); | 450 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_sendingData'); |
449 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecords parameters: " + Clipperz.Base.serializeJSON(res)); return res;}); | 451 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecords parameters: " + Clipperz.Base.serializeJSON(res)); return res;}); |
450 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 7 " + res); return res;}); | 452 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 7 " + res); return res;}); |
451 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'deleteRecords'); | 453 | // deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'deleteRecords'); |
454 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'saveChanges'); | ||
452 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 8 " + res); return res;}); | 455 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 8 " + res); return res;}); |
453 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_updatingInterface'); | 456 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_updatingInterface'); |
454 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 9 " + res); return res;}); | 457 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 9 " + res); return res;}); |
455 | deferredResult.callback(someRecords); | 458 | deferredResult.callback(someRecords); |
456 | //MochiKit.Logging.logDebug("<<< User.deleteRecordsAction"); | 459 | //MochiKit.Logging.logDebug("<<< User.deleteRecordsAction"); |
457 | 460 | ||
458 | return deferredResult; | 461 | return deferredResult; |
459 | }, | 462 | }, |
460 | 463 | ||
461 | //------------------------------------------------------------------------- | 464 | //------------------------------------------------------------------------- |
462 | 465 | ||
463 | 'resetAllLocalData': function() { | 466 | 'resetAllLocalData': function() { |
464 | this.resetConnection(); | 467 | this.resetConnection(); |
465 | 468 | ||
466 | this.setUsername(""); | 469 | this.setUsername(""); |
467 | this.setPassphrase(""); | 470 | this.setPassphrase(""); |
468 | 471 | ||
469 | this._header = null; | 472 | this._header = null; |
470 | this._statistics = null; | 473 | this._statistics = null; |
471 | this._preferences = null; | 474 | this._preferences = null; |
472 | this._records = {}; | 475 | this._records = {}; |
473 | this._directLoginReferences = {}; | 476 | this._directLoginReferences = {}; |
474 | }, | 477 | }, |
475 | 478 | ||
476 | //------------------------------------------------------------------------- | 479 | //------------------------------------------------------------------------- |
477 | 480 | ||
478 | 'deleteAccountAction': function() { | 481 | 'deleteAccountAction': function() { |
479 | var deferredResult; | 482 | var deferredResult; |
480 | 483 | ||
481 | //MochiKit.Logging.logDebug(">>> user.deleteAccountAction - " + this); | 484 | //MochiKit.Logging.logDebug(">>> user.deleteAccountAction - " + this); |
482 | deferredResult = new MochiKit.Async.Deferred(); | 485 | deferredResult = new MochiKit.Async.Deferred(); |
483 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'deleteUser'); | 486 | deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'deleteUser'); |
484 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetAllLocalData')); | 487 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetAllLocalData')); |
485 | deferredResult.callback(); | 488 | deferredResult.callback(); |
486 | //MochiKit.Logging.logDebug("<<< user.deleteAccountAction - " + this); | 489 | //MochiKit.Logging.logDebug("<<< user.deleteAccountAction - " + this); |
487 | 490 | ||
488 | return deferredResult; | 491 | return deferredResult; |
489 | }, | 492 | }, |
490 | 493 | ||
491 | //------------------------------------------------------------------------- | 494 | //------------------------------------------------------------------------- |
492 | 495 | ||
493 | 'encryptedData': function() { | 496 | 'encryptedData': function() { |
494 | var deferredResult; | 497 | var deferredResult; |
495 | varresult; | 498 | varresult; |
496 | 499 | ||
497 | result = {}; | 500 | result = {}; |
498 | 501 | ||
499 | deferredResult = new MochiKit.Async.Deferred(); | 502 | deferredResult = new MochiKit.Async.Deferred(); |
500 | 503 | ||
501 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 0: " + res); return res;}); | 504 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 0: " + res); return res;}); |
502 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'encryptedData')); | 505 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'encryptedData')); |
503 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 1: " + res); return res;}); | 506 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 1: " + res); return res;}); |
504 | deferredResult.addCallback(function(aResult, aValue) { | 507 | deferredResult.addCallback(function(aResult, aValue) { |
505 | aResult['header'] = aValue; | 508 | aResult['header'] = aValue; |
506 | }, result); | 509 | }, result); |
507 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 2: " + res); return res;}); | 510 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 2: " + res); return res;}); |
508 | 511 | ||
509 | deferredResult.addCallback(MochiKit.Base.method(this.statistics(), 'encryptedData')); | 512 | deferredResult.addCallback(MochiKit.Base.method(this.statistics(), 'encryptedData')); |
510 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 3: " + res); return res;}); | 513 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 3: " + res); return res;}); |
511 | deferredResult.addCallback(function(aResult, aValue) { | 514 | deferredResult.addCallback(function(aResult, aValue) { |
512 | aResult['statistics'] = aValue; | 515 | aResult['statistics'] = aValue; |
513 | }, result); | 516 | }, result); |
514 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 4: " + res); return res;}); | 517 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 4: " + res); return res;}); |
515 | 518 | ||
516 | deferredResult.addCallback(MochiKit.Base.bind(function(aResult, aValue) { | 519 | deferredResult.addCallback(MochiKit.Base.bind(function(aResult, aValue) { |
517 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; | 520 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; |
518 | aResult['lock'] = this.lock(); | 521 | aResult['lock'] = this.lock(); |
519 | 522 | ||
520 | return aResult; | 523 | return aResult; |
521 | }, this), result); | 524 | }, this), result); |
522 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 5: " + res); return res;}); | 525 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 5: " + res); return res;}); |
523 | deferredResult.callback(); | 526 | deferredResult.callback(); |
524 | 527 | ||
525 | return deferredResult; | 528 | return deferredResult; |
526 | }, | 529 | }, |
527 | 530 | ||
528 | //------------------------------------------------------------------------- | 531 | //------------------------------------------------------------------------- |
529 | 532 | ||
530 | 'preferences': function() { | 533 | 'preferences': function() { |
531 | if (this._preferences == null) { | 534 | if (this._preferences == null) { |
532 | this._preferences = new Clipperz.PM.DataModel.UserPreferences({user:this}); | 535 | this._preferences = new Clipperz.PM.DataModel.UserPreferences({user:this}); |
533 | } | 536 | } |
534 | 537 | ||
535 | return this._preferences; | 538 | return this._preferences; |
536 | }, | 539 | }, |
537 | /* | 540 | /* |
538 | 'setPreferences': function(aValue) { | 541 | 'setPreferences': function(aValue) { |
539 | this._preferences = aValue; | 542 | this._preferences = aValue; |
540 | 543 | ||
541 | if (this._preferences.preferredLanguage() != null) { | 544 | if (this._preferences.preferredLanguage() != null) { |
542 | Clipperz.PM.Strings.Languages.setSelectedLanguage(this._preferences.preferredLanguage()); | 545 | Clipperz.PM.Strings.Languages.setSelectedLanguage(this._preferences.preferredLanguage()); |
543 | } else { | 546 | } else { |
544 | //MochiKit.Logging.logDebug("### keepping the browser selected language: " + Clipperz.PM.Strings.selectedLanguage); | 547 | //MochiKit.Logging.logDebug("### keepping the browser selected language: " + Clipperz.PM.Strings.selectedLanguage); |
545 | } | 548 | } |
546 | }, | 549 | }, |
547 | */ | 550 | */ |
548 | //------------------------------------------------------------------------- | 551 | //------------------------------------------------------------------------- |
549 | 552 | ||
550 | 'oneTimePasswordManager': function() { | 553 | 'oneTimePasswordManager': function() { |
551 | if (this._oneTimePasswordManager == null) { | 554 | if (this._oneTimePasswordManager == null) { |
552 | this._oneTimePasswordManager = new Clipperz.PM.DataModel.OneTimePasswordManager(this, null); | 555 | this._oneTimePasswordManager = new Clipperz.PM.DataModel.OneTimePasswordManager(this, null); |
553 | } | 556 | } |
554 | 557 | ||
555 | return this._oneTimePasswordManager; | 558 | return this._oneTimePasswordManager; |
556 | }, | 559 | }, |
557 | 560 | ||
558 | //------------------------------------------------------------------------- | 561 | //------------------------------------------------------------------------- |
559 | 562 | ||
560 | 'directLoginReferences': function() { | 563 | 'directLoginReferences': function() { |
561 | return this._directLoginReferences; | 564 | return this._directLoginReferences; |
562 | }, | 565 | }, |
563 | 566 | ||
564 | 'addDirectLoginReference': function(aDirectLoginReference, isBatchUpdate) { | 567 | 'addDirectLoginReference': function(aDirectLoginReference, isBatchUpdate) { |
565 | //MochiKit.Logging.logDebug(">>> User.addDirectLoginReference"); | 568 | //MochiKit.Logging.logDebug(">>> User.addDirectLoginReference"); |
566 | this.directLoginReferences()[aDirectLoginReference.reference()] = aDirectLoginReference; | 569 | this.directLoginReferences()[aDirectLoginReference.reference()] = aDirectLoginReference; |
567 | 570 | ||
568 | if (isBatchUpdate != true) { | 571 | if (isBatchUpdate != true) { |
569 | Clipperz.NotificationCenter.notify(aDirectLoginReference, 'directLoginAdded'); | 572 | Clipperz.NotificationCenter.notify(aDirectLoginReference, 'directLoginAdded'); |
570 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'directLogins', true); | 573 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'directLogins', true); |
571 | } | 574 | } |
572 | }, | 575 | }, |
573 | 576 | ||
574 | 'removeDirectLoginReference': function(aDirectLoginReference) { | 577 | 'removeDirectLoginReference': function(aDirectLoginReference) { |
575 | delete this.directLoginReferences()[aDirectLoginReference.reference()]; | 578 | delete this.directLoginReferences()[aDirectLoginReference.reference()]; |
576 | Clipperz.NotificationCenter.notify(aDirectLoginReference, 'directLoginRemoved'); | 579 | Clipperz.NotificationCenter.notify(aDirectLoginReference, 'directLoginRemoved'); |
577 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'directLogins', true); | 580 | Clipperz.NotificationCenter.notify(this, 'updatedSection', 'directLogins', true); |
578 | }, | 581 | }, |
579 | 582 | ||
580 | //......................................................................... | 583 | //......................................................................... |
581 | 584 | ||
582 | 'addDirectLogin': function(aDirectLogin) { | 585 | 'addDirectLogin': function(aDirectLogin) { |
583 | varnewDirectLoginReference; | 586 | varnewDirectLoginReference; |
584 | 587 | ||
585 | newDirectLoginReference = new Clipperz.PM.DataModel.DirectLoginReference({user:this, directLogin:aDirectLogin}) | 588 | newDirectLoginReference = new Clipperz.PM.DataModel.DirectLoginReference({user:this, directLogin:aDirectLogin}) |
586 | this.addDirectLoginReference(newDirectLoginReference); | 589 | this.addDirectLoginReference(newDirectLoginReference); |
587 | }, | 590 | }, |
588 | 591 | ||
589 | 'synchronizeDirectLogin': function(aDirectLogin) { | 592 | 'synchronizeDirectLogin': function(aDirectLogin) { |
590 | var directLoginReference; | 593 | var directLoginReference; |
591 | 594 | ||
592 | directLoginReference = this.directLoginReferences()[aDirectLogin.reference()]; | 595 | directLoginReference = this.directLoginReferences()[aDirectLogin.reference()]; |
593 | if (typeof(directLoginReference) != 'undefined') { | 596 | if (typeof(directLoginReference) != 'undefined') { |
594 | directLoginReference.synchronizeValues(aDirectLogin); | 597 | directLoginReference.synchronizeValues(aDirectLogin); |
595 | } else { | 598 | } else { |
596 | this.addDirectLogin(aDirectLogin); | 599 | this.addDirectLogin(aDirectLogin); |
597 | } | 600 | } |
598 | }, | 601 | }, |
599 | 602 | ||
600 | 'removeDirectLogin': function(aDirectLogin) { | 603 | 'removeDirectLogin': function(aDirectLogin) { |
601 | this.removeDirectLoginReference(aDirectLogin); | 604 | this.removeDirectLoginReference(aDirectLogin); |
602 | }, | 605 | }, |
603 | 606 | ||
604 | //------------------------------------------------------------------------- | 607 | //------------------------------------------------------------------------- |
605 | 608 | ||
606 | 'changeCredentials': function(aUsername, aPassphrase) { | 609 | 'changeCredentials': function(aUsername, aPassphrase) { |
607 | vardeferredResult; | 610 | vardeferredResult; |
608 | var result; | 611 | var result; |
609 | 612 | ||
610 | result = {}; | 613 | result = {}; |
611 | 614 | ||
612 | deferredResult = new MochiKit.Async.Deferred(); | 615 | deferredResult = new MochiKit.Async.Deferred(); |
613 | 616 | ||
614 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'loadAllSections')); | 617 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'loadAllSections')); |
615 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'updateAllSections')); | 618 | deferredResult.addCallback(MochiKit.Base.method(this.header(), 'updateAllSections')); |
616 | 619 | ||
617 | deferredResult.addCallback(MochiKit.Base.bind(function(aUsername, aPssphrase) { | 620 | deferredResult.addCallback(MochiKit.Base.bind(function(aUsername, aPssphrase) { |
618 | this.setUsername(aUsername); | 621 | this.setUsername(aUsername); |
619 | this.setPassphrase(aPassphrase); | 622 | this.setPassphrase(aPassphrase); |
620 | }, this), aUsername, aPassphrase) | 623 | }, this), aUsername, aPassphrase) |
621 | 624 | ||
622 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 1: " + res); return res;}); | 625 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 1: " + res); return res;}); |
623 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'changeCredentials_encryptingData'); | 626 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'changeCredentials_encryptingData'); |
624 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 2: " + res); return res;}); | 627 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 2: " + res); return res;}); |
625 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 628 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
626 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 3: " + res); return res;}); | 629 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 3: " + res); return res;}); |
627 | deferredResult.addCallback(function(aResult, anEncryptedData) { | 630 | deferredResult.addCallback(function(aResult, anEncryptedData) { |
628 | aResult['user'] = anEncryptedData; | 631 | aResult['user'] = anEncryptedData; |
629 | 632 | ||
630 | return aResult; | 633 | return aResult; |
631 | }, result); | 634 | }, result); |
632 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 4: " + res); return res;}); | 635 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 4: " + res); return res;}); |
633 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'changeCredentials_creatingNewCredentials'); | 636 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'changeCredentials_creatingNewCredentials'); |
634 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 5: " + res); return res;}); | 637 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 5: " + res); return res;}); |
635 | deferredResult.addCallback(function(aResult, anUser) { | 638 | deferredResult.addCallback(function(aResult, anUser) { |
636 | varnewConnection; | 639 | varnewConnection; |
637 | 640 | ||
638 | newConnection = new Clipperz.PM.Crypto.communicationProtocol.versions[Clipperz.PM.Crypto.communicationProtocol.currentVersion]({user:anUser}) | 641 | newConnection = new Clipperz.PM.Crypto.communicationProtocol.versions[Clipperz.PM.Crypto.communicationProtocol.currentVersion]({user:anUser}) |
639 | aResult['credentials'] = newConnection.serverSideUserCredentials(); | 642 | aResult['credentials'] = newConnection.serverSideUserCredentials(); |
640 | 643 | ||
641 | return aResult; | 644 | return aResult; |
642 | }, result, this); | 645 | }, result, this); |
643 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 6: " + res); return res;}); | 646 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 6: " + res); return res;}); |