Commit 976ca8a4 authored by Aurelien Vermylen's avatar Aurelien Vermylen

Make credentials possible in ERP5Storage for nodejs use.

parent d1895b24
...@@ -11368,7 +11368,7 @@ return new Parser; ...@@ -11368,7 +11368,7 @@ return new Parser;
/*jslint nomen: true, unparam: true */ /*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob, /*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery*/ SimpleQuery, ComplexQuery, btoa*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob, (function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) { SimpleQuery, ComplexQuery) {
...@@ -11381,8 +11381,9 @@ return new Parser; ...@@ -11381,8 +11381,9 @@ return new Parser;
"type": "GET", "type": "GET",
"url": storage._url, "url": storage._url,
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (event) { .push(function (event) {
...@@ -11407,8 +11408,9 @@ return new Parser; ...@@ -11407,8 +11408,9 @@ return new Parser;
view: options._view view: options._view
}), }),
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
...@@ -11506,6 +11508,13 @@ return new Parser; ...@@ -11506,6 +11508,13 @@ return new Parser;
} }
this._url = spec.url; this._url = spec.url;
this._default_view_reference = spec.default_view_reference; this._default_view_reference = spec.default_view_reference;
this._headers = {};
this._withCredentials = true;
if (spec.login !== undefined && spec.password !== undefined) {
this._headers = {"Authorization": "Basic "
+ btoa(spec.login + ":" + spec.password)};
this._withCredentials = false;
}
} }
function convertJSONToGet(json) { function convertJSONToGet(json) {
...@@ -11543,8 +11552,9 @@ return new Parser; ...@@ -11543,8 +11552,9 @@ return new Parser;
url: site_hal._actions.add.href, url: site_hal._actions.add.href,
data: form_data, data: form_data,
xhrFields: { xhrFields: {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (evt) { .push(function (evt) {
...@@ -11658,6 +11668,7 @@ return new Parser; ...@@ -11658,6 +11668,7 @@ return new Parser;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var start, var start,
k,
end, end,
range, range,
request_options = { request_options = {
...@@ -11665,7 +11676,7 @@ return new Parser; ...@@ -11665,7 +11676,7 @@ return new Parser;
"dataType": "blob", "dataType": "blob",
"url": action, "url": action,
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} }
}; };
if (options.start !== undefined || options.end !== undefined) { if (options.start !== undefined || options.end !== undefined) {
...@@ -11687,6 +11698,11 @@ return new Parser; ...@@ -11687,6 +11698,11 @@ return new Parser;
range = "bytes=" + start + "-" + end; range = "bytes=" + start + "-" + end;
} }
request_options.headers = {Range: range}; request_options.headers = {Range: range};
for (k in this._headers) {
if (this._headers.hasOwnProperty(k)) {
request_options.headers[k] = this._headers[k];
}
}
} }
return jIO.util.ajax(request_options); return jIO.util.ajax(request_options);
}) })
...@@ -11746,8 +11762,9 @@ return new Parser; ...@@ -11746,8 +11762,9 @@ return new Parser;
"data": data, "data": data,
"dataType": "blob", "dataType": "blob",
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}); });
}; };
...@@ -11864,8 +11881,9 @@ return new Parser; ...@@ -11864,8 +11881,9 @@ return new Parser;
local_roles: local_roles local_roles: local_roles
}), }),
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (response) { .push(function (response) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -4268,7 +4268,7 @@ return new Parser; ...@@ -4268,7 +4268,7 @@ return new Parser;
/*jslint nomen: true, unparam: true */ /*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob, /*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery*/ SimpleQuery, ComplexQuery, btoa*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob, (function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) { SimpleQuery, ComplexQuery) {
...@@ -4281,8 +4281,9 @@ return new Parser; ...@@ -4281,8 +4281,9 @@ return new Parser;
"type": "GET", "type": "GET",
"url": storage._url, "url": storage._url,
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (event) { .push(function (event) {
...@@ -4307,8 +4308,9 @@ return new Parser; ...@@ -4307,8 +4308,9 @@ return new Parser;
view: options._view view: options._view
}), }),
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
...@@ -4406,6 +4408,13 @@ return new Parser; ...@@ -4406,6 +4408,13 @@ return new Parser;
} }
this._url = spec.url; this._url = spec.url;
this._default_view_reference = spec.default_view_reference; this._default_view_reference = spec.default_view_reference;
this._headers = {};
this._withCredentials = true;
if (spec.login !== undefined && spec.password !== undefined) {
this._headers = {"Authorization": "Basic "
+ btoa(spec.login + ":" + spec.password)};
this._withCredentials = false;
}
} }
function convertJSONToGet(json) { function convertJSONToGet(json) {
...@@ -4443,8 +4452,9 @@ return new Parser; ...@@ -4443,8 +4452,9 @@ return new Parser;
url: site_hal._actions.add.href, url: site_hal._actions.add.href,
data: form_data, data: form_data,
xhrFields: { xhrFields: {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (evt) { .push(function (evt) {
...@@ -4558,6 +4568,7 @@ return new Parser; ...@@ -4558,6 +4568,7 @@ return new Parser;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var start, var start,
k,
end, end,
range, range,
request_options = { request_options = {
...@@ -4565,7 +4576,7 @@ return new Parser; ...@@ -4565,7 +4576,7 @@ return new Parser;
"dataType": "blob", "dataType": "blob",
"url": action, "url": action,
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} }
}; };
if (options.start !== undefined || options.end !== undefined) { if (options.start !== undefined || options.end !== undefined) {
...@@ -4587,6 +4598,11 @@ return new Parser; ...@@ -4587,6 +4598,11 @@ return new Parser;
range = "bytes=" + start + "-" + end; range = "bytes=" + start + "-" + end;
} }
request_options.headers = {Range: range}; request_options.headers = {Range: range};
for (k in this._headers) {
if (this._headers.hasOwnProperty(k)) {
request_options.headers[k] = this._headers[k];
}
}
} }
return jIO.util.ajax(request_options); return jIO.util.ajax(request_options);
}) })
...@@ -4646,8 +4662,9 @@ return new Parser; ...@@ -4646,8 +4662,9 @@ return new Parser;
"data": data, "data": data,
"dataType": "blob", "dataType": "blob",
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}); });
}; };
...@@ -4764,8 +4781,9 @@ return new Parser; ...@@ -4764,8 +4781,9 @@ return new Parser;
local_roles: local_roles local_roles: local_roles
}), }),
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (response) { .push(function (response) {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
/*jslint nomen: true, unparam: true */ /*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob, /*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery*/ SimpleQuery, ComplexQuery, btoa*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob, (function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) { SimpleQuery, ComplexQuery) {
...@@ -24,8 +24,9 @@ ...@@ -24,8 +24,9 @@
"type": "GET", "type": "GET",
"url": storage._url, "url": storage._url,
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (event) { .push(function (event) {
...@@ -50,8 +51,9 @@ ...@@ -50,8 +51,9 @@
view: options._view view: options._view
}), }),
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
...@@ -149,6 +151,13 @@ ...@@ -149,6 +151,13 @@
} }
this._url = spec.url; this._url = spec.url;
this._default_view_reference = spec.default_view_reference; this._default_view_reference = spec.default_view_reference;
this._headers = {};
this._withCredentials = true;
if (spec.login !== undefined && spec.password !== undefined) {
this._headers = {"Authorization": "Basic "
+ btoa(spec.login + ":" + spec.password)};
this._withCredentials = false;
}
} }
function convertJSONToGet(json) { function convertJSONToGet(json) {
...@@ -186,8 +195,9 @@ ...@@ -186,8 +195,9 @@
url: site_hal._actions.add.href, url: site_hal._actions.add.href,
data: form_data, data: form_data,
xhrFields: { xhrFields: {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (evt) { .push(function (evt) {
...@@ -301,6 +311,7 @@ ...@@ -301,6 +311,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var start, var start,
k,
end, end,
range, range,
request_options = { request_options = {
...@@ -308,7 +319,7 @@ ...@@ -308,7 +319,7 @@
"dataType": "blob", "dataType": "blob",
"url": action, "url": action,
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} }
}; };
if (options.start !== undefined || options.end !== undefined) { if (options.start !== undefined || options.end !== undefined) {
...@@ -330,6 +341,11 @@ ...@@ -330,6 +341,11 @@
range = "bytes=" + start + "-" + end; range = "bytes=" + start + "-" + end;
} }
request_options.headers = {Range: range}; request_options.headers = {Range: range};
for (k in this._headers) {
if (this._headers.hasOwnProperty(k)) {
request_options.headers[k] = this._headers[k];
}
}
} }
return jIO.util.ajax(request_options); return jIO.util.ajax(request_options);
}) })
...@@ -389,8 +405,9 @@ ...@@ -389,8 +405,9 @@
"data": data, "data": data,
"dataType": "blob", "dataType": "blob",
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}); });
}; };
...@@ -507,8 +524,9 @@ ...@@ -507,8 +524,9 @@
local_roles: local_roles local_roles: local_roles
}), }),
"xhrFields": { "xhrFields": {
withCredentials: true withCredentials: this._withCredentials
} },
"headers": this._headers
}); });
}) })
.push(function (response) { .push(function (response) {
......
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