summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/User.js
Side-by-side diff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/User.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/User.js24
1 files changed, 10 insertions, 14 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.js
index 646ce21..fd18faf 100644
--- a/frontend/gamma/js/Clipperz/PM/DataModel/User.js
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.js
@@ -1,70 +1,68 @@
/*
-Copyright 2008-2011 Clipperz Srl
+Copyright 2008-2013 Clipperz Srl
-This file is part of Clipperz Community Edition.
-Clipperz Community Edition is an online password manager.
+This file is part of Clipperz, the online password manager.
For further information about its features and functionalities please
refer to http://www.clipperz.com.
-* Clipperz Community Edition is free software: you can redistribute
- it and/or modify it under the terms of the GNU Affero General Public
- License as published by the Free Software Foundation, either version
- 3 of the License, or (at your option) any later version.
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
-* Clipperz Community Edition is distributed in the hope that it will
- be useful, but WITHOUT ANY WARRANTY; without even the implied
- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
- License along with Clipperz Community Edition. If not, see
- <http://www.gnu.org/licenses/>.
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
*/
if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
//#############################################################################
Clipperz.PM.DataModel.User = function (args) {
args = args || {};
Clipperz.PM.DataModel.User.superclass.constructor.apply(this, arguments);
this._username = args.username || null;
this._getPassphraseFunction = args.getPassphraseFunction || null;
this._data = null;
this._connection = null;
this._connectionVersion = 'current';
this._serverData = null;
// this._serverLockValue = null;
this._transientState = null;
this._deferredLocks = {
'passphrase': new MochiKit.Async.DeferredLock(),
'serverData': new MochiKit.Async.DeferredLock(),
// 'recordsIndex': new MochiKit.Async.DeferredLock(),
// 'directLoginsIndex': new MochiKit.Async.DeferredLock()
// 'preferences': new MochiKit.Async.DeferredLock()
// 'oneTimePasswords': new MochiKit.Async.DeferredLock()
'__syntaxFix__': 'syntax fix'
};
return this;
}
Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, {
'toString': function () {
return "Clipperz.PM.DataModel.User - " + this.username();
},
//-------------------------------------------------------------------------
@@ -283,186 +281,184 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, {
return result;
},
//-------------------------------------------------------------------------
'lock': function () {
return Clipperz.Async.callbacks("User.lock", [
MochiKit.Base.method(this, 'deleteAllCleanTextData')
], {trace:false});
},
//-------------------------------------------------------------------------
'logout': function () {
return Clipperz.Async.callbacks("User.logout", [
MochiKit.Base.method(this, 'deleteAllCleanTextData'),
MochiKit.Base.method(this.connection(), 'logout')
], {trace:false});
},
//-------------------------------------------------------------------------
'headerFormatVersion': function(anHeader) {
var result;
if (anHeader.charAt(0) == '{') {
var headerData;
headerData = Clipperz.Base.evalJSON(anHeader);
result = headerData['version'];
} else {
result = 'LEGACY';
}
return result;
},
//-------------------------------------------------------------------------
'unpackServerData': function (someServerData) {
var unpackedData;
var headerVersion;
var recordsIndex;
var preferences;
var oneTimePasswords;
-//console.log(">>> ***************** user.unpackServerData", someServerData);
// this.setServerLockValue(someServerData['lock']);
headerVersion = this.headerFormatVersion(someServerData['header']);
switch (headerVersion) {
case 'LEGACY':
var legacyHeader;
legacyHeader = new Clipperz.PM.DataModel.User.Header.Legacy({
'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'),
'remoteData': {
'data': someServerData['header'],
'version': someServerData['version'],
'recordsStats': someServerData['recordsStats']
},
// 'encryptedDataKeypath': 'data',
// 'encryptedVersionKeypath': 'version',
'retrieveRecordDetailFunction': MochiKit.Base.method(this, 'getRecordDetail')
});
recordsIndex = legacyHeader;
preferences = legacyHeader;
oneTimePasswords = legacyHeader;
break;
case '0.1':
var headerData;
headerData = Clipperz.Base.evalJSON(someServerData['header']);
recordsIndex = new Clipperz.PM.DataModel.User.Header.RecordIndex({
'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'),
'recordsData': headerData['records'],
'recordsStats': someServerData['recordsStats'],
'directLoginsData': headerData['directLogins'],
'encryptedDataVersion': someServerData['version'],
'retrieveRecordDetailFunction': MochiKit.Base.method(this, 'getRecordDetail')
});
// Still missing a test case that actually fais with the old version of the code, where the check for undefined was missing
if (typeof(headerData['preferences']) != 'undefined') {
preferences = new Clipperz.PM.DataModel.User.Header.Preferences({
'name': 'preferences',
'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'),
'remoteData': {
'data': headerData['preferences']['data'],
'version': someServerData['version']
}
});
} else {
preferences = new Clipperz.PM.DataModel.User.Header.Preferences({
'name': 'preferences',
'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase')
});
}
if (typeof(headerData['oneTimePasswords']) != 'undefined') {
oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({
'name': 'preferences',
'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'),
'remoteData': {
'data': headerData['oneTimePasswords']['data'],
'version': someServerData['version']
}
});
} else {
oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({
'name': 'preferences',
'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase')
});
}
break;
}
unpackedData = {
'version': someServerData['version'],
'statistics': someServerData['statistics'],
'header': {
'data': someServerData['header'],
'version': headerVersion,
'recordsIndex': recordsIndex,
'preferences': preferences,
'oneTimePasswords': oneTimePasswords
}
};
this._serverData = unpackedData;
-//console.log("<<< ***************** user.unpackServerData", this._serverData);
return this._serverData;
},
//-------------------------------------------------------------------------
'getServerData': function() {
var deferredResult;
deferredResult = new Clipperz.Async.Deferred("User.getServerData", {trace:false});
deferredResult.acquireLock(this.deferredLockForSection('serverData'));
deferredResult.addCallback(MochiKit.Base.bind(function(aResult) {
var innerDeferredResult;
innerDeferredResult = new Clipperz.Async.Deferred("User.getUserDetails.innerDeferred", {trace:false});
if (this._serverData == null) {
innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadingUserDetails');
innerDeferredResult.addMethod(this.connection(), 'message', 'getUserDetails');
innerDeferredResult.addMethod(this, 'unpackServerData');
innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadedUserDetails');
}
innerDeferredResult.addCallback(MochiKit.Base.bind(function () {
return this._serverData;
},this));
innerDeferredResult.callback();
return innerDeferredResult;
}, this));
deferredResult.releaseLock(this.deferredLockForSection('serverData'));
deferredResult.callback();
return deferredResult;
},
//-------------------------------------------------------------------------
'connectionVersion': function() {
return this._connectionVersion;
},
'setConnectionVersion': function(aValue) {
if (this._connectionVersion != aValue) {
this.resetConnection();
}
this._connectionVersion = aValue;
},