Add CSRF to load

This commit is contained in:
Paulo Gustavo Veiga 2022-02-21 05:45:10 -08:00
parent c95b5c5a50
commit 9650d27490
3 changed files with 5 additions and 5 deletions

View File

@ -43,7 +43,7 @@ class LocalStorageManager extends PersistenceManager {
if (xml == null || this.forceLoad) { if (xml == null || this.forceLoad) {
$.ajax({ $.ajax({
url: this.documentUrl.replace('{id}', mapId), url: this.documentUrl.replace('{id}', mapId),
headers: { 'Content-Type': 'text/plain', Accept: 'application/xml' }, headers: { 'Content-Type': 'text/plain', Accept: 'application/xml', 'X-CSRF-Token': this.getCSRFToken() },
type: 'get', type: 'get',
dataType: 'text', dataType: 'text',
async: false, async: false,

View File

@ -52,6 +52,10 @@ abstract class PersistenceManager {
} }
} }
protected getCSRFToken(): string {
return document.head.querySelector('meta[name="_csrf"]').getAttribute('content');
}
load(mapId: string) { load(mapId: string) {
$assert(mapId, 'mapId can not be null'); $assert(mapId, 'mapId can not be null');
const domDocument = this.loadMapDom(mapId); const domDocument = this.loadMapDom(mapId);

View File

@ -159,10 +159,6 @@ class RESTPersistenceManager extends PersistenceManager {
return { severity, message }; return { severity, message };
} }
private getCSRFToken(): string {
return document.head.querySelector('meta[name="_csrf"]').getAttribute('content');
}
loadMapDom(mapId: string): Document { loadMapDom(mapId: string): Document {
let xml: Document; let xml: Document;
$.ajax({ $.ajax({