From daf0cfc65f63911b5819e33edf4adc0ea5d55dff Mon Sep 17 00:00:00 2001 From: Vincent Fournier Date: Fri, 15 May 2015 10:03:39 -0400 Subject: [PATCH] Add development config for automatique login Change-Id: I12318c7e0b1bfd8630639f2ec8e3478121f1e856 --- .gitignore | 2 ++ .../authentication/authentication.js | 31 ++++++++++++++++--- app/components/config/config.js | 22 ++++++++++++- app/components/config/developmentConfig.json | 5 +++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 app/components/config/developmentConfig.json diff --git a/.gitignore b/.gitignore index 7d0d51d..9e6467f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ dist/ .tmp/ app/components/live/live.js + +app/components/config/developmentConfig.json diff --git a/app/components/authentication/authentication.js b/app/components/authentication/authentication.js index f4d36a6..54a41c5 100644 --- a/app/components/authentication/authentication.js +++ b/app/components/authentication/authentication.js @@ -9,7 +9,11 @@ angular.module('bansho.authentication', []) }); }]) - .controller('LoginController', ['$scope', '$rootScope', '$location', 'authService', function ($scope, $rootScope, $location, authService) { + .controller('LoginController', ['$scope', '$rootScope', '$location', 'authService', 'configManager', function ($scope, $rootScope, $location, authService, configManager) { + var login = function (credentials) { + authService.login(credentials); + }; + $scope.credentials = { 'auth': { 'tenantName': '', @@ -20,9 +24,28 @@ angular.module('bansho.authentication', []) } }; - $scope.login = function (credentials) { - authService.login(credentials); - }; + $scope.login = function() { + login($scope.credentials); + }; + + configManager.loadDevelopmentConfig().then(function () { + var devConfig = configManager.getDevelopmentConfig(); + if (devConfig.env === 'development') { + login({ + 'auth': { + 'tenantName': '', + 'passwordCredentials': { + 'username': devConfig.username, + 'password': devConfig.password + } + } + }); + } + + }, function () { + // Development config failed + }); + }]) .factory('authService', ['$http', '$location', '$rootScope', 'session', 'configManager', function ($http, $location, $rootScope, session, configManager) { diff --git a/app/components/config/config.js b/app/components/config/config.js index c86da96..f4d8b08 100644 --- a/app/components/config/config.js +++ b/app/components/config/config.js @@ -4,7 +4,27 @@ angular.module('bansho.config', []) .service('configManager', ['$http', '$q', function ($http, $q) { - var config = {}; + var config = {}, + developmentConfig = {}; + + this.loadDevelopmentConfig = function() { + var promise = $q.defer(); + + $http.get('components/config/developmentConfig.json') + .success(function (config) { + developmentConfig = config; + promise.resolve(); + }) + .error(function() { + promise.reject(); + }); + + return promise.promise; + }; + + this.getDevelopmentConfig = function () { + return developmentConfig; + }; this.loadByTemplate = function (templateName, destination) { var viewsConfig = config.data; diff --git a/app/components/config/developmentConfig.json b/app/components/config/developmentConfig.json new file mode 100644 index 0000000..c1ec75c --- /dev/null +++ b/app/components/config/developmentConfig.json @@ -0,0 +1,5 @@ +{ + "env": "development", + "username":"", + "password":"" +}