Add development config for automatique login

Change-Id: I12318c7e0b1bfd8630639f2ec8e3478121f1e856
This commit is contained in:
Vincent Fournier 2015-05-15 10:03:39 -04:00
parent 981198439a
commit daf0cfc65f
4 changed files with 55 additions and 5 deletions

2
.gitignore vendored
View File

@ -20,3 +20,5 @@ dist/
.tmp/
app/components/live/live.js
app/components/config/developmentConfig.json

View File

@ -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) {

View File

@ -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;

View File

@ -0,0 +1,5 @@
{
"env": "development",
"username":"",
"password":""
}