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