author | Giulio 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) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js | 267 |
1 files changed, 267 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js b/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js new file mode 100644 index 0000000..e534435 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js | |||
@@ -0,0 +1,267 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer 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 | |||
29 | Clipperz.Base.module('Clipperz.PM.UI.Common.Controllers'); | ||
30 | |||
31 | Clipperz.PM.UI.Common.Controllers.DirectLoginRunner = function(args) { | ||
32 | this._directLogin = args['directLogin'] || Clipperz.Base.exception.raise('MandatoryParameter'); | ||
33 | this._target = Clipperz.PM.Crypto.randomKey(); | ||
34 | |||
35 | return this; | ||
36 | } | ||
37 | |||
38 | MochiKit.Base.update(Clipperz.PM.UI.Common.Controllers.DirectLoginRunner.prototype, { | ||
39 | |||
40 | 'toString': function() { | ||
41 | return "Clipperz.PM.UI.Common.Controllers.DirectLoginRunner"; | ||
42 | }, | ||
43 | |||
44 | //----------------------------------------------------------------------------- | ||
45 | |||
46 | 'directLogin': function () { | ||
47 | return this._directLogin; | ||
48 | }, | ||
49 | |||
50 | //----------------------------------------------------------------------------- | ||
51 | |||
52 | 'target': function () { | ||
53 | return this._target; | ||
54 | }, | ||
55 | |||
56 | //============================================================================= | ||
57 | |||
58 | 'setWindowTitle': function (aWindow, aTitle) { | ||
59 | aWindow.document.title = aTitle; | ||
60 | }, | ||
61 | |||
62 | 'setWindowBody': function (aWindow, anHTML) { | ||
63 | aWindow.document.body.innerHTML = anHTML; | ||
64 | }, | ||
65 | |||
66 | //============================================================================= | ||
67 | |||
68 | 'initialWindowSetup': function (aWindow) { | ||
69 | this.setWindowTitle(aWindow, "Loading Clipperz Direct Login"); | ||
70 | this.setWindowBody (aWindow, MochiKit.DOM.toHTML(MochiKit.DOM.H3("Loading Clipperz Direct Login ..."))); | ||
71 | }, | ||
72 | |||
73 | //----------------------------------------------------------------------------- | ||
74 | |||
75 | 'updateWindowWithDirectLoginLabel': function (aWindow, aLabel) { | ||
76 | var titleText; | ||
77 | var bodyText; | ||
78 | |||
79 | titleText = "Loading '__label__' Direct Login".replace(/__label__/, aLabel) | ||
80 | bodyText = "Loading '__label__' Direct Login... ".replace(/__label__/, aLabel) | ||
81 | |||
82 | this.setWindowTitle(aWindow, titleText); | ||
83 | this.setWindowBody (aWindow, MochiKit.DOM.toHTML(MochiKit.DOM.H3(bodyText))); | ||
84 | }, | ||
85 | |||
86 | //----------------------------------------------------------------------------- | ||
87 | |||
88 | 'updateWindowWithHTMLContent': function (aWindow, anHtml) { | ||
89 | this.setWindowBody(aWindow, anHtml); | ||
90 | }, | ||
91 | |||
92 | //============================================================================= | ||
93 | |||
94 | 'submitLoginForm': function(aWindow, aSubmitFunction) { | ||
95 | MochiKit.DOM.withWindow(aWindow, MochiKit.Base.bind(function () { | ||
96 | var formElement; | ||
97 | var submitButtons; | ||
98 | |||
99 | formElement = MochiKit.DOM.getElement('directLoginForm'); | ||
100 | |||
101 | submitButtons = MochiKit.Base.filter(function(anInputElement) { | ||
102 | return ((anInputElement.tagName.toLowerCase() == 'input') && (anInputElement.getAttribute('type').toLowerCase() == 'submit')); | ||
103 | }, formElement.elements); | ||
104 | |||
105 | if (submitButtons.length == 0) { | ||
106 | if (typeof(formElement.submit) == 'function') { | ||
107 | formElement.submit(); | ||
108 | } else { | ||
109 | aSubmitFunction.apply(formElement); | ||
110 | } | ||
111 | /* | ||
112 | varformSubmitFunction; | ||
113 | |||
114 | formSubmitFunction = MochiKit.Base.method(formElement, 'submit'); | ||
115 | if (Clipperz_IEisBroken == true) { | ||
116 | formElement.submit(); | ||
117 | } else { | ||
118 | formSubmitFunction(); | ||
119 | } | ||
120 | */ | ||
121 | } else { | ||
122 | submitButtons[0].click(); | ||
123 | } | ||
124 | }, this)); | ||
125 | }, | ||
126 | |||
127 | //------------------------------------------------------------------------- | ||
128 | |||
129 | 'runSubmitFormDirectLogin': function (aWindow, someAttributes) { | ||
130 | var html; | ||
131 | var formElement; | ||
132 | var submitFunction; | ||
133 | |||
134 | formElement = MochiKit.DOM.FORM({ | ||
135 | 'id':'directLoginForm', | ||
136 | 'method':someAttributes['formAttributes']['method'], | ||
137 | 'action':someAttributes['formAttributes']['action'] | ||
138 | }); | ||
139 | |||
140 | submitFunction = formElement.submit; | ||
141 | |||
142 | MochiKit.DOM.appendChildNodes(formElement, MochiKit.Base.map(function (anInputAttributes) { | ||
143 | return MochiKit.DOM.INPUT({'type':'hidden', 'name':anInputAttributes[0], 'value':anInputAttributes[1]}); | ||
144 | }, MochiKit.Base.items(someAttributes['inputValues']))); | ||
145 | |||
146 | html =''; | ||
147 | html += '<h3>Loading ' + someAttributes['label'] + ' ...</h3>'; | ||
148 | html +=MochiKit.DOM.appendChildNodes(MochiKit.DOM.DIV(), MochiKit.DOM.appendChildNodes(MochiKit.DOM.DIV({style:'display:none; visibility:hidden;'}), formElement)).innerHTML; | ||
149 | |||
150 | this.updateWindowWithHTMLContent(aWindow, html); | ||
151 | this.submitLoginForm(aWindow, submitFunction); | ||
152 | }, | ||
153 | |||
154 | //------------------------------------------------------------------------- | ||
155 | |||
156 | 'runHttpAuthDirectLogin': function(aWindow, someAttributes) { | ||
157 | var completeUrl; | ||
158 | var url; | ||
159 | |||
160 | //console.log("runHttpAuthDirectLogin", someAttributes); | ||
161 | url = someAttributes['inputValues']['url']; | ||
162 | |||
163 | if (/^https?\:\/\//.test(url) == false) { | ||
164 | url = 'http://' + url; | ||
165 | } | ||
166 | |||
167 | if (Clipperz_IEisBroken === true) { | ||
168 | completeUrl = url; | ||
169 | } else { | ||
170 | var username; | ||
171 | var password; | ||
172 | |||
173 | username = someAttributes['inputValues']['username']; | ||
174 | password = someAttributes['inputValues']['password']; | ||
175 | /(^https?\:\/\/)?(.*)/.test(url); | ||
176 | |||
177 | completeUrl = RegExp.$1 + username + ':' + password + '@' + RegExp.$2; | ||
178 | } | ||
179 | |||
180 | window.open(completeUrl, this.target()); | ||
181 | }, | ||
182 | |||
183 | //============================================================================= | ||
184 | |||
185 | 'runDirectLogin': function (aWindow) { | ||
186 | var deferredResult; | ||
187 | |||
188 | //console.log(">>> runDirectLogin"); | ||
189 | deferredResult = new Clipperz.Async.Deferred("DirectLoginRunner.openDirectLogin", {trace:false}); | ||
190 | deferredResult.addMethod(this, 'initialWindowSetup', aWindow); | ||
191 | deferredResult.addMethod(this.directLogin(), 'label'); | ||
192 | deferredResult.addMethod(this, 'updateWindowWithDirectLoginLabel', aWindow); | ||
193 | deferredResult.collectResults({ | ||
194 | 'type': MochiKit.Base.method(this.directLogin(), 'type'), | ||
195 | 'label': MochiKit.Base.method(this.directLogin(), 'label'), | ||
196 | 'formAttributes':MochiKit.Base.method(this.directLogin(), 'formAttributes'), | ||
197 | 'inputValues': MochiKit.Base.method(this.directLogin(), 'inputValues') | ||
198 | }); | ||
199 | //deferredResult.addCallback(function (aValue) { console.log("SOME ATTRIBUTES", aValue); return aValue; }); | ||
200 | deferredResult.addCallback(MochiKit.Base.bind(function (someAttributes) { | ||
201 | //console.log("SOME ATTRIBUTES", someAttributes); | ||
202 | switch (someAttributes['type']) { | ||
203 | case 'http_auth': | ||
204 | this.runHttpAuthDirectLogin(aWindow, someAttributes); | ||
205 | break; | ||
206 | case 'simple_url': | ||
207 | this.runSimpleUrlDirectLogin(aWindow, someAttributes); | ||
208 | break; | ||
209 | default: | ||
210 | this.runSubmitFormDirectLogin(aWindow, someAttributes); | ||
211 | break; | ||
212 | } | ||
213 | }, this)); | ||
214 | deferredResult.callback(); | ||
215 | //console.log("<<< runDirectLogin"); | ||
216 | |||
217 | return deferredResult; | ||
218 | }, | ||
219 | |||
220 | //============================================================================= | ||
221 | |||
222 | 'run': function () { | ||
223 | var newWindow; | ||
224 | |||
225 | newWindow = window.open(Clipperz.PM.Strings.getValue('directLoginJumpPageUrl'), this.target()); | ||
226 | |||
227 | return this.runDirectLogin(newWindow); | ||
228 | }, | ||
229 | |||
230 | //============================================================================= | ||
231 | |||
232 | 'test': function () { | ||
233 | var iFrame; | ||
234 | var newWindow; | ||
235 | |||
236 | iFrame = MochiKit.DOM.createDOM('iframe'); | ||
237 | MochiKit.DOM.appendChildNodes(MochiKit.DOM.currentDocument().body, iFrame); | ||
238 | |||
239 | newWindow = iFrame.contentWindow; | ||
240 | |||
241 | return this.runDirectLogin(newWindow); | ||
242 | }, | ||
243 | |||
244 | //============================================================================= | ||
245 | __syntaxFix__: "syntax fix" | ||
246 | }); | ||
247 | |||
248 | //----------------------------------------------------------------------------- | ||
249 | |||
250 | Clipperz.PM.UI.Common.Controllers.DirectLoginRunner.openDirectLogin = function (aDirectLogin) { | ||
251 | varrunner; | ||
252 | |||
253 | runner = new Clipperz.PM.UI.Common.Controllers.DirectLoginRunner({directLogin:aDirectLogin}); | ||
254 | return runner.run(); | ||
255 | }; | ||
256 | |||
257 | //----------------------------------------------------------------------------- | ||
258 | |||
259 | Clipperz.PM.UI.Common.Controllers.DirectLoginRunner.testDirectLogin = function (aDirectLogin) { | ||
260 | varrunner; | ||
261 | |||
262 | //console.log(">>>>>> TESTING DIRECT LOGIN"); | ||
263 | runner = new Clipperz.PM.UI.Common.Controllers.DirectLoginRunner({directLogin:aDirectLogin}); | ||
264 | return runner.test(); | ||
265 | }; | ||
266 | |||
267 | //----------------------------------------------------------------------------- | ||