Commit 9fc4ddfd authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_officejs: Handle ERP5 redirection when getting 401 code in a jIO request

parent 6b85d617
...@@ -12,22 +12,36 @@ ...@@ -12,22 +12,36 @@
return storage[method_name].apply(storage, argument_list) return storage[method_name].apply(storage, argument_list)
.push(undefined, function (error) { .push(undefined, function (error) {
if ((error.target !== undefined) && (error.target.status === 401)) { if ((error.target !== undefined) && (error.target.status === 401)) {
var regexp,
site,
auth_page;
if (gadget.state_parameter_dict.jio_storage_name === "ERP5") { if (gadget.state_parameter_dict.jio_storage_name === "ERP5") {
return gadget.redirect({ page: "login" }); regexp = /^X-Delegate uri=\"(http[s]?:\/\/[\/\-\[\]{}()*+=:?&.,\\\^$|#\s\w%]+)\"$/;
auth_page = error.target.getResponseHeader('WWW-Authenticate');
if (regexp.test(auth_page)) {
site = UriTemplate.parse(
regexp.exec(auth_page)[1]
).expand({
came_from: window.location.href,
cors_origin: window.location.origin,
});
}
} }
if (gadget.state_parameter_dict.jio_storage_name === "DAV") { if (gadget.state_parameter_dict.jio_storage_name === "DAV") {
var regexp = /^Nayookie login_url=(http[s]?:\/\/[\/\-\[\]{}()*+=:?&.,\\\^$|#\s\w%]+)$/, regexp = /^Nayookie login_url=(http[s]?:\/\/[\/\-\[\]{}()*+=:?&.,\\\^$|#\s\w%]+)$/;
auth_page = error.target.getResponseHeader('WWW-Authenticate'), auth_page = error.target.getResponseHeader('WWW-Authenticate');
site;
if (regexp.test(auth_page)) { if (regexp.test(auth_page)) {
site = UriTemplate.parse( site = UriTemplate.parse(
regexp.exec(auth_page)[1] regexp.exec(auth_page)[1]
).expand({back_url: window.location.href, ).expand({
origin: window.location.protocol + '//' + back_url: window.location.href,
window.location.host}); origin: window.location.origin,
return gadget.redirect({ toExternal: true, url: site}); });
} }
} }
if (site) {
return gadget.redirect({ toExternal: true, url: site});
}
} }
throw error; throw error;
}); });
......
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