mirror of
https://github.com/zulip/zulip.git
synced 2025-10-30 19:43:47 +00:00
This commit was originally automatically generated using `tools/lint --only=eslint --fix`. It was then modified by tabbott to contain only changes to a set of files that are unlikely to result in significant merge conflicts with any open pull request, excluding about 20 files. His plan is to merge the remaining changes with more precise care, potentially involving merging parts of conflicting pull requests before running the `eslint --fix` operation. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
25 lines
728 B
JavaScript
25 lines
728 B
JavaScript
let csrf_token;
|
|
$(function () {
|
|
// This requires that we used Jinja2's {% csrf_input %} somewhere on the page.
|
|
const csrf_input = $('input[name="csrfmiddlewaretoken"]');
|
|
if (csrf_input.length > 0) {
|
|
csrf_token = csrf_input.attr('value');
|
|
} else {
|
|
csrf_token = undefined;
|
|
}
|
|
window.csrf_token = csrf_token;
|
|
|
|
if (csrf_token === undefined) {
|
|
return;
|
|
}
|
|
|
|
$.ajaxSetup({
|
|
beforeSend: function (xhr, settings) {
|
|
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
|
// Only send the token to relative URLs i.e. locally.
|
|
xhr.setRequestHeader("X-CSRFToken", csrf_token);
|
|
}
|
|
},
|
|
});
|
|
});
|