Commit 26c65447 authored by iv's avatar iv

OfficeJS: support cookie authentication based on the origin (used in flaskdav).

parent c9a17d6e
...@@ -101,10 +101,38 @@ ...@@ -101,10 +101,38 @@
<key> <string>text_content</string> </key> <key> <string>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
/*global window, rJS, jIO, FormData, XMLHttpRequestProgressEvent */\n /*global window, rJS, jIO, FormData, XMLHttpRequestProgressEvent, UriTemplate */\n
/*jslint indent: 2, maxerr: 3 */\n /*jslint indent: 2, maxerr: 3 */\n
(function (window, rJS, jIO) {\n (function (window, rJS, jIO) {\n
"use strict";\n "use strict";\n
\n
// jIO call wrapper for redirection to authentication page if needed\n
function wrapJioCall(gadget, method_name, argument_list) {\n
var storage = gadget.state_parameter_dict.jio_storage;\n
return storage[method_name].apply(storage, argument_list)\n
.push(undefined, function (error) {\n
if (error instanceof XMLHttpRequestProgressEvent &&\n
error.target.status === 401) {\n
if (gadget.state_parameter_dict.jio_storage_name === "ERP5") {\n
return gadget.redirect({ page: "login" });\n
}\n
if (gadget.state_parameter_dict.jio_storage_name === "DAV") {\n
var regexp = /^Nayookie login_url=(http[s]?:\\/\\/[\\/\\-\\[\\]{}()*+=:?&.,\\\\\\^$|#\\s\\w%]+)$/,\n
auth_page = error.target.getResponseHeader(\'WWW-Authenticate\'),\n
site;\n
if (regexp.test(auth_page)) {\n
site = UriTemplate.parse(\n
regexp.exec(auth_page)[1]\n
).expand({back_url: window.location.href,\n
origin: window.location.protocol + \'//\' +\n
window.location.host});\n
return gadget.redirect({ toExternal: true, url: site});\n
}\n
}\n
}\n
throw error;\n
});\n
}\n
\n \n
rJS(window)\n rJS(window)\n
\n \n
...@@ -137,57 +165,34 @@ ...@@ -137,57 +165,34 @@
});\n });\n
})\n })\n
.declareMethod(\'allDocs\', function () {\n .declareMethod(\'allDocs\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'allDocs\', arguments);\n
return storage.allDocs.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'allAttachments\', function () {\n .declareMethod(\'allAttachments\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'allAttachments\', arguments);\n
return storage.allAttachments.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'get\', function () {\n .declareMethod(\'get\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'get\', arguments);\n
return storage.get.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'put\', function () {\n .declareMethod(\'put\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'put\', arguments);\n
return storage.put.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'post\', function () {\n .declareMethod(\'post\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'post\', arguments);\n
return storage.post.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'remove\', function () {\n .declareMethod(\'remove\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'remove\', arguments);\n
return storage.remove.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'getAttachment\', function () {\n .declareMethod(\'getAttachment\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'gettAttachment\', arguments);\n
return storage.getAttachment.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'putAttachment\', function () {\n .declareMethod(\'putAttachment\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'putAttachment\', arguments);\n
return storage.putAttachment.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'removeAttachment\', function () {\n .declareMethod(\'removeAttachment\', function () {\n
var storage = this.state_parameter_dict.jio_storage;\n return wrapJioCall(this, \'removeAttachment\', arguments);\n
return storage.removeAttachment.apply(storage, arguments);\n
})\n })\n
.declareMethod(\'repair\', function () {\n .declareMethod(\'repair\', function () {\n
var gadget = this,\n return wrapJioCall(this, \'repair\', arguments);\n
storage = gadget.state_parameter_dict.jio_storage;\n
return storage.repair.apply(storage, arguments)\n
.push(undefined, function (error) {\n
if (error instanceof XMLHttpRequestProgressEvent &&\n
error.currentTarget.status === 401 &&\n
gadget.state_parameter_dict.jio_storage_name === "ERP5") {\n
return {\n
redirect: {\n
page: "login"\n
}\n
};\n
}\n
throw error;\n
});\n
});\n });\n
\n \n
}(window, rJS, jIO)); }(window, rJS, jIO));
...@@ -313,7 +318,7 @@ ...@@ -313,7 +318,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>cedric.le.ninivin</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -327,7 +332,7 @@ ...@@ -327,7 +332,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>945.63008.32756.3891</string> </value> <value> <string>947.54207.48571.57002</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -345,7 +350,7 @@ ...@@ -345,7 +350,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1443118127.75</float> <float>1450281591.67</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -144,7 +144,8 @@ ...@@ -144,7 +144,8 @@
type: "dav",\n type: "dav",\n
url: gadget.props.element.querySelector("input[name=\'dav_url\']").value,\n url: gadget.props.element.querySelector("input[name=\'dav_url\']").value,\n
basic_login: btoa(gadget.props.element.querySelector("input[name=\'dav_username\']").value\n basic_login: btoa(gadget.props.element.querySelector("input[name=\'dav_username\']").value\n
+ \':\' + gadget.props.element.querySelector("input[name=\'dav_password\']").value)\n + \':\' + gadget.props.element.querySelector("input[name=\'dav_password\']").value),\n
with_credentials: true\n
}\n }\n
}\n }\n
}\n }\n
...@@ -355,7 +356,7 @@ ...@@ -355,7 +356,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>946.59103.36885.15735</string> </value> <value> <string>947.53845.25131.55500</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -373,7 +374,7 @@ ...@@ -373,7 +374,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1446741080.69</float> <float>1450259852.52</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -173,6 +173,11 @@ ...@@ -173,6 +173,11 @@
})\n })\n
\n \n
.declareMethod(\'redirect\', function (options) {\n .declareMethod(\'redirect\', function (options) {\n
if (options !== undefined && options.toExternal) {\n
window.location.replace(options.url);\n
return RSVP.timeout(REDIRECT_TIMEOUT); // timeout if not redirected\n
}\n
else {\n
return this.getCommandUrlFor(options)\n return this.getCommandUrlFor(options)\n
.push(function (hash) {\n .push(function (hash) {\n
window.location.replace(hash);\n window.location.replace(hash);\n
...@@ -181,6 +186,7 @@ ...@@ -181,6 +186,7 @@
// fail if nothing happens\n // fail if nothing happens\n
return RSVP.timeout(REDIRECT_TIMEOUT);\n return RSVP.timeout(REDIRECT_TIMEOUT);\n
});\n });\n
}\n
})\n })\n
\n \n
.declareMethod(\'route\', function (options) {\n .declareMethod(\'route\', function (options) {\n
...@@ -374,7 +380,7 @@ ...@@ -374,7 +380,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>946.59105.23936.34252</string> </value> <value> <string>947.54085.31754.65399</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -392,7 +398,7 @@ ...@@ -392,7 +398,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1446740807.62</float> <float>1450274255.9</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment