summaryrefslogtreecommitdiff
path: root/frontend
Side-by-side diff
Diffstat (limited to 'frontend') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Connection.js9
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/Record.js12
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/User.js17
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
'sharedSecret': function() {
throw Clipperz.Base.exception.AbstractMethod;
},
'serverSideUserCredentials': function() {
throw Clipperz.Base.exception.AbstractMethod;
},
//=========================================================================
'connectionId': function() {
return this._connectionId;
},
'setConnectionId': function(aValue) {
this._connectionId = aValue;
},
//=========================================================================
'oneTimePassword': function() {
return this._oneTimePassword;
},
'setOneTimePassword': function(aValue) {
this._oneTimePassword = aValue;
},
//=========================================================================
__syntaxFix__: "syntax fix"
}
);
if (typeof(Clipperz.PM.Connection.SRP) == 'undefined') { Clipperz.PM.Connection.SRP = {}; }
//-----------------------------------------------------------------------------
//
// S R P [ 1 . 0 ] C O N N E C T I O N class
//
//-----------------------------------------------------------------------------
Clipperz.PM.Connection.SRP['1.0'] = function (args) {
args = args || {};
Clipperz.PM.Connection.call(this, args);
this._C = null;
this._P = null;
this._srpConnection = null;
return this;
}
Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection(), {
'version': function() {
return '1.0';
},
//=========================================================================
'register': function(anInvitationCode) {
var deferredResult;
var parameters;
//MochiKit.Logging.logError(">>> Connection.register: " + this);
parameters = {};
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 1: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_verify');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 2: " + res); return res;});
deferredResult.addCallback(function(aConnection, anInvitationCode) {
var args;
args = {};
args.message = 'register';
args.version = aConnection.clipperz_pm_crypto_version();
args.invitationCode = anInvitationCode;
return args;
}, this);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 3: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_sendingCredentials');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 4: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 5: " + res); return res;});
deferredResult.addCallback(function(someParameters, anUser, anEncryptedData) {
var currentVersionConnection;
var args;
currentVersionConnection = new Clipperz.PM.Crypto.communicationProtocol.versions['current']({user:anUser});
args = someParameters
args.credentials = currentVersionConnection.serverSideUserCredentials();
args.user = anEncryptedData;
args.version = args.credentials.version;
args.message = "completeRegistration";
return args;
}, parameters, this.user());
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 6: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'registration'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 7: " + Clipperz.Base.serializeJSON(res)); return res;});
deferredResult.addCallback(MochiKit.Base.bind(function(res) {
this.user().setLock(res['lock']);
return res;
}, this));
deferredResult.callback(anInvitationCode);
//MochiKit.Logging.logError("<<< Connection.register");
return deferredResult;
},
//=========================================================================
'login': function(isReconnecting) {
var deferredResult;
//MochiKit.Logging.logDebug(">>> Connection.login: "/* + this*/);
//MochiKit.Logging.logDebug("--- Connection.login - isReconnecting: " + (isReconnecting == true));
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.1 - Connection.login - 1: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_sendingCredentials');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.2 - Connection.login - 2: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(function(aConnection) {
var args;
args = {};
args.message = 'connect';
args.version = aConnection.clipperz_pm_crypto_version();
args.parameters = {};
//MochiKit.Logging.logDebug("=== Connection.login - username: " + aConnection.srpConnection().C());
args.parameters['C'] = aConnection.srpConnection().C();
args.parameters['A'] = aConnection.srpConnection().A().asString(16);
if (isReconnecting == true) {
//MochiKit.Logging.logDebug("--- Connection.login - reconnecting");
//# args.parameters['reconnecting'] = "yes";
args.parameters['reconnecting'] = aConnection.connectionId();
}
//MochiKit.Logging.logDebug("--- Connection.login - args: " + Clipperz.Base.serializeJSON(args));
//MochiKit.Logging.logDebug("--- Connection.login - srp.a: " + aConnection.srpConnection().a().asString(16));
return args;
});
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.3 - Connection.login - 3: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.4 - Connection.login - 4: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_credentialVerification');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.5 - Connection.login - 5: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addErrback(MochiKit.Base.bind(function(res) {MochiKit.Logging.logDebug("ERROR - c: " + this.srpConnection().C() + " # version: " + this.clipperz_pm_crypto_version()); return res;}, this));
deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) {
var args;
this.srpConnection().set_s(new Clipperz.Crypto.BigInt(someParameters['s'], 16));
this.srpConnection().set_B(new Clipperz.Crypto.BigInt(someParameters['B'], 16));
if (typeof(someParameters['oneTimePassword']) != 'undefined') {
this.setOneTimePassword(someParameters['oneTimePassword']);
}
args = {};
args.message = 'credentialCheck';
args.version = this.clipperz_pm_crypto_version();
args.parameters = {};
args.parameters['M1'] = this.srpConnection().M1();
return args;
}, this));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.6 - Connection.login - 6: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.7 - Connection.login - 7: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
//# deferredResult.addCallback(MochiKit.Base.method(this, 'loginDone'));
deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) {
var result;
//MochiKit.Logging.logDebug(">>> Connection.loginDone: " + this + " (M2: " + this.srpConnection().M2() + ")");
if (someParameters['M2'] == this.srpConnection().M2()) {
result = new MochiKit.Async.Deferred();
//MochiKit.Logging.logDebug("--- Connection.loginDone - someParameters: " + Clipperz.Base.serializeJSON(someParameters));
this.setConnectionId(someParameters['connectionId']);
this.user().setLoginInfo(someParameters['loginInfo']);
this.user().setShouldDownloadOfflineCopy(someParameters['offlineCopyNeeded']);
- this.user().setLock(someParameters['lock']);
+
+ if ((isReconnecting == true) && (this.user().lock() != someParameters['lock'])) {
+ throw Clipperz.PM.Connection.exception.StaleData;
+ }
if (this.oneTimePassword() != null) {
result.addCallback(MochiKit.Base.method(this.user().oneTimePasswordManager(), 'archiveOneTimePassword', this.oneTimePassword()));
}
+
result.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_loggedIn');
result.addCallback(MochiKit.Async.succeed, someParameters);
result.callback();
//MochiKit.Logging.logDebug("--- Connection.loginDone - 1 - result: "/* + Clipperz.Base.serializeJSON(result)*/);
} else {
//MochiKit.Logging.logDebug("--- Connection.loginDone - 2 - ERROR");
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
result = MochiKit.Async.fail(Clipperz.PM.Connection.exception.WrongChecksum);
}
//MochiKit.Logging.logDebug("<<< Connection.loginDone - result: " + Clipperz.Base.serializeJSON(result));
return result;
}, this));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.8 - Connection.login - 8: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.callback(this);
//MochiKit.Logging.logDebug("<<< Connection.login");
return deferredResult;
},
//=========================================================================
'logout': function() {
var deferredResult;
//MochiKit.Logging.logDebug(">>> Connection.logout: " + this);
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 1: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'logout'), {});
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 2: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 3: " + res); return res;});
deferredResult.callback();
//MochiKit.Logging.logDebug("<<< Connection.logout");
return deferredResult;
},
//=========================================================================
'message': function(aMessageName, someParameters) {
var args;
var deferredResult;
//MochiKit.Logging.logDebug(">>> Connection.message: " + this);
args = {}
args['message'] = aMessageName;
args['srpSharedSecret'] = this.srpConnection().K();
// args['lock'] = this.user().lock();
if (someParameters != null) {
args['parameters'] = someParameters;
} else {
args['parameters'] = {};
}
//MochiKit.Logging.logDebug("--- Connection.message - args: " + Clipperz.Base.serializeJSON(args));
// deferredResult = new MochiKit.Async.Deferred(); // ### ?????????????
return this.sendMessage(args);
},
//-------------------------------------------------------------------------
'sendMessage': function(someArguments) {
var deferredResult;
//MochiKit.Logging.logDebug(">>> Connection.sendMessage: " + this);
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 1: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'message'), someArguments);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 2: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.bind(function(res) {
if (typeof(res['lock']) != 'undefined') {
this.user().setLock(res['lock']);
}
return res;
}, this));
deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + res); return res;});
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + Clipperz.Base.serializeJSON(res)); return res;});
deferredResult.callback();
//MochiKit.Logging.logDebug("<<< Connection.sendMessage");
return deferredResult
},
//-------------------------------------------------------------------------
'messageExceptionHandler': function(anOriginalMessageArguments, anError) {
var result;
//MochiKit.Logging.logDebug(">>> Connection.messageExceptionHandler - this: " + this + ", anError: " + anError);
if (anError instanceof MochiKit.Async.CancelledError) {
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 1");
result = anError;
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 2");
} else {
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 3 - anError.name: " + anError.name + ", message: " + anError.message);
if ((anError.message == 'Trying to communicate without an active connection') ||
(anError.message == 'No tollManager available for current session')
) {
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 4");
result = this.reestablishConnection(anOriginalMessageArguments);
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5");
} else if (anError.message == 'Session with stale data') {
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.1");
Clipperz.NotificationCenter.notify(this, 'EXCEPTION');
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.2");
} else {
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 6");
result = anError;
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 7");
}
//MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 8");
}
//MochiKit.Logging.logDebug("<<< Connection.messageExceptionHandler");
return result;;
},
//=========================================================================
'reestablishConnection': function(anOriginalMessageArguments) {
var deferredResult;
//MochiKit.Logging.logDebug("+++ Connection.reestablishConnection: " + Clipperz.Base.serializeJSON(anOriginalMessageArguments));
//MochiKit.Logging.logDebug(">>> Connection.reestablishConnection: " + this);
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 1: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 2: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this, 'login'), true);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 3: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.bind(function(aMessage) {
aMessage['srpSharedSecret'] = this.srpConnection().K();
return aMessage;
}, this), anOriginalMessageArguments);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 4: " + Clipperz.Base.serializeJSON(res)); return res;});
deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 5: " + res); return res;});
deferredResult.addErrback(Clipperz.NotificationCenter.deferredNotification, this, 'EXCEPTION', null);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 6: " + res); return res;});
deferredResult.callback();
//MochiKit.Logging.logDebug("<<< Connection.reestablishConnection");
return deferredResult;
},
//=========================================================================
'sharedSecret': function() {
return this.srpConnection().K();
},
//=========================================================================
'serverSideUserCredentials': function() {
var result;
var newSrpConnection;
//MochiKit.Logging.logDebug(">>> Connection.serverSideUserCredentials");
newSrpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() });
result = newSrpConnection.serverSideCredentials();
result['version'] = this.clipperz_pm_crypto_version();
//MochiKit.Logging.logDebug("<<< Connection.serverSideUserCredentials - result: " + Clipperz.Base.serializeJSON(result));
return result;
},
//=========================================================================
'C': function() {
if (this._C == null) {
this._C = this.hash()(new Clipperz.ByteArray(this.user().username())).toHexString().substring(2);
}
return this._C;
},
//-----------------------------------------------------------------------------
'P': function() {
if (this._P == null) {
this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2);
}
return this._P;
},
//-----------------------------------------------------------------------------
'hash': function() {
return Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].hash;
},
//-----------------------------------------------------------------------------
'srpConnection': function() {
if (this._srpConnection == null) {
this._srpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() });
}
return this._srpConnection;
},
'resetSrpConnection': function() {
this._C = null;
this._P = null;
this._srpConnection = null;
},
//-----------------------------------------------------------------------------
__syntaxFix__: "syntax fix"
});
//-----------------------------------------------------------------------------
//
// S R P [ 1 . 1 ] C O N N E C T I O N class
//
//-----------------------------------------------------------------------------
Clipperz.PM.Connection.SRP['1.1'] = function (args) {
args = args || {};
Clipperz.PM.Connection.SRP['1.0'].call(this, args);
return this;
}
Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection.SRP['1.0'](), {
'version': function() {
return '1.1';
},
//-----------------------------------------------------------------------------
'C': function() {
if (this._C == null) {
this._C = this.hash()(new Clipperz.ByteArray(this.user().username() + this.user().passphrase())).toHexString().substring(2);
}
return this._C;
},
//-----------------------------------------------------------------------------
'P': function() {
if (this._P == null) {
this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2);
}
return this._P;
},
//-----------------------------------------------------------------------------
'hash': function() {
return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash;
},
//-----------------------------------------------------------------------------
__syntaxFix__: "syntax fix"
});
Clipperz.PM.Connection.exception = {
- WrongChecksum: new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.InvalidValue")
+ WrongChecksum: new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.InvalidValue"),
+ StaleData: new MochiKit.Base.NamedError("Stale data")
};
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
return this._removedDirectLogins;
},
'resetRemovedDirectLogins': function() {
this._removedDirectLogins = [];
},
//-------------------------------------------------------------------------
'serverData': function() {
return this._serverData;
},
'setServerData': function(aValue) {
this._serverData = aValue;
this.setShouldLoadData(false);
return aValue;
},
//-------------------------------------------------------------------------
'decryptedData': function() {
return this._decryptedData;
},
'setDecryptedData': function(aValue) {
this._decryptedData = aValue;
this.setShouldDecryptData(false);
return aValue;
},
//-------------------------------------------------------------------------
'cachedData': function() {
return this._cachedData;
},
'setCachedData': function(aValue) {
//MochiKit.Logging.logDebug(">>> Record.setCachedData");
//MochiKit.Logging.logDebug("--- Record.setCachedData - aValue: " + Clipperz.Base.serializeJSON(aValue));
this._cachedData = aValue;
this.setShouldProcessData(false);
//MochiKit.Logging.logDebug("<<< Record.setCachedData");
return aValue;
},
//-------------------------------------------------------------------------
'hasPendingChanges': function() {
var result;
//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.hasPendingChanges");
//MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + this.cachedData());
//MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData()));
//MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + this.currentDataSnapshot());
//MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + Clipperz.Base.serializeJSON(this.currentDataSnapshot()));
//console.log(">>> Record.hasPendingChanges - cachedData: %o", this.cachedData());
//console.log(">>> Record.hasPendingChanges - currentSnapshot: %o", this.currentDataSnapshot());
result = (MochiKit.Base.compare(this.cachedData(), this.currentDataSnapshot()) != 0);
//MochiKit.Logging.logDebug("<<< Record.hasPendingChanges - " + result);
if ((result == false) && this.isBrandNew() && (this.label() != Clipperz.PM.Strings['newRecordTitleLabel'])) {
result = true;
}
//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.hasPendingChanges");
return result;
},
//-------------------------------------------------------------------------
'currentDataSnapshot': function() {
var result;
//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.currentDataSnapshot");
result = {
'label': this.label(),
'data': this.serializedData(),
'currentVersion': this.currentVersion().currentDataSnapshot()
};
// result['data']['data'] = this.notes();
result = Clipperz.Base.serializeJSON(result);
//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.currentDataSnapshot");
//MochiKit.Logging.logDebug("<<< Record.currentDataSnapshot");
return result;
},
//.........................................................................
'takeSnapshotOfCurrentData': function() {
this.setCachedData(this.currentDataSnapshot());
},
//-------------------------------------------------------------------------
'headerData': function() {
var result;
result = {
'label': this.label(),
'key': this.key()
};
if (this.headerNotes() != null) {
result['headerNotes'] = this.headerNotes();
}
return result;
},
//-------------------------------------------------------------------------
'serializedData': function() {
var result;
var directLoginReference;
result = {};
result['currentVersionKey'] = this.currentVersion().key();
result['directLogins'] = {};
for (directLoginReference in this.directLogins()) {
result['directLogins'][directLoginReference] = this.directLogins()[directLoginReference].serializedData();
}
result['notes'] = this.notes();
return result;
},
//-------------------------------------------------------------------------
'encryptedData': function() {
var deferredResult;
var result;
//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.encryptedData");
result = {}
//MochiKit.Logging.logDebug("--- Record.encryptedData - 1");
deferredResult = new MochiKit.Async.Deferred();
//MochiKit.Logging.logDebug("--- Record.encryptedData - 2");
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 1: " + res); return res;});
deferredResult.addCallback(function(aResult, aRecord) {
aResult['reference'] = aRecord.reference();
return aResult;
}, result, this);
//MochiKit.Logging.logDebug("--- Record.encryptedData - 3");
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 2: " + res); return res;});
deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.key(), this.serializedData());
//MochiKit.Logging.logDebug("--- Record.encryptedData - 4");
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 3: " + res); return res;});
deferredResult.addCallback(function(aResult, res) {
aResult['data'] = res;
return aResult;
}, result);
//MochiKit.Logging.logDebug("--- Record.encryptedData - 5");
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 4: " + res); return res;});
deferredResult.addCallback(function(aResult) {
aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion;
return aResult;
}, result);
//MochiKit.Logging.logDebug("--- Record.encryptedData - 6");
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 5: " + res); return res;});
deferredResult.callback();
//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.encryptedData");
return deferredResult;
},
//-------------------------------------------------------------------------
'syncDirectLoginReferenceValues': function() {
//MochiKit.Logging.logDebug(">>> Record.syncDirectLoginReferenceValues");
MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), function(aDirectLogin) {
aDirectLogin.record().user().synchronizeDirectLogin(aDirectLogin);
});
MochiKit.Iter.forEach(this.removedDirectLogins(), function(aDirectLogin) {
aDirectLogin.record().user().removeDirectLogin(aDirectLogin);
});
this.resetRemovedDirectLogins();
//MochiKit.Logging.logDebug("<<< Record.syncDirectLoginReferenceValues");
},
//-------------------------------------------------------------------------
'saveChanges': function() {
var result;
- if (this.isBrandNew() == false) {
- result = this.user().saveRecords([this], 'updateData');
- } else {
- result = this.user().saveRecords([this], 'addNewRecords');
- }
+// if (this.isBrandNew() == false) {
+// result = this.user().saveRecords([this], 'updateData');
+// } else {
+// result = this.user().saveRecords([this], 'addNewRecords');
+// }
+
+ result = this.user().saveRecords([this]);
return result;
},
/*
'saveChanges': function() {
var deferredResult;
var result;
Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'records', true);
//MochiKit.Logging.logDebug(">>> Record.saveChanges");
//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.saveChanges");
if (this.headerNotes() != null) {
this.setNotes(this.headerNotes());
}
this.syncDirectLoginReferenceValues();
this.currentVersion().createNewVersion();
result = {'records': [{}]};
deferredResult = new MochiKit.Async.Deferred();
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo');
deferredResult.addCallback(MochiKit.Base.method(this, 'updateKey'));
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData');
deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData'));
deferredResult.addCallback(function(aResult, res) {
aResult['user'] = res;
return aResult;
}, result);
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData');
deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData'));
deferredResult.addCallback(function(aResult, res) {
//# aResult['record'] = res;
aResult['records'][0]['record'] = res;
return aResult;
}, result);
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordVersions');
deferredResult.addCallback(MochiKit.Base.method(this.currentVersion(), 'encryptedData'));
deferredResult.addCallback(function(aResult, res) {
// aResult['currentRecordVersion'] = res;
aResult['records'][0]['currentRecordVersion'] = res;
return aResult;
}, result);
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData');
if (this.isBrandNew() == false) {
deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'updateData');
} else {
//# deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecord');
deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecords');
}
deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData'));
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_updatingInterface');
deferredResult.addCallback(MochiKit.Base.method(this, 'setIsBrandNew'), false);
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated');
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated');
deferredResult.callback();
return deferredResult;
},
*/
//-------------------------------------------------------------------------
'cancelChanges': function() {
//MochiKit.Logging.logDebug(">>> Record.cancelChanges");
//MochiKit.Logging.logDebug("--- Record.cancelChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData()));
if (this.isBrandNew()) {
this.user().removeRecord(this);
} else {
this.restoreValuesFromSnapshot(this.cachedData());
}
//MochiKit.Logging.logDebug("<<< Record.cancelChanges");
},
//-------------------------------------------------------------------------
'restoreValuesFromSnapshot': function(someSnapshotData) {
var snapshotData;
//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot");
snapshotData = Clipperz.Base.evalJSON(someSnapshotData);
//MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData (1): " + Clipperz.Base.serializeJSON(someSnapshotData));
this.setLabel(snapshotData['label']);
this.resetDirectLogins();
this.setShouldProcessData(true);
this.processData(snapshotData);
//MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - snapshotData: (2)" + Clipperz.Base.serializeJSON(snapshotData));
this.resetRemovedDirectLogins();
{
var currentSnapshot;
var comparisonResult;
currentSnapshot = this.currentDataSnapshot();
//MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - 1");
//console.log("snapshot data: %o", someSnapshotData.currentVersion);
//console.log("current data: %o", currentSnapshot.currentVersion);
//MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData: " + Clipperz.Base.serializeJSON(someSnapshotData.currentVersion));
//MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - currentSnapshot: " + Clipperz.Base.serializeJSON(currentSnapshot.currentVersion));
comparisonResult = MochiKit.Base.compare(someSnapshotData.currentVersion, currentSnapshot.currentVersion);
//MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - " + comparisonResult);
}
//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot");
},
//-------------------------------------------------------------------------
__syntaxFix__: "syntax fix"
});
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, {
'maxNumberOfRecords': function() {
return this._maxNumberOfRecords;
},
'setMaxNumberOfRecords': function(aValue) {
this._maxNumberOfRecords = aValue;
},
//-------------------------------------------------------------------------
'errorHandler': function(anErrorString, anException) {
MochiKit.Logging.logError("- User.errorHandler: " + anErrorString + " (" + anException + ")");
},
//-------------------------------------------------------------------------
'connectionVersion': function() {
return this._connectionVersion;
},
'setConnectionVersion': function(aValue) {
this._connectionVersion = aValue;
},
//-------------------------------------------------------------------------
'connection': function() {
if ((this._connection == null) && (this.connectionVersion() != null) ){
this._connection = new Clipperz.PM.Crypto.communicationProtocol.versions[this.connectionVersion()]({user:this});
}
return this._connection;
},
'resetConnection': function(aValue) {
this._connection = null;
},
//=========================================================================
'register': function(anInvitationCode) {
var deferredResult;
var prng;
//MochiKit.Logging.logError(">>> User.register: " + this);
prng = Clipperz.Crypto.PRNG.defaultRandomGenerator();
deferredResult = new MochiKit.Async.Deferred()
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 1: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(prng, 'deferredEntropyCollection'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 2: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this.header(), 'updateAllSections'), anInvitationCode);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 2.1: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'register'), anInvitationCode);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.register - 3: " + res); return res;});
deferredResult.callback();
//MochiKit.Logging.logError("<<< User.register");
return deferredResult;
},
//=========================================================================
'connect': function(aValue) {
var deferredResult;
var prng;
prng = Clipperz.Crypto.PRNG.defaultRandomGenerator();
//MochiKit.Logging.logDebug(">>> User.connect");
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.1 - User.connect - 1: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(prng, 'deferredEntropyCollection'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.2 - User.connect - 2: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'login'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.3 - User.connect - 3: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
// TODO: add an addErrback call here to manage a wrong login. Any error after this point is due to some other causes.
// possibly the same exact 'handleConnectionFallback use at the end of this same method.
if (this.connectionVersion() != 'current') {
var currentConnection;
currentVersionConnection = new Clipperz.PM.Crypto.communicationProtocol.versions['current']({user:this});
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.4 - User.connect - 4: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_upgrading');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.5 - User.connect - 5: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'upgradeUserCredentials', currentVersionConnection.serverSideUserCredentials());
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.6 - User.connect - 6: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
}
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.7 - User.connect - 7: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'userConnected', null);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.8 - User.connect - 8: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.addErrback(MochiKit.Base.method(this, 'handleConnectionFallback'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.9 - User.connect - 9: "/* + res*/); return res;});
//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
deferredResult.callback(aValue);
//MochiKit.Logging.logDebug("<<< User.connect");
return deferredResult;
},
//.........................................................................
'handleConnectionFallback': function(aValue) {
var result;
//MochiKit.Logging.logDebug(">>> User.handleConnectionFallback");
if (aValue instanceof MochiKit.Async.CancelledError) {
//MochiKit.Logging.logDebug("--- User.handleConnectionFallback - operation cancelled");
result = aValue;
} else {
//MochiKit.Logging.logDebug("--- User.handleConnectionFallback - an ERROR has occurred - " + aValue);
this.resetConnection();
this.setConnectionVersion(Clipperz.PM.Crypto.communicationProtocol.fallbackVersions[this.connectionVersion()]);
if (this.connectionVersion() != null) {
result = new MochiKit.Async.Deferred();
result.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_tryOlderSchema');
result.addCallback(MochiKit.Base.method(this, 'connect'));
result.callback();
} else {
result = MochiKit.Async.fail(Clipperz.PM.DataModel.User.exception.LoginFailed);
}
}
//MochiKit.Logging.logDebug("<<< User.handleConnectionFallback");
return result;
},
//=========================================================================
'header': function() {
if (this._header == null) {
this._header = new Clipperz.PM.DataModel.Header({user:this});
}
return this._header;
},
//-------------------------------------------------------------------------
'statistics': function() {
if (this._statistics == null) {
this._statistics = new Clipperz.PM.DataModel.Statistics({user:this});
}
return this._statistics;
},
//-------------------------------------------------------------------------
'records': function() {
return this._records;
},
//.........................................................................
'addRecord': function(aValue, isBatchUpdate) {
this.records()[aValue.reference()] = aValue;
if (isBatchUpdate != true) {
Clipperz.NotificationCenter.notify(aValue, 'recordAdded', null, true);
Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true);
}
},
//-----------------------------------------------------------------------------
'addNewRecord': function() {
var record;
//MochiKit.Logging.logDebug(">>> User.addNewRecord");
record = new Clipperz.PM.DataModel.Record({user:this});
this.addRecord(record);
Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true);
//MochiKit.Logging.logDebug("<<< User.addNewRecord");
return record;
},
//-------------------------------------------------------------------------
- 'saveRecords': function(someRecords, aMethodName) {
+ 'saveRecords': function(someRecords /*, aMethodName*/) {
var deferredResult;
- var methodName;
+// var methodName;
var result;
var i,c;
//console.log("User.saveRecords - someRecords", someRecords);
- methodName = aMethodName || 'addNewRecords';
+// methodName = aMethodName || 'addNewRecords';
Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true);
//MochiKit.Logging.logDebug(">>> User.saveRecords");
//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] User.saveRecords");
/*
MochiKit.Logging.logDebug("--- User.saveRecords - 1");
MochiKit.Iter.forEach(someRecords, function(aRecord) {
if (aRecord.headerNotes() != null) {
aRecord.setNotes(aRecord.headerNotes());
}
aRecord.syncDirectLoginReferenceValues();
aRecord.currentVersion().createNewVersion();
aRecord.updateKey();
});
MochiKit.Logging.logDebug("--- User.saveRecords - 2");
*/
result = {'records': []};
deferredResult = new MochiKit.Async.Deferred();
c = someRecords.length;
for (i=0; i<c; i++) {
deferredResult.addCallback(function(aRecord) {
if (aRecord.headerNotes() != null) {
aRecord.setNotes(aRecord.headerNotes());
}
aRecord.syncDirectLoginReferenceValues();
aRecord.currentVersion().createNewVersion();
aRecord.updateKey();
}, someRecords[i]);
deferredResult.addCallback(MochiKit.Async.wait, 0.1);
}
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 1 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 2 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 3 " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 4 " + res); return res;});
deferredResult.addCallback(function(aResult, res) {
aResult['user'] = res;
return aResult;
}, result);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 5 " + res); return res;});
c = someRecords.length;
for (i=0; i<c; i++) {
var recordData;
recordData = {};
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.1 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.2 " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.3 " + res); return res;});
deferredResult.addCallback(function(aResult, res) {
aResult['record'] = res;
return aResult;
}, recordData);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.4 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {} /*'saveCard_encryptRecordVersions'*/);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.5 " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(someRecords[i].currentVersion(), 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.6 " + res); return res;});
deferredResult.addCallback(function(aResult, res) {
aResult['currentRecordVersion'] = res;
return aResult;
}, recordData);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.7 " + res); return res;});
deferredResult.addCallback(function(aResult, res) {
- aResult['records'].push(res);
+ aResult['records'] = { 'updated': [res] };
return aResult;
}, result);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 6.8 " + res); return res;});
}
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 7 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 8 " + res); return res;});
- deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), methodName);
+// deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), methodName);
+ deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'saveChanges');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9 " + res); return res;});
for (i=0; i<c; i++) {
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.1 " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'takeSnapshotOfCurrentData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.2 " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(someRecords[i], 'setIsBrandNew'), false);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 9.3 " + res); return res;});
}
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 10 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 11 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.saveRecords - 12 " + res); return res;});
deferredResult.callback();
return deferredResult;
},
//-------------------------------------------------------------------------
'removeRecord': function(aRecord) {
//MochiKit.Logging.logDebug(">>> User.removeRecord");
delete this.records()[aRecord.reference()];
//MochiKit.Logging.logDebug("--- User.removeRecord - 1");
Clipperz.NotificationCenter.notify(aRecord, 'recordRemoved', null, false);
Clipperz.NotificationCenter.notify(this, 'updatedSection', 'records', true);
//MochiKit.Logging.logDebug("<<< User.removeRecord");
},
//-------------------------------------------------------------------------
'deleteRecordsAction': function(someRecords) {
var deferredResult;
var parameters;
//MochiKit.Logging.logDebug(">>> User.deleteRecordsAction - someRecords.length: " + someRecords.length);
parameters = {};
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 1 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_collectData');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 2 " + res); return res;});
deferredResult.addCallback(function(someParameters, someRecords) {
var recordReferences;
recordReferences = MochiKit.Base.map(function(aRecord) {
var result;
result = aRecord.reference();
aRecord.remove();
return result;
}, someRecords);
- someParameters.recordReferences = recordReferences;
+// someParameters.recordReferences = recordReferences;
+ someParameters['records'] = { 'deleted': recordReferences};
return someParameters;
}, parameters);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 3 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_encryptData');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 4 " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 5 " + res); return res;});
deferredResult.addCallback(function(someParameters, anUserEncryptedData) {
someParameters.user = anUserEncryptedData;
return someParameters;
}, parameters);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 6 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_sendingData');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecords parameters: " + Clipperz.Base.serializeJSON(res)); return res;});
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 7 " + res); return res;});
- deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'deleteRecords');
+// deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'deleteRecords');
+ deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'saveChanges');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 8 " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'deleteRecord_updatingInterface');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.deleteRecordsAction - 9 " + res); return res;});
deferredResult.callback(someRecords);
//MochiKit.Logging.logDebug("<<< User.deleteRecordsAction");
return deferredResult;
},
//-------------------------------------------------------------------------
'resetAllLocalData': function() {
this.resetConnection();
this.setUsername("");
this.setPassphrase("");
this._header = null;
this._statistics = null;
this._preferences = null;
this._records = {};
this._directLoginReferences = {};
},
//-------------------------------------------------------------------------
'deleteAccountAction': function() {
var deferredResult;
//MochiKit.Logging.logDebug(">>> user.deleteAccountAction - " + this);
deferredResult = new MochiKit.Async.Deferred();
deferredResult.addCallback(MochiKit.Base.method(this.connection(), 'message'), 'deleteUser');
deferredResult.addCallback(MochiKit.Base.method(this, 'resetAllLocalData'));
deferredResult.callback();
//MochiKit.Logging.logDebug("<<< user.deleteAccountAction - " + this);
return deferredResult;
},
//-------------------------------------------------------------------------
'encryptedData': function() {
var deferredResult;
var result;
result = {};
deferredResult = new MochiKit.Async.Deferred();
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 0: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this.header(), 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 1: " + res); return res;});
deferredResult.addCallback(function(aResult, aValue) {
aResult['header'] = aValue;
}, result);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 2: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this.statistics(), 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 3: " + res); return res;});
deferredResult.addCallback(function(aResult, aValue) {
aResult['statistics'] = aValue;
}, result);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 4: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.bind(function(aResult, aValue) {
aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion;
aResult['lock'] = this.lock();
return aResult;
}, this), result);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.encryptedData - 5: " + res); return res;});
deferredResult.callback();
return deferredResult;
},
//-------------------------------------------------------------------------
'preferences': function() {
if (this._preferences == null) {
this._preferences = new Clipperz.PM.DataModel.UserPreferences({user:this});
}
return this._preferences;
},
/*
'setPreferences': function(aValue) {
this._preferences = aValue;
if (this._preferences.preferredLanguage() != null) {
Clipperz.PM.Strings.Languages.setSelectedLanguage(this._preferences.preferredLanguage());
} else {
//MochiKit.Logging.logDebug("### keepping the browser selected language: " + Clipperz.PM.Strings.selectedLanguage);
}
},
*/
//-------------------------------------------------------------------------
'oneTimePasswordManager': function() {
if (this._oneTimePasswordManager == null) {
this._oneTimePasswordManager = new Clipperz.PM.DataModel.OneTimePasswordManager(this, null);
}
return this._oneTimePasswordManager;
},
//-------------------------------------------------------------------------
'directLoginReferences': function() {
return this._directLoginReferences;
},
'addDirectLoginReference': function(aDirectLoginReference, isBatchUpdate) {
//MochiKit.Logging.logDebug(">>> User.addDirectLoginReference");
this.directLoginReferences()[aDirectLoginReference.reference()] = aDirectLoginReference;
if (isBatchUpdate != true) {
Clipperz.NotificationCenter.notify(aDirectLoginReference, 'directLoginAdded');
Clipperz.NotificationCenter.notify(this, 'updatedSection', 'directLogins', true);
}
},
'removeDirectLoginReference': function(aDirectLoginReference) {
delete this.directLoginReferences()[aDirectLoginReference.reference()];
Clipperz.NotificationCenter.notify(aDirectLoginReference, 'directLoginRemoved');
Clipperz.NotificationCenter.notify(this, 'updatedSection', 'directLogins', true);
},
//.........................................................................
'addDirectLogin': function(aDirectLogin) {
var newDirectLoginReference;
newDirectLoginReference = new Clipperz.PM.DataModel.DirectLoginReference({user:this, directLogin:aDirectLogin})
this.addDirectLoginReference(newDirectLoginReference);
},
'synchronizeDirectLogin': function(aDirectLogin) {
var directLoginReference;
directLoginReference = this.directLoginReferences()[aDirectLogin.reference()];
if (typeof(directLoginReference) != 'undefined') {
directLoginReference.synchronizeValues(aDirectLogin);
} else {
this.addDirectLogin(aDirectLogin);
}
},
'removeDirectLogin': function(aDirectLogin) {
this.removeDirectLoginReference(aDirectLogin);
},
//-------------------------------------------------------------------------
'changeCredentials': function(aUsername, aPassphrase) {
var deferredResult;
var result;
result = {};
deferredResult = new MochiKit.Async.Deferred();
deferredResult.addCallback(MochiKit.Base.method(this.header(), 'loadAllSections'));
deferredResult.addCallback(MochiKit.Base.method(this.header(), 'updateAllSections'));
deferredResult.addCallback(MochiKit.Base.bind(function(aUsername, aPssphrase) {
this.setUsername(aUsername);
this.setPassphrase(aPassphrase);
}, this), aUsername, aPassphrase)
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 1: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'changeCredentials_encryptingData');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 2: " + res); return res;});
deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData'));
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 3: " + res); return res;});
deferredResult.addCallback(function(aResult, anEncryptedData) {
aResult['user'] = anEncryptedData;
return aResult;
}, result);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 4: " + res); return res;});
deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'changeCredentials_creatingNewCredentials');
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 5: " + res); return res;});
deferredResult.addCallback(function(aResult, anUser) {
var newConnection;
newConnection = new Clipperz.PM.Crypto.communicationProtocol.versions[Clipperz.PM.Crypto.communicationProtocol.currentVersion]({user:anUser})
aResult['credentials'] = newConnection.serverSideUserCredentials();
return aResult;
}, result, this);
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("User.changeCredentials - 6: " + res); return res;});