summaryrefslogtreecommitdiffstats
path: root/public/js
diff options
context:
space:
mode:
authorslene <vslene@gmail.com>2014-03-23 01:44:02 +0800
committerslene <vslene@gmail.com>2014-03-23 01:44:02 +0800
commit076fc98d981aea3533eea363ca1c7e43f77b9802 (patch)
tree596d754de0d53a7e0794dcd61122ddb85298a0e1 /public/js
parent01e781dedb3c6d48349516de0eee5cea41c077e1 (diff)
downloadgitea-076fc98d981aea3533eea363ca1c7e43f77b9802.tar.gz
gitea-076fc98d981aea3533eea363ca1c7e43f77b9802.zip
add csrf check
Diffstat (limited to 'public/js')
-rw-r--r--public/js/app.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/public/js/app.js b/public/js/app.js
index f179342f4b..df755727b5 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -2,6 +2,39 @@ var Gogits = {
"PageIsSignup": false
};
+(function($){
+ // extend jQuery ajax, set csrf token value
+ var ajax = $.ajax;
+ $.extend({
+ ajax: function(url, options) {
+ if (typeof url === 'object') {
+ options = url;
+ url = undefined;
+ }
+ options = options || {};
+ url = options.url;
+ var csrftoken = $('meta[name=_csrf]').attr('content');
+ var headers = options.headers || {};
+ var domain = document.domain.replace(/\./ig, '\\.');
+ if (!/^(http:|https:).*/.test(url) || eval('/^(http:|https:)\\/\\/(.+\\.)*' + domain + '.*/').test(url)) {
+ headers = $.extend(headers, {'X-Csrf-Token':csrftoken});
+ }
+ options.headers = headers;
+ var callback = options.success;
+ options.success = function(data){
+ if(data.once){
+ // change all _once value if ajax data.once exist
+ $('[name=_once]').val(data.once);
+ }
+ if(callback){
+ callback.apply(this, arguments);
+ }
+ };
+ return ajax(url, options);
+ }
+ });
+}(jQuery));
+
(function ($) {
Gogits.showTab = function (selector, index) {