summaryrefslogtreecommitdiffstats
path: root/pharos-dashboard/dashboard/static/js/csrf.js
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:10:31 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:10:31 +0200
commit79aec84973032e15ae9d36fcbd7d7d42af3283d1 (patch)
treec02fbd44cd53b0eed105bc648c743b10c62bfeb4 /pharos-dashboard/dashboard/static/js/csrf.js
parent639cd5db77064c275253828780c17ae59551d95c (diff)
Split the dashboard into different apps, add tests
JIRA: RELENG-12 Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'pharos-dashboard/dashboard/static/js/csrf.js')
-rw-r--r--pharos-dashboard/dashboard/static/js/csrf.js34
1 files changed, 0 insertions, 34 deletions
diff --git a/pharos-dashboard/dashboard/static/js/csrf.js b/pharos-dashboard/dashboard/static/js/csrf.js
deleted file mode 100644
index 12429b3..0000000
--- a/pharos-dashboard/dashboard/static/js/csrf.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * use django csrf token in ajax requests
- * source: https://docs.djangoproject.com/en/1.8/ref/csrf/#ajax
- */
-// using jQuery
-function getCookie(name) {
- var cookieValue = null;
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // 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;
-}
-var csrftoken = getCookie('csrftoken');
-
-function csrfSafeMethod(method) {
- // these HTTP methods do not require CSRF protection
- return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
-}
-
-$.ajaxSetup({
- beforeSend: function (xhr, settings) {
- if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
- xhr.setRequestHeader("X-CSRFToken", csrftoken);
- }
- }
-}); \ No newline at end of file