summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
commitef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff)
treec403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
parent597ecfbc0249d83e1b856cbd558340c01237a360 (diff)
downloadclipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js280
1 files changed, 280 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js b/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
new file mode 100644
index 0000000..d90100a
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
@@ -0,0 +1,280 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
32
33
34//#############################################################################
35
36Clipperz.PM.DataModel.OneTimePasswordManager = function(anUser, args) {
37 args = args || {};
38
39 this._user = anUser;
40 this._oneTimePasswords = {};
41
42 this.updateWithData(args);
43
44 Clipperz.NotificationCenter.notify(null, 'oneTimePasswordAdded', null, true);
45
46 return this;
47}
48
49Clipperz.PM.DataModel.OneTimePasswordManager.prototype = MochiKit.Base.update(null, {
50
51 'toString': function() {
52 return "Clipperz.PM.DataModel.OneTimePasswordManager";
53 },
54
55 //-------------------------------------------------------------------------
56
57 'updateWithData': function(someValues) {
58 varotpReference;
59
60//console.log("OneTimePasswordManager.updateWithData", someValues);
61//MochiKit.Logging.logDebug("OneTimePasswordManager.updateWithData: " + Clipperz.Base.serializeJSON(someValues));
62 for (otpReference in someValues) {
63 var otp;
64 var otpConfiguration;
65
66 otpConfiguration = someValues[otpReference];
67 otpConfiguration['user'] = this.user();
68 otpConfiguration['reference'] = otpReference;
69 otp = new Clipperz.PM.DataModel.OneTimePassword(otpConfiguration);
70 this._oneTimePasswords[otpReference] = otp;
71 }
72
73 return this;
74 },
75
76 //-------------------------------------------------------------------------
77
78 'updateWithServerData': function(someValues) {
79 var deferredResult;
80 varoneTimePasswordReference;
81 var wereChangesApplied;
82
83//MochiKit.Logging.logDebug(">>> OneTimePasswordManager.updateWithServerData");
84 deferredResult = new MochiKit.Async.Deferred();
85 wereChangesApplied = false;
86
87 for (oneTimePasswordReference in someValues) {
88 var oneTimePassword;
89
90 oneTimePassword = this.oneTimePasswordWithReference(oneTimePasswordReference);
91 if (oneTimePassword != null) {
92 var oneTimePasswordHasBeenUpdated;
93
94 oneTimePasswordHasBeenUpdated = oneTimePassword.updateStatusWithValues(someValues[oneTimePasswordReference]);
95 wereChangesApplied = oneTimePasswordHasBeenUpdated || wereChangesApplied;
96 } else {
97
98 }
99 }
100
101 if (wereChangesApplied == true) {
102 this.user().header().markSectionAsUpdated('oneTimePasswords');
103 }
104
105 for (oneTimePasswordReference in this.oneTimePasswords()) {
106 if (typeof(someValues[oneTimePasswordReference]) == 'undefind') {
107 deferredResult.addCallback(MochiKit.Base.method(this.oneTimePasswordWithReference(oneTimePasswordReference), 'saveChanges'));
108 }
109 }
110
111 deferredResult.addCallback(MochiKit.Async.succeed, this);
112
113 deferredResult.callback();
114//MochiKit.Logging.logDebug("<<< OneTimePasswordManager.updateWithServerData");
115
116 return deferredResult;
117 },
118
119 //-------------------------------------------------------------------------
120
121 'user': function() {
122 return this._user;
123 },
124
125 //-------------------------------------------------------------------------
126
127 'addOneTimePassword': function(aOneTimePassword, isBatchUpdate) {
128 this.oneTimePasswords()[aOneTimePassword.reference()] = aOneTimePassword;
129
130 if (isBatchUpdate != true) {
131 Clipperz.NotificationCenter.notify(aOneTimePassword, 'oneTimePasswordAdded');
132 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true);
133 }
134 },
135
136 //-------------------------------------------------------------------------
137
138 'archiveOneTimePassword': function(aOneTimePasswordReference) {
139 var deferredResult;
140
141//MochiKit.Logging.logDebug(">>> OneTimePasswordManager.archiveOneTimePassword");
142//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 0 otp.reference: " + aOneTimePasswordReference);
143 deferredResult = new MochiKit.Async.Deferred();
144 deferredResult.addCallback(MochiKit.Base.method(this.user(), 'loadOneTimePasswords'));
145 deferredResult.addCallback(MochiKit.Base.bind(function(aOneTimePasswordReference) {
146 var oneTimePassword;
147
148//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 1 serializedData: " + Clipperz.Base.serializeJSON(this.serializedData()));
149 oneTimePassword = this.oneTimePasswords()[aOneTimePasswordReference];
150
151 if (oneTimePassword != null) {
152 oneTimePassword.setUsageDate(new Date());
153
154 // while (this.usedOneTimePasswords().length > 10) {
155 // var referenceOfOneTimePasswordToRemove;
156 //
157 // referenceOfOneTimePasswordToRemove = this.usedOneTimePasswords()[0];
158 // delete this.oneTimePasswords()[referenceOfOneTimePasswordToRemove];
159 // this.usedOneTimePasswords().shift();
160 // }
161
162 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true);
163 } else {
164 MochiKit.Logging.logError("### OneTimePasswordManager.archiveOneTimePassword - the used OneTimePassword has not been found on the index-card. :-(");
165 }
166
167//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 2 serializedData: " + Clipperz.Base.serializeJSON(this.serializedData()));
168 }, this), aOneTimePasswordReference);
169 deferredResult.addCallback(MochiKit.Base.method(this, 'saveChanges'));
170 deferredResult.callback();
171//MochiKit.Logging.logDebug("<<< OneTimePasswordManager.archiveOneTimePassword");
172
173 return deferredResult;
174 },
175
176 //-------------------------------------------------------------------------
177
178 'serializedData': function() {
179 var result;
180 varkey;
181
182 result = {};
183
184 for (key in this.oneTimePasswords()) {
185 result[key] = this.oneTimePasswords()[key].serializedData();
186 }
187
188 return result;
189 },
190
191 //-------------------------------------------------------------------------
192
193 'oneTimePasswords': function() {
194 return this._oneTimePasswords;
195 },
196
197 //-------------------------------------------------------------------------
198
199 'oneTimePasswordWithReference': function(aOneTimePasswordReference) {
200 return this.oneTimePasswords()[aOneTimePasswordReference];
201 },
202
203 //-------------------------------------------------------------------------
204
205 'deleteOneTimePasswordWithReference': function(aOneTimePasswordReference) {
206 delete(this.oneTimePasswords()[aOneTimePasswordReference]);
207 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true);
208 },
209
210 //-------------------------------------------------------------------------
211
212 'encryptedData': function() {
213 var deferredResult;
214 var oneTimePasswordReferences;
215 var result;
216 var i, c;
217
218 result = {};
219 deferredResult = new MochiKit.Async.Deferred();
220 deferredResult.addCallback(MochiKit.Async.succeed);
221
222 oneTimePasswordReferences = MochiKit.Base.keys(this.oneTimePasswords());
223 c = oneTimePasswordReferences.length;
224 for (i=0; i<c; i++) {
225 var currentOneTimePassword;
226
227 currentOneTimePassword = this.oneTimePasswords()[oneTimePasswordReferences[i]];
228 deferredResult.addCallback(MochiKit.Base.method(currentOneTimePassword, 'encryptedPackedPassphrase'));
229 deferredResult.addCallback(function(aResult, aOneTimePasswordReference, anEncryptedPackedPassphrase) {
230 aResult[aOneTimePasswordReference] = anEncryptedPackedPassphrase;
231 return aResult;
232 }, result, oneTimePasswordReferences[i]);
233 }
234//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePasswordManager.encryptedData: " + res); return res;});
235
236 deferredResult.callback(result);
237
238 return deferredResult;
239 },
240
241 //-------------------------------------------------------------------------
242
243 'saveChanges': function() {
244 var deferredResult;
245 varresult;
246
247//MochiKit.Logging.logDebug(">>> OneTimePasswordManager.saveChanges");
248 result = {};
249 deferredResult = new MochiKit.Async.Deferred();
250 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptUserData');
251 deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData'));
252 deferredResult.addCallback(function(aResult, res) {
253 aResult['user'] = res;
254 return aResult;
255 }, result);
256
257 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptOTPData');
258 deferredResult.addCallback(MochiKit.Base.bind(function(res) {
259 res['oneTimePasswords'] = MochiKit.Base.keys(this.oneTimePasswords());
260 return res;
261 }, this));
262
263 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_sendingData');
264//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePasswordManager.saveChanges - 1: " + Clipperz.Base.serializeJSON(res)); return res;});
265 deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'updateOneTimePasswords');
266
267 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_updatingInterface');
268//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePasswordManager.saveChanges - 2: " + res); return res;});
269 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'OTPUpdated');
270//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePasswordManager.saveChanges - 3: " + res); return res;});
271 deferredResult.callback();
272//MochiKit.Logging.logDebug("<<< OneTimePasswordManager.saveChanges");
273
274 return deferredResult;
275 },
276
277 //-------------------------------------------------------------------------
278 __syntaxFix__: "syntax fix"
279});
280