mirror of
https://github.com/Hopiu/django-markdownx.git
synced 2026-04-20 13:10:59 +00:00
Handle csrf stored in sessions (#111)
* Handle csrf stored in sessions This allow to use CSRF_USE_SESSIONS = True which store crsf token in session instead of cookies.tting CSRF_USE_SESSIONS = True. It checks if csrf token found in cookies otherwise try to get csrf token in session. * Remove useless line
This commit is contained in:
parent
ec23807f18
commit
e9605560f0
1 changed files with 6 additions and 2 deletions
|
|
@ -117,7 +117,11 @@ export function preparePostData(data: Object, csrf: Boolean=true) {
|
|||
|
||||
let form: FormData = new FormData();
|
||||
|
||||
if (csrf) form.append("csrfmiddlewaretoken", getCookie('csrftoken'));
|
||||
if (csrf) {
|
||||
let csrfToken = getCookie('csrftoken');
|
||||
if (!csrfToken) csrfToken = (<HTMLInputElement>document.querySelector("input[name='csrfmiddlewaretoken']")).value;
|
||||
form.append("csrfmiddlewaretoken", csrfToken);
|
||||
}
|
||||
|
||||
Object.keys(data).map(key => form.append(key, data[key]));
|
||||
|
||||
|
|
@ -344,4 +348,4 @@ export function removeClass (element: Element, ...className: string[]): void {
|
|||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue