aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-09-03 08:34:57 +0200
committerGitHub <noreply@github.com>2020-09-03 08:34:57 +0200
commit43582975dcef7ba0a47d740f29f925d02a067849 (patch)
treea3c2d9ba99a5e29bba39f0d74427789b85344d3e
parent0e60b7f1741c35b68a37e0705521669e1191774e (diff)
parentcd10bc23e79c68d7a017e9284f95a166ea66ea08 (diff)
downloadShaarli-43582975dcef7ba0a47d740f29f925d02a067849.tar.gz
Shaarli-43582975dcef7ba0a47d740f29f925d02a067849.tar.zst
Shaarli-43582975dcef7ba0a47d740f29f925d02a067849.zip
Merge pull request #1535 from ArthurHoaro/fix/export-token
Export: refresh CRSF token after submit
-rw-r--r--assets/default/js/base.js19
1 files changed, 16 insertions, 3 deletions
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index 0f29799d..27938823 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -25,16 +25,18 @@ function findParent(element, tagName, attributes) {
25/** 25/**
26 * Ajax request to refresh the CSRF token. 26 * Ajax request to refresh the CSRF token.
27 */ 27 */
28function refreshToken(basePath) { 28function refreshToken(basePath, callback) {
29 console.log('refresh');
30 const xhr = new XMLHttpRequest(); 29 const xhr = new XMLHttpRequest();
31 xhr.open('GET', `${basePath}/admin/token`); 30 xhr.open('GET', `${basePath}/admin/token`);
32 xhr.onload = () => { 31 xhr.onload = () => {
33 const elements = document.querySelectorAll('input[name="token"]'); 32 const elements = document.querySelectorAll('input[name="token"]');
34 [...elements].forEach((element) => { 33 [...elements].forEach((element) => {
35 console.log(element);
36 element.setAttribute('value', xhr.responseText); 34 element.setAttribute('value', xhr.responseText);
37 }); 35 });
36
37 if (callback) {
38 callback(xhr.response);
39 }
38 }; 40 };
39 xhr.send(); 41 xhr.send();
40} 42}
@@ -622,4 +624,15 @@ function init(description) {
622 [...autocompleteFields].forEach((autocompleteField) => { 624 [...autocompleteFields].forEach((autocompleteField) => {
623 awesomepletes.push(createAwesompleteInstance(autocompleteField)); 625 awesomepletes.push(createAwesompleteInstance(autocompleteField));
624 }); 626 });
627
628 const exportForm = document.querySelector('#exportform');
629 if (exportForm != null) {
630 exportForm.addEventListener('submit', (event) => {
631 event.preventDefault();
632
633 refreshToken(basePath, () => {
634 event.target.submit();
635 });
636 });
637 }
625})(); 638})();