Description: Fix bug related to CSRF verification on Django
Author: Jorge Bastida <neo2001@gmail.com>
From: Angel Abad <angelabad@ubuntu.com>
Bug-Ubuntu: https://launchpad.net/bugs/723585
Bug-Debian: http://bugs.debian.org/614787

diff --git a/dajaxice/templates/dajaxice/dajaxice.core.js b/dajaxice/templates/dajaxice/dajaxice.core.js
index ce52364..99568fa 100644
--- a/dajaxice/templates/dajaxice/dajaxice.core.js
+++ b/dajaxice/templates/dajaxice/dajaxice.core.js
@@ -9,6 +9,23 @@ var Dajaxice = {
         },
     {% endfor %}
     
+    get_cookie: function(name)
+    {
+        var cookieValue = null;
+        if (document.cookie && document.cookie != '') {
+            var cookies = document.cookie.split(';');
+            for (var i = 0; i < cookies.length; i++) {
+                var cookie = cookies[i].toString().replace(/^\s+/, "").replace(/\s+$/, "");
+                // Does this cookie string begin with the name we want?
+                if (cookie.substring(0, name.length + 1) == (name + '=')) {
+                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+                    break;
+                }
+            }
+        }
+        return cookieValue;
+    },
+    
     call: function(dajaxice_function, dajaxice_callback, argv)
     {
         var send_data = [];
@@ -17,6 +34,7 @@ var Dajaxice = {
         send_data = send_data.join('&');
         var oXMLHttpRequest = new XMLHttpRequest;
         oXMLHttpRequest.open('POST', '/{{DAJAXICE_URL_PREFIX}}/'+dajaxice_function+'/');
+        oXMLHttpRequest.setRequestHeader("X-CSRFToken",Dajaxice.get_cookie('csrftoken'));
         oXMLHttpRequest.onreadystatechange = function() {
             if (this.readyState == XMLHttpRequest.DONE) {
                 eval(this.responseText);
