From dc1c955485564e17a2540d52058290aa10742a6b Mon Sep 17 00:00:00 2001 From: jcwimer Date: Thu, 10 Mar 2016 12:46:03 +0000 Subject: [PATCH] Workers have a different command --- deploy/docker-compose-prod-full-stack.yml | 1 + frontend/app/js/auth-service.js | 49 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 frontend/app/js/auth-service.js diff --git a/deploy/docker-compose-prod-full-stack.yml b/deploy/docker-compose-prod-full-stack.yml index ed3e280..2bc49d9 100644 --- a/deploy/docker-compose-prod-full-stack.yml +++ b/deploy/docker-compose-prod-full-stack.yml @@ -23,3 +23,4 @@ worker: restart: always env_file: - ./prod.env + command: bundle exec rake jobs:work RAILS_ENV=production diff --git a/frontend/app/js/auth-service.js b/frontend/app/js/auth-service.js new file mode 100644 index 0000000..db0c7d9 --- /dev/null +++ b/frontend/app/js/auth-service.js @@ -0,0 +1,49 @@ +app.factory('AuthenticationService', + ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout', + function (Base64, $http, $cookieStore, $rootScope, $timeout) { + var service = {}; + + service.Login = function (username, password, callback) { + + /* Dummy authentication for testing, uses $timeout to simulate api call + ----------------------------------------------*/ + // $timeout(function(){ + // var response = { success: username === 'test' && password === 'test' }; + // if(!response.success) { + // response.message = 'Username or password is incorrect'; + // } + // callback(response); + // }, 1000); + + + /* Use this for real authentication + ----------------------------------------------*/ + $http.post('/api/authenticate', { username: username, password: password }) + .success(function (response) { + callback(response); + }); + + }; + + service.SetCredentials = function (username, password) { + var authdata = Base64.encode(username + ':' + password); + + $rootScope.globals = { + currentUser: { + username: username, + authdata: authdata + } + }; + + $http.defaults.headers.common['Authorization'] = 'Basic ' + authdata; // jshint ignore:line + $cookieStore.put('globals', $rootScope.globals); + }; + + service.ClearCredentials = function () { + $rootScope.globals = {}; + $cookieStore.remove('globals'); + $http.defaults.headers.common.Authorization = 'Basic '; + }; + + return service; + }]); \ No newline at end of file