summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
Unidiff
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.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js b/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
index aa40aba..1ebb615 100644
--- a/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
+++ b/frontend/beta/js/Clipperz/PM/DataModel/OneTimePasswordManager.js
@@ -1,214 +1,212 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
27if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } 25if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
28if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } 26if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
29 27
30 28
31//############################################################################# 29//#############################################################################
32 30
33Clipperz.PM.DataModel.OneTimePasswordManager = function(anUser, args) { 31Clipperz.PM.DataModel.OneTimePasswordManager = function(anUser, args) {
34 args = args || {}; 32 args = args || {};
35 33
36 this._user = anUser; 34 this._user = anUser;
37 this._oneTimePasswords = {}; 35 this._oneTimePasswords = {};
38 36
39 this.updateWithData(args); 37 this.updateWithData(args);
40 38
41 Clipperz.NotificationCenter.notify(null, 'oneTimePasswordAdded', null, true); 39 Clipperz.NotificationCenter.notify(null, 'oneTimePasswordAdded', null, true);
42 40
43 return this; 41 return this;
44} 42}
45 43
46Clipperz.PM.DataModel.OneTimePasswordManager.prototype = MochiKit.Base.update(null, { 44Clipperz.PM.DataModel.OneTimePasswordManager.prototype = MochiKit.Base.update(null, {
47 45
48 'toString': function() { 46 'toString': function() {
49 return "Clipperz.PM.DataModel.OneTimePasswordManager"; 47 return "Clipperz.PM.DataModel.OneTimePasswordManager";
50 }, 48 },
51 49
52 //------------------------------------------------------------------------- 50 //-------------------------------------------------------------------------
53 51
54 'updateWithData': function(someValues) { 52 'updateWithData': function(someValues) {
55 varotpReference; 53 varotpReference;
56 54
57//console.log("OneTimePasswordManager.updateWithData", someValues); 55//console.log("OneTimePasswordManager.updateWithData", someValues);
58//MochiKit.Logging.logDebug("OneTimePasswordManager.updateWithData: " + Clipperz.Base.serializeJSON(someValues)); 56//MochiKit.Logging.logDebug("OneTimePasswordManager.updateWithData: " + Clipperz.Base.serializeJSON(someValues));
59 for (otpReference in someValues) { 57 for (otpReference in someValues) {
60 var otp; 58 var otp;
61 var otpConfiguration; 59 var otpConfiguration;
62 60
63 otpConfiguration = someValues[otpReference]; 61 otpConfiguration = someValues[otpReference];
64 otpConfiguration['user'] = this.user(); 62 otpConfiguration['user'] = this.user();
65 otpConfiguration['reference'] = otpReference; 63 otpConfiguration['reference'] = otpReference;
66 otp = new Clipperz.PM.DataModel.OneTimePassword(otpConfiguration); 64 otp = new Clipperz.PM.DataModel.OneTimePassword(otpConfiguration);
67 this._oneTimePasswords[otpReference] = otp; 65 this._oneTimePasswords[otpReference] = otp;
68 } 66 }
69 67
70 return this; 68 return this;
71 }, 69 },
72 70
73 //------------------------------------------------------------------------- 71 //-------------------------------------------------------------------------
74 72
75 'updateWithServerData': function(someValues) { 73 'updateWithServerData': function(someValues) {
76 var deferredResult; 74 var deferredResult;
77 varoneTimePasswordReference; 75 varoneTimePasswordReference;
78 var wereChangesApplied; 76 var wereChangesApplied;
79 77
80//MochiKit.Logging.logDebug(">>> OneTimePasswordManager.updateWithServerData"); 78//MochiKit.Logging.logDebug(">>> OneTimePasswordManager.updateWithServerData");
81 deferredResult = new MochiKit.Async.Deferred(); 79 deferredResult = new MochiKit.Async.Deferred();
82 wereChangesApplied = false; 80 wereChangesApplied = false;
83 81
84 for (oneTimePasswordReference in someValues) { 82 for (oneTimePasswordReference in someValues) {
85 var oneTimePassword; 83 var oneTimePassword;
86 84
87 oneTimePassword = this.oneTimePasswordWithReference(oneTimePasswordReference); 85 oneTimePassword = this.oneTimePasswordWithReference(oneTimePasswordReference);
88 if (oneTimePassword != null) { 86 if (oneTimePassword != null) {
89 var oneTimePasswordHasBeenUpdated; 87 var oneTimePasswordHasBeenUpdated;
90 88
91 oneTimePasswordHasBeenUpdated = oneTimePassword.updateStatusWithValues(someValues[oneTimePasswordReference]); 89 oneTimePasswordHasBeenUpdated = oneTimePassword.updateStatusWithValues(someValues[oneTimePasswordReference]);
92 wereChangesApplied = oneTimePasswordHasBeenUpdated || wereChangesApplied; 90 wereChangesApplied = oneTimePasswordHasBeenUpdated || wereChangesApplied;
93 } else { 91 } else {
94 92
95 } 93 }
96 } 94 }
97 95
98 if (wereChangesApplied == true) { 96 if (wereChangesApplied == true) {
99 this.user().header().markSectionAsUpdated('oneTimePasswords'); 97 this.user().header().markSectionAsUpdated('oneTimePasswords');
100 } 98 }
101 99
102 for (oneTimePasswordReference in this.oneTimePasswords()) { 100 for (oneTimePasswordReference in this.oneTimePasswords()) {
103 if (typeof(someValues[oneTimePasswordReference]) == 'undefind') { 101 if (typeof(someValues[oneTimePasswordReference]) == 'undefind') {
104 deferredResult.addCallback(MochiKit.Base.method(this.oneTimePasswordWithReference(oneTimePasswordReference), 'saveChanges')); 102 deferredResult.addCallback(MochiKit.Base.method(this.oneTimePasswordWithReference(oneTimePasswordReference), 'saveChanges'));
105 } 103 }
106 } 104 }
107 105
108 deferredResult.addCallback(MochiKit.Async.succeed, this); 106 deferredResult.addCallback(MochiKit.Async.succeed, this);
109 107
110 deferredResult.callback(); 108 deferredResult.callback();
111//MochiKit.Logging.logDebug("<<< OneTimePasswordManager.updateWithServerData"); 109//MochiKit.Logging.logDebug("<<< OneTimePasswordManager.updateWithServerData");
112 110
113 return deferredResult; 111 return deferredResult;
114 }, 112 },
115 113
116 //------------------------------------------------------------------------- 114 //-------------------------------------------------------------------------
117 115
118 'user': function() { 116 'user': function() {
119 return this._user; 117 return this._user;
120 }, 118 },
121 119
122 //------------------------------------------------------------------------- 120 //-------------------------------------------------------------------------
123 121
124 'addOneTimePassword': function(aOneTimePassword, isBatchUpdate) { 122 'addOneTimePassword': function(aOneTimePassword, isBatchUpdate) {
125 this.oneTimePasswords()[aOneTimePassword.reference()] = aOneTimePassword; 123 this.oneTimePasswords()[aOneTimePassword.reference()] = aOneTimePassword;
126 124
127 if (isBatchUpdate != true) { 125 if (isBatchUpdate != true) {
128 Clipperz.NotificationCenter.notify(aOneTimePassword, 'oneTimePasswordAdded'); 126 Clipperz.NotificationCenter.notify(aOneTimePassword, 'oneTimePasswordAdded');
129 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true); 127 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true);
130 } 128 }
131 }, 129 },
132 130
133 //------------------------------------------------------------------------- 131 //-------------------------------------------------------------------------
134 132
135 'archiveOneTimePassword': function(aOneTimePasswordReference) { 133 'archiveOneTimePassword': function(aOneTimePasswordReference) {
136 var deferredResult; 134 var deferredResult;
137 135
138//MochiKit.Logging.logDebug(">>> OneTimePasswordManager.archiveOneTimePassword"); 136//MochiKit.Logging.logDebug(">>> OneTimePasswordManager.archiveOneTimePassword");
139//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 0 otp.reference: " + aOneTimePasswordReference); 137//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 0 otp.reference: " + aOneTimePasswordReference);
140 deferredResult = new MochiKit.Async.Deferred(); 138 deferredResult = new MochiKit.Async.Deferred();
141 deferredResult.addCallback(MochiKit.Base.method(this.user(), 'loadOneTimePasswords')); 139 deferredResult.addCallback(MochiKit.Base.method(this.user(), 'loadOneTimePasswords'));
142 deferredResult.addCallback(MochiKit.Base.bind(function(aOneTimePasswordReference) { 140 deferredResult.addCallback(MochiKit.Base.bind(function(aOneTimePasswordReference) {
143 var oneTimePassword; 141 var oneTimePassword;
144 142
145//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 1 serializedData: " + Clipperz.Base.serializeJSON(this.serializedData())); 143//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 1 serializedData: " + Clipperz.Base.serializeJSON(this.serializedData()));
146 oneTimePassword = this.oneTimePasswords()[aOneTimePasswordReference]; 144 oneTimePassword = this.oneTimePasswords()[aOneTimePasswordReference];
147 145
148 if (oneTimePassword != null) { 146 if (oneTimePassword != null) {
149 oneTimePassword.setUsageDate(new Date()); 147 oneTimePassword.setUsageDate(new Date());
150 148
151 // while (this.usedOneTimePasswords().length > 10) { 149 // while (this.usedOneTimePasswords().length > 10) {
152 // var referenceOfOneTimePasswordToRemove; 150 // var referenceOfOneTimePasswordToRemove;
153 // 151 //
154 // referenceOfOneTimePasswordToRemove = this.usedOneTimePasswords()[0]; 152 // referenceOfOneTimePasswordToRemove = this.usedOneTimePasswords()[0];
155 // delete this.oneTimePasswords()[referenceOfOneTimePasswordToRemove]; 153 // delete this.oneTimePasswords()[referenceOfOneTimePasswordToRemove];
156 // this.usedOneTimePasswords().shift(); 154 // this.usedOneTimePasswords().shift();
157 // } 155 // }
158 156
159 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true); 157 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true);
160 } else { 158 } else {
161 MochiKit.Logging.logError("### OneTimePasswordManager.archiveOneTimePassword - the used OneTimePassword has not been found on the index-card. :-("); 159 MochiKit.Logging.logError("### OneTimePasswordManager.archiveOneTimePassword - the used OneTimePassword has not been found on the index-card. :-(");
162 } 160 }
163 161
164//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 2 serializedData: " + Clipperz.Base.serializeJSON(this.serializedData())); 162//MochiKit.Logging.logDebug("--- OneTimePasswordManager.archiveOneTimePassword - 2 serializedData: " + Clipperz.Base.serializeJSON(this.serializedData()));
165 }, this), aOneTimePasswordReference); 163 }, this), aOneTimePasswordReference);
166 deferredResult.addCallback(MochiKit.Base.method(this, 'saveChanges')); 164 deferredResult.addCallback(MochiKit.Base.method(this, 'saveChanges'));
167 deferredResult.callback(); 165 deferredResult.callback();
168//MochiKit.Logging.logDebug("<<< OneTimePasswordManager.archiveOneTimePassword"); 166//MochiKit.Logging.logDebug("<<< OneTimePasswordManager.archiveOneTimePassword");
169 167
170 return deferredResult; 168 return deferredResult;
171 }, 169 },
172 170
173 //------------------------------------------------------------------------- 171 //-------------------------------------------------------------------------
174 172
175 'serializedData': function() { 173 'serializedData': function() {
176 var result; 174 var result;
177 varkey; 175 varkey;
178 176
179 result = {}; 177 result = {};
180 178
181 for (key in this.oneTimePasswords()) { 179 for (key in this.oneTimePasswords()) {
182 result[key] = this.oneTimePasswords()[key].serializedData(); 180 result[key] = this.oneTimePasswords()[key].serializedData();
183 } 181 }
184 182
185 return result; 183 return result;
186 }, 184 },
187 185
188 //------------------------------------------------------------------------- 186 //-------------------------------------------------------------------------
189 187
190 'oneTimePasswords': function() { 188 'oneTimePasswords': function() {
191 return this._oneTimePasswords; 189 return this._oneTimePasswords;
192 }, 190 },
193 191
194 //------------------------------------------------------------------------- 192 //-------------------------------------------------------------------------
195 193
196 'oneTimePasswordWithReference': function(aOneTimePasswordReference) { 194 'oneTimePasswordWithReference': function(aOneTimePasswordReference) {
197 return this.oneTimePasswords()[aOneTimePasswordReference]; 195 return this.oneTimePasswords()[aOneTimePasswordReference];
198 }, 196 },
199 197
200 //------------------------------------------------------------------------- 198 //-------------------------------------------------------------------------
201 199
202 'deleteOneTimePasswordWithReference': function(aOneTimePasswordReference) { 200 'deleteOneTimePasswordWithReference': function(aOneTimePasswordReference) {
203 delete(this.oneTimePasswords()[aOneTimePasswordReference]); 201 delete(this.oneTimePasswords()[aOneTimePasswordReference]);
204 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true); 202 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'oneTimePasswords', true);
205 }, 203 },
206 204
207 //------------------------------------------------------------------------- 205 //-------------------------------------------------------------------------
208 206
209 'encryptedData': function() { 207 'encryptedData': function() {
210 var deferredResult; 208 var deferredResult;
211 var oneTimePasswordReferences; 209 var oneTimePasswordReferences;
212 var result; 210 var result;
213 var i, c; 211 var i, c;
214 212