mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-16 13:54:54 +00:00
(js) Add support for XSRF token with file uploader
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Set XSRF header if the cookie exists.
|
||||
* Solution based on the following discussion:
|
||||
* https://github.com/nervgh/angular-file-upload/issues/360
|
||||
*/
|
||||
angular
|
||||
.module('angularFileUpload')
|
||||
.decorator('FileUploader', FileUploaderDecorator);
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
FileUploaderDecorator.$inject = ['$delegate', '$cookies'];
|
||||
function FileUploaderDecorator($delegate, $cookies) {
|
||||
$delegate.prototype.onBeforeUploadItem = function(item) {
|
||||
var token = $cookies.get('XSRF-TOKEN');
|
||||
if (token)
|
||||
item.headers = {'X-XSRF-TOKEN': token};
|
||||
};
|
||||
return $delegate;
|
||||
}
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user