~sirodoht/mataroa

6993932b293fdf3044c857b4b8076e27f3679394 — Theodore Keloglou 25 days ago 63d995d
change csrf from django to a js variable
4 files changed, 1 insertions(+), 18 deletions(-)

M main/templates/main/page_form.html
M main/templates/main/post_form.html
M main/templates/partials/drag-and-drop-upload.js
D main/templates/partials/get-csrf.js
M main/templates/main/page_form.html => main/templates/main/page_form.html +0 -2
@@ 65,8 65,6 @@
    // when page loads, focus on title
    document.querySelector('input[name="title"]').focus();

    {% include "partials/get-csrf.js" %}

    {% include "partials/drag-and-drop-upload.js" %}
</script>
{% endblock %}

M main/templates/main/post_form.html => main/templates/main/post_form.html +0 -2
@@ 76,8 76,6 @@

{% block scripts %}
<script>
    {% include "partials/get-csrf.js" %}

    {% include "partials/drag-and-drop-upload.js" %}
    
    // add 'set to today' functionality on publication date

M main/templates/partials/drag-and-drop-upload.js => main/templates/partials/drag-and-drop-upload.js +1 -1
@@ 76,7 76,7 @@ bodyElem.addEventListener('drop', function (e) {
        };

        xhr.open('POST', '/images/?raw=true');
        xhr.setRequestHeader('X-CSRFToken', getCsrf());
        xhr.setRequestHeader('X-CSRFToken', {{csrf_token}});
        xhr.send(formData);
    }
});

D main/templates/partials/get-csrf.js => main/templates/partials/get-csrf.js +0 -13
@@ 1,13 0,0 @@
// get csrf token from django template variable
function getCsrf() {
    var inputElems = document.querySelectorAll('input');
    var csrfToken = '';
    var i = 0;
    for (i = 0; i < inputElems.length; i++) {
        if (inputElems[i].name === 'csrfmiddlewaretoken') {
            csrfToken = inputElems[i].value;
            break;
        }
    }
    return csrfToken;
}