author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-08-30 15:56:53 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-08-30 21:23:42 (UTC) |
commit | 20bea94ab6b91c85b171dcf86baba0a64169d508 (patch) (unidiff) | |
tree | 6e38e91498dcdb861620eba1e237d1026fe79cc5 /frontend/delta/js/Clipperz/PM/UI/DirectLoginController.js | |
parent | bde3c7b98523112ade9c5bbf7390c4ecb494cd2e (diff) | |
download | clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.zip clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.tar.gz clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.tar.bz2 |
First release of /delta version
Diffstat (limited to 'frontend/delta/js/Clipperz/PM/UI/DirectLoginController.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/delta/js/Clipperz/PM/UI/DirectLoginController.js | 256 |
1 files changed, 256 insertions, 0 deletions
diff --git a/frontend/delta/js/Clipperz/PM/UI/DirectLoginController.js b/frontend/delta/js/Clipperz/PM/UI/DirectLoginController.js new file mode 100644 index 0000000..d9dfe6d --- a/dev/null +++ b/frontend/delta/js/Clipperz/PM/UI/DirectLoginController.js | |||
@@ -0,0 +1,256 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | Clipperz.Base.module('Clipperz.PM.UI'); | ||
25 | |||
26 | Clipperz.PM.UI.DirectLoginRunner = function(args) { | ||
27 | this._directLogin = args['directLogin'] || Clipperz.Base.exception.raise('MandatoryParameter'); | ||
28 | this._target = Clipperz.PM.Crypto.randomKey(); | ||
29 | |||
30 | return this; | ||
31 | } | ||
32 | |||
33 | MochiKit.Base.update(Clipperz.PM.UI.DirectLoginRunner.prototype, { | ||
34 | |||
35 | 'toString': function() { | ||
36 | return "Clipperz.PM.UI.DirectLoginRunner"; | ||
37 | }, | ||
38 | |||
39 | //----------------------------------------------------------------------------- | ||
40 | |||
41 | 'directLogin': function () { | ||
42 | return this._directLogin; | ||
43 | }, | ||
44 | |||
45 | //----------------------------------------------------------------------------- | ||
46 | |||
47 | 'target': function () { | ||
48 | return this._target; | ||
49 | }, | ||
50 | |||
51 | //============================================================================= | ||
52 | |||
53 | 'setWindowTitle': function (aWindow, aTitle) { | ||
54 | aWindow.document.title = aTitle; | ||
55 | }, | ||
56 | |||
57 | 'setWindowBody': function (aWindow, anHTML) { | ||
58 | aWindow.document.body.innerHTML = anHTML; | ||
59 | }, | ||
60 | |||
61 | //============================================================================= | ||
62 | |||
63 | 'initialWindowSetup': function (aWindow) { | ||
64 | this.setWindowTitle(aWindow, "Loading Clipperz Direct Login"); | ||
65 | this.setWindowBody (aWindow, MochiKit.DOM.toHTML(MochiKit.DOM.H3("Loading Clipperz Direct Login ..."))); | ||
66 | }, | ||
67 | |||
68 | //----------------------------------------------------------------------------- | ||
69 | |||
70 | 'updateWindowWithDirectLoginLabel': function (aWindow, aLabel) { | ||
71 | var titleText; | ||
72 | var bodyText; | ||
73 | |||
74 | titleText = "Loading '__label__' Direct Login".replace(/__label__/, aLabel) | ||
75 | bodyText = "Loading '__label__' Direct Login... ".replace(/__label__/, aLabel) | ||
76 | |||
77 | this.setWindowTitle(aWindow, titleText); | ||
78 | this.setWindowBody (aWindow, MochiKit.DOM.toHTML(MochiKit.DOM.H3(bodyText))); | ||
79 | }, | ||
80 | |||
81 | //----------------------------------------------------------------------------- | ||
82 | |||
83 | 'updateWindowWithHTMLContent': function (aWindow, anHtml) { | ||
84 | this.setWindowBody(aWindow, anHtml); | ||
85 | }, | ||
86 | |||
87 | //============================================================================= | ||
88 | |||
89 | 'submitLoginForm': function(aWindow, aSubmitFunction) { | ||
90 | MochiKit.DOM.withWindow(aWindow, MochiKit.Base.bind(function () { | ||
91 | var formElement; | ||
92 | var submitButtons; | ||
93 | |||
94 | formElement = MochiKit.DOM.getElement('directLoginForm'); | ||
95 | |||
96 | submitButtons = MochiKit.Base.filter(function(anInputElement) { | ||
97 | return ((anInputElement.tagName.toLowerCase() == 'input') && (anInputElement.getAttribute('type').toLowerCase() == 'submit')); | ||
98 | }, formElement.elements); | ||
99 | |||
100 | if (submitButtons.length == 0) { | ||
101 | if (typeof(formElement.submit) == 'function') { | ||
102 | formElement.submit(); | ||
103 | } else { | ||
104 | aSubmitFunction.apply(formElement); | ||
105 | } | ||
106 | /* | ||
107 | varformSubmitFunction; | ||
108 | |||
109 | formSubmitFunction = MochiKit.Base.method(formElement, 'submit'); | ||
110 | if (Clipperz_IEisBroken == true) { | ||
111 | formElement.submit(); | ||
112 | } else { | ||
113 | formSubmitFunction(); | ||
114 | } | ||
115 | */ | ||
116 | } else { | ||
117 | submitButtons[0].click(); | ||
118 | } | ||
119 | }, this)); | ||
120 | }, | ||
121 | |||
122 | //------------------------------------------------------------------------- | ||
123 | |||
124 | 'runSubmitFormDirectLogin': function (aWindow, someAttributes) { | ||
125 | var html; | ||
126 | var formElement; | ||
127 | var submitFunction; | ||
128 | |||
129 | formElement = MochiKit.DOM.FORM({ | ||
130 | 'id':'directLoginForm', | ||
131 | 'method':someAttributes['formAttributes']['method'], | ||
132 | 'action':someAttributes['formAttributes']['action'] | ||
133 | }); | ||
134 | |||
135 | submitFunction = formElement.submit; | ||
136 | |||
137 | MochiKit.DOM.appendChildNodes(formElement, MochiKit.Base.map(function (anInputAttributes) { | ||
138 | return MochiKit.DOM.INPUT({'type':'hidden', 'name':anInputAttributes[0], 'value':anInputAttributes[1]}); | ||
139 | }, MochiKit.Base.items(someAttributes['inputValues']))); | ||
140 | |||
141 | html =''; | ||
142 | html += '<h3>Loading ' + someAttributes['label'] + ' ...</h3>'; | ||
143 | html +=MochiKit.DOM.appendChildNodes(MochiKit.DOM.DIV(), MochiKit.DOM.appendChildNodes(MochiKit.DOM.DIV({style:'display:none; visibility:hidden;'}), formElement)).innerHTML; | ||
144 | |||
145 | this.updateWindowWithHTMLContent(aWindow, html); | ||
146 | this.submitLoginForm(aWindow, submitFunction); | ||
147 | }, | ||
148 | |||
149 | //------------------------------------------------------------------------- | ||
150 | |||
151 | 'runHttpAuthDirectLogin': function(aWindow, someAttributes) { | ||
152 | var completeUrl; | ||
153 | var url; | ||
154 | |||
155 | url = someAttributes['inputValues']['url']; | ||
156 | |||
157 | if (/^https?\:\/\//.test(url) == false) { | ||
158 | url = 'http://' + url; | ||
159 | } | ||
160 | |||
161 | if (Clipperz_IEisBroken === true) { | ||
162 | completeUrl = url; | ||
163 | } else { | ||
164 | var username; | ||
165 | var password; | ||
166 | |||
167 | username = someAttributes['inputValues']['username']; | ||
168 | password = someAttributes['inputValues']['password']; | ||
169 | /(^https?\:\/\/)?(.*)/.test(url); | ||
170 | |||
171 | completeUrl = RegExp.$1 + username + ':' + password + '@' + RegExp.$2; | ||
172 | } | ||
173 | |||
174 | window.open(completeUrl, this.target()); | ||
175 | }, | ||
176 | |||
177 | //============================================================================= | ||
178 | |||
179 | 'runDirectLogin': function (aWindow) { | ||
180 | var deferredResult; | ||
181 | |||
182 | deferredResult = new Clipperz.Async.Deferred("DirectLoginRunner.openDirectLogin", {trace:false}); | ||
183 | deferredResult.addMethod(this, 'initialWindowSetup', aWindow); | ||
184 | deferredResult.addMethod(this.directLogin(), 'label'); | ||
185 | deferredResult.addMethod(this, 'updateWindowWithDirectLoginLabel', aWindow); | ||
186 | deferredResult.collectResults({ | ||
187 | 'type': MochiKit.Base.method(this.directLogin(), 'type'), | ||
188 | 'label': MochiKit.Base.method(this.directLogin(), 'label'), | ||
189 | 'formAttributes':MochiKit.Base.method(this.directLogin(), 'formAttributes'), | ||
190 | 'inputValues': MochiKit.Base.method(this.directLogin(), 'inputValues') | ||
191 | }); | ||
192 | deferredResult.addCallback(MochiKit.Base.bind(function (someAttributes) { | ||
193 | switch (someAttributes['type']) { | ||
194 | case 'http_auth': | ||
195 | this.runHttpAuthDirectLogin(aWindow, someAttributes); | ||
196 | break; | ||
197 | case 'simple_url': | ||
198 | this.runSimpleUrlDirectLogin(aWindow, someAttributes); | ||
199 | break; | ||
200 | default: | ||
201 | this.runSubmitFormDirectLogin(aWindow, someAttributes); | ||
202 | break; | ||
203 | } | ||
204 | }, this)); | ||
205 | deferredResult.callback(); | ||
206 | |||
207 | return deferredResult; | ||
208 | }, | ||
209 | |||
210 | //============================================================================= | ||
211 | |||
212 | 'run': function () { | ||
213 | var newWindow; | ||
214 | |||
215 | newWindow = window.open(Clipperz.PM.Strings.getValue('directLoginJumpPageUrl'), this.target()); | ||
216 | |||
217 | return this.runDirectLogin(newWindow); | ||
218 | }, | ||
219 | |||
220 | //============================================================================= | ||
221 | |||
222 | 'test': function () { | ||
223 | var iFrame; | ||
224 | var newWindow; | ||
225 | |||
226 | iFrame = MochiKit.DOM.createDOM('iframe'); | ||
227 | MochiKit.DOM.appendChildNodes(MochiKit.DOM.currentDocument().body, iFrame); | ||
228 | |||
229 | newWindow = iFrame.contentWindow; | ||
230 | |||
231 | return this.runDirectLogin(newWindow); | ||
232 | }, | ||
233 | |||
234 | //============================================================================= | ||
235 | __syntaxFix__: "syntax fix" | ||
236 | }); | ||
237 | |||
238 | //----------------------------------------------------------------------------- | ||
239 | |||
240 | Clipperz.PM.UI.DirectLoginRunner.openDirectLogin = function (aDirectLogin) { | ||
241 | varrunner; | ||
242 | |||
243 | runner = new Clipperz.PM.UI.DirectLoginRunner({directLogin:aDirectLogin}); | ||
244 | return runner.run(); | ||
245 | }; | ||
246 | |||
247 | //----------------------------------------------------------------------------- | ||
248 | |||
249 | Clipperz.PM.UI.DirectLoginRunner.testDirectLogin = function (aDirectLogin) { | ||
250 | varrunner; | ||
251 | |||
252 | runner = new Clipperz.PM.UI.DirectLoginRunner({directLogin:aDirectLogin}); | ||
253 | return runner.test(); | ||
254 | }; | ||
255 | |||
256 | //----------------------------------------------------------------------------- | ||