File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ // modify jquery ajax to add csrtoken when doing "local" requests
2
+ $ ( 'html' ) . ajaxSend ( function ( event , xhr , settings ) {
3
+ function getCookie ( name ) {
4
+ var cookieValue = null ;
5
+ if ( document . cookie && document . cookie != '' ) {
6
+ var cookies = document . cookie . split ( ';' ) ;
7
+ for ( var i = 0 ; i < cookies . length ; i ++ ) {
8
+ var cookie = jQuery . trim ( cookies [ i ] ) ;
9
+ // Does this cookie string begin with the name we want?
10
+ if ( cookie . substring ( 0 , name . length + 1 ) == ( name + '=' ) ) {
11
+ cookieValue = decodeURIComponent ( cookie . substring ( name . length + 1 ) ) ;
12
+ break ;
13
+ }
14
+ }
15
+ }
16
+ return cookieValue ;
17
+ }
18
+ if ( ! ( / ^ h t t p : .* / . test ( settings . url ) || / ^ h t t p s : .* / . test ( settings . url ) ) ) {
19
+ // Only send the token to relative URLs i.e. locally.
20
+ xhr . setRequestHeader ( "X-CSRFToken" , getCookie ( 'csrftoken' ) ) ;
21
+ }
22
+ } ) ;
Original file line number Diff line number Diff line change @@ -84,4 +84,5 @@ <h3 class="modal-title"></h3>
84
84
< script src ="{{ STATIC_URL }}js/jquery.fileupload-ui.js "> </ script >
85
85
< script src ="{{ STATIC_URL }}js/locale.js "> </ script >
86
86
< script src ="{{ STATIC_URL }}js/main.js "> </ script >
87
+ < script src ="{{ STATIC_URL }}js/csrf.js "> </ script >
87
88
{% endblock %}
You can’t perform that action at this time.
0 commit comments