Merge pull request #1535 from ArthurHoaro/fix/export-token
Export: refresh CRSF token after submit
This commit is contained in:
commit
43582975dc
1 changed files with 16 additions and 3 deletions
|
@ -25,16 +25,18 @@ function findParent(element, tagName, attributes) {
|
||||||
/**
|
/**
|
||||||
* Ajax request to refresh the CSRF token.
|
* Ajax request to refresh the CSRF token.
|
||||||
*/
|
*/
|
||||||
function refreshToken(basePath) {
|
function refreshToken(basePath, callback) {
|
||||||
console.log('refresh');
|
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', `${basePath}/admin/token`);
|
xhr.open('GET', `${basePath}/admin/token`);
|
||||||
xhr.onload = () => {
|
xhr.onload = () => {
|
||||||
const elements = document.querySelectorAll('input[name="token"]');
|
const elements = document.querySelectorAll('input[name="token"]');
|
||||||
[...elements].forEach((element) => {
|
[...elements].forEach((element) => {
|
||||||
console.log(element);
|
|
||||||
element.setAttribute('value', xhr.responseText);
|
element.setAttribute('value', xhr.responseText);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback(xhr.response);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
@ -622,4 +624,15 @@ function init(description) {
|
||||||
[...autocompleteFields].forEach((autocompleteField) => {
|
[...autocompleteFields].forEach((autocompleteField) => {
|
||||||
awesomepletes.push(createAwesompleteInstance(autocompleteField));
|
awesomepletes.push(createAwesompleteInstance(autocompleteField));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const exportForm = document.querySelector('#exportform');
|
||||||
|
if (exportForm != null) {
|
||||||
|
exportForm.addEventListener('submit', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
refreshToken(basePath, () => {
|
||||||
|
event.target.submit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue