Adapt frontend for CSRF in import dialog

This commit is contained in:
Antonin Delpeuch 2019-10-15 12:04:17 +01:00
parent 91cead27f8
commit f7177e670d
2 changed files with 25 additions and 5 deletions

View File

@ -37,6 +37,26 @@ var Refine = {
actionAreas: [] actionAreas: []
}; };
Refine.wrapCSRF = function(onCSRF) {
$.get(
"command/core/get-csrf-token",
{},
function(response) {
onCSRF(response['token']);
},
"json"
);
};
Refine.postCSRF = function(url, data, success, dataType) {
Refine.wrapCSRF(function(token) {
var fullData = data || {};
data['csrf_token'] = token;
$.post(url, fulldata, success, dataType);
});
};
var lang = (navigator.language|| navigator.userLanguage).split("-")[0]; var lang = (navigator.language|| navigator.userLanguage).split("-")[0];
var dictionary = ""; var dictionary = "";
$.ajax({ $.ajax({

View File

@ -187,7 +187,7 @@ Refine.DefaultImportingController.prototype._ensureFormatParserUIHasInitializati
$.post( $.post(
"command/core/importing-controller?" + $.param({ "command/core/importing-controller?" + $.param({
"controller": "core/default-importing-controller", "controller": "core/default-importing-controller",
"jobID": this._jobID, "jobID": self._jobID,
"subCommand": "initialize-parser-ui", "subCommand": "initialize-parser-ui",
"format": format, "format": format,
"csrf_token": token "csrf_token": token
@ -219,12 +219,12 @@ Refine.DefaultImportingController.prototype.updateFormatAndOptions = function(op
$.post( $.post(
"command/core/importing-controller?" + $.param({ "command/core/importing-controller?" + $.param({
"controller": "core/default-importing-controller", "controller": "core/default-importing-controller",
"jobID": this._jobID, "jobID": self._jobID,
"subCommand": "update-format-and-options", "subCommand": "update-format-and-options",
"csrf_token": token "csrf_token": token
}), }),
{ {
"format" : this._format, "format" : self._format,
"options" : JSON.stringify(options) "options" : JSON.stringify(options)
}, },
function(o) { function(o) {
@ -297,12 +297,12 @@ Refine.DefaultImportingController.prototype._createProject = function() {
$.post( $.post(
"command/core/importing-controller?" + $.param({ "command/core/importing-controller?" + $.param({
"controller": "core/default-importing-controller", "controller": "core/default-importing-controller",
"jobID": this._jobID, "jobID": self._jobID,
"subCommand": "create-project", "subCommand": "create-project",
"csrf_token": token "csrf_token": token
}), }),
{ {
"format" : this._format, "format" : self._format,
"options" : JSON.stringify(options) "options" : JSON.stringify(options)
}, },
function(o) { function(o) {