mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 08:09:33 +08:00
Revert "DEV: resets csrf ajax prefilter only if present (#7747)"
This reverts commit 6612218a4e
.
This commit is contained in:
parent
61b587f66e
commit
dc15486f0a
|
@ -1,29 +1,16 @@
|
||||||
// Append our CSRF token to AJAX requests when necessary.
|
// Append our CSRF token to AJAX requests when necessary.
|
||||||
let _crsfCallbacks;
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "csrf-token",
|
name: "csrf-token",
|
||||||
|
initialize: function(container) {
|
||||||
initialize(container) {
|
var session = container.lookup("session:main");
|
||||||
const session = container.lookup("session:main");
|
|
||||||
_crsfCallbacks = $.Callbacks();
|
|
||||||
|
|
||||||
// Add a CSRF token to all AJAX requests
|
// Add a CSRF token to all AJAX requests
|
||||||
session.set("csrfToken", $("meta[name=csrf-token]").attr("content"));
|
session.set("csrfToken", $("meta[name=csrf-token]").attr("content"));
|
||||||
|
|
||||||
_crsfCallbacks.add(function(options, originalOptions, xhr) {
|
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
||||||
if (!options.crossDomain) {
|
if (!options.crossDomain) {
|
||||||
xhr.setRequestHeader("X-CSRF-Token", session.csrfToken);
|
xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.ajaxPrefilter(_crsfCallbacks);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function resetCsrfCallbacks() {
|
|
||||||
if (_crsfCallbacks) {
|
|
||||||
_crsfCallbacks.empty();
|
|
||||||
_crsfCallbacks = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { resetDecorators } from "discourse/widgets/widget";
|
||||||
import { resetDecorators as resetPostCookedDecorators } from "discourse/widgets/post-cooked";
|
import { resetDecorators as resetPostCookedDecorators } from "discourse/widgets/post-cooked";
|
||||||
import { resetCache as resetOneboxCache } from "pretty-text/oneboxer";
|
import { resetCache as resetOneboxCache } from "pretty-text/oneboxer";
|
||||||
import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";
|
import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";
|
||||||
import { resetCsrfCallbacks } from "discourse/initializers/csrf-token";
|
|
||||||
|
|
||||||
export function currentUser() {
|
export function currentUser() {
|
||||||
return Discourse.User.create(
|
return Discourse.User.create(
|
||||||
|
@ -129,7 +128,6 @@ export function acceptance(name, options) {
|
||||||
resetPostCookedDecorators();
|
resetPostCookedDecorators();
|
||||||
resetOneboxCache();
|
resetOneboxCache();
|
||||||
resetCustomPostMessageCallbacks();
|
resetCustomPostMessageCallbacks();
|
||||||
resetCsrfCallbacks();
|
|
||||||
Discourse.reset();
|
Discourse.reset();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user