From 91806e05c6a3576daa90d8e0430c7ae4d695f33f Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 11 Oct 2017 14:02:27 -0400 Subject: [PATCH] Require auth for /upload --- public/js/components/UploadComp.js | 8 +++++--- public/js/services/AuthSvc.js | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/public/js/components/UploadComp.js b/public/js/components/UploadComp.js index f487c36..2481002 100644 --- a/public/js/components/UploadComp.js +++ b/public/js/components/UploadComp.js @@ -1,4 +1,4 @@ -function UploadController($scope, Upload, $timeout) { +function UploadController($scope, Upload, $timeout, AuthService) { $scope.errToString = function(err) { if (err === 'maxSize') return "File too large."; @@ -14,7 +14,9 @@ function UploadController($scope, Upload, $timeout) { file.upload = Upload.upload({ url: '/upload', method: 'POST', - // data: loginToken, unique id, something + headers: { + 'Authorization': AuthService.getAuthHeader() + }, file: file }); @@ -36,7 +38,7 @@ function UploadController($scope, Upload, $timeout) { }; } -angular.module('UploadComp', ['ngFileUpload']).component('uploadComponent', { +angular.module('UploadComp', ['ngFileUpload', 'AuthSvc']).component('uploadComponent', { templateUrl: '/views/upload-form.html', controller: UploadController, controllerAs: 'vm' diff --git a/public/js/services/AuthSvc.js b/public/js/services/AuthSvc.js index 135f7f5..c115e2c 100644 --- a/public/js/services/AuthSvc.js +++ b/public/js/services/AuthSvc.js @@ -18,6 +18,11 @@ angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', functi return $window.localStorage['shimapan-token']; } + this.getAuthHeader = function() { + return 'Bearer ' + getToken(); + }; + + this.login = function(user) { return $http({ method: 'POST',