diff --git a/v2/index.html b/v2/index.html index 9bc6831..2a03d1e 100644 --- a/v2/index.html +++ b/v2/index.html @@ -36,7 +36,25 @@
- + diff --git a/v2/src/app/app.js b/v2/src/app/app.js index 3130499..3cb9199 100644 --- a/v2/src/app/app.js +++ b/v2/src/app/app.js @@ -45,10 +45,15 @@ define([ }); compassModule.run(function($rootScope, $state, authService, rememberMe) { $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) { - if (toState.authenticate && rememberMe.getCookie('isAuthenticated') != "true") { - // User isn't authenticated - $state.transitionTo("login"); - event.preventDefault(); + if (toState.authenticate && !authService.isAuthenticated) { + if (rememberMe.getCookie("isAuthenticated")) { + authService.isAuthenticated = true + } + else { + // User isn't authenticated + $state.transitionTo("login"); + event.preventDefault(); + } } }); }); @@ -65,7 +70,7 @@ define([ $scope.logout = function() { authService.logout().success(function(data) { - rememberMe.setCookies("isAuthenticated", "false", -30); + authService.setLogout(); $state.transitionTo("login"); }).error(function(response) { console.log(response); @@ -73,5 +78,13 @@ define([ }) } }); + compassModule.controller('errorHandlingModalController',function($scope,$modalInstance,message){ + $scope.warning = message.data; + $scope.status = message.status; + + $scope.ok =function(){ + $modalInstance.close(); + } + }); }); \ No newline at end of file diff --git a/v2/src/app/login/login.js b/v2/src/app/login/login.js index 9cfb5c5..823a821 100644 --- a/v2/src/app/login/login.js +++ b/v2/src/app/login/login.js @@ -25,8 +25,7 @@ define(['uiRouter'], function() { "remember": Boolean($scope.remember) }; authService.login(credentials).success(function(data) { - rememberMe.setCookies("isAuthenticated","true",0.0833,Boolean($scope.remember)); - //authService.isAuthenticated = true; + authService.setLogin($scope.remember); $state.transitionTo("clusterList"); }).error(function(response) { console.log(response); diff --git a/v2/src/app/services.js b/v2/src/app/services.js index 0ed62b4..2a2fd2d 100644 --- a/v2/src/app/services.js +++ b/v2/src/app/services.js @@ -1,5 +1,5 @@ -define(['angular'], function() { - var servicesModule = angular.module('compass.services', []); +define(['angular','uiBootstrap'], function(ng, uiBootstrap) { + var servicesModule = angular.module('compass.services', ['ui.bootstrap']); // stateService is used for dynamically add/edit state /* .service('stateService', ['$state', function($state) { @@ -503,12 +503,17 @@ define(['angular'], function() { } ]); - servicesModule.service('authService', ['$http', 'dataService', - function($http, dataService) { - this.isAuthenticated = true; + servicesModule.service('authService', ['$http', 'dataService','rememberMe', + function($http, dataService,rememberMe) { + this.isAuthenticated = false; - this.setLogin = function(isLogin) { - this.isAuthenticated = isLogin; + this.setLogin = function(remember) { + this.isAuthenticated = true; + rememberMe.setCookies("isAuthenticated","true",0.0833,Boolean(remember)); + }; + this.setLogout = function(){ + this.isAuthenticated = false; + rememberMe.setCookies("isAuthenticated", "false", -30); } this.login = function(user) { @@ -516,13 +521,25 @@ define(['angular'], function() { }; this.logout = function() { - //this.isAuthenticated = false; return dataService.logout(); }; } ]); - servicesModule.factory('authenticationInterceptor', ['$q', '$location', - function($q, $location) { + servicesModule.service('modalService',function($modal){ + this.show = function(message){ + return $modal.open({ + templateUrl: 'messagemodal.html', + controller: 'errorHandlingModalController', + resolve:{ + message: function(){ + return message; + } + } + }); + } + }); + servicesModule.factory('authenticationInterceptor', ['$q', '$location','$injector', + function($q, $location, $injector) { return { response: function(response) { return response; @@ -532,6 +549,13 @@ define(['angular'], function() { console.log("Response Error 401", rejection); $location.path('/login'); } + else{ + if(rejection.config.url && rejection.config.url != "/api/users/login") + { + var modal = $injector.get("modalService"); + modal.show(rejection); + } + } return $q.reject(rejection); } @@ -557,8 +581,13 @@ define(['angular'], function() { var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; - while (c.charAt(0) == ' ') c = c.substring(1); - if (c.indexOf(name) != -1) return c.substring(name.length, c.length); + while (c.charAt(0) == ' ') + c = c.substring(1); + if (c.indexOf(name) != -1) + { + console.log("inside") + return c.substring(name.length, c.length); + } } return ""; diff --git a/v2/src/app/wizard/wizard.js b/v2/src/app/wizard/wizard.js index 6ef0a11..4b2d19b 100644 --- a/v2/src/app/wizard/wizard.js +++ b/v2/src/app/wizard/wizard.js @@ -485,14 +485,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne wizardFactory.setCommitState(commitState); wizardFactory.setAllMachinesHost($scope.allservers); - }).error(function(response) { - var commitState = { - "name": "sv_selection", - "state": "success", - "message": response - }; - wizardFactory.setCommitState(commitState); }); + // .error(function(response) { + // var commitState = { + // "name": "sv_selection", + // "state": "success", + // "message": response + // }; + // wizardFactory.setCommitState(commitState); + // }); //wizardFactory.setServers(selectedServers); } }; @@ -601,14 +602,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne "message": "" }; wizardFactory.setCommitState(commitState); - }).error(function(response) { - var commitState = { - "name": "os_global", - "state": "error", - "message": response - }; - wizardFactory.setCommitState(commitState); }); + // .error(function(response) { + // var commitState = { + // "name": "os_global", + // "state": "error", + // "message": response + // }; + // wizardFactory.setCommitState(commitState); + // }); } else { var message = {}; if ($scope.generalForm.$error.required) { @@ -1107,14 +1109,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne "message": "" }; wizardFactory.setCommitState(commitState); - }).error(function(response) { - var commitState = { - "name": "partition", - "state": "error", - "message": response - }; - wizardFactory.setCommitState(commitState); }); + // .error(function(response) { + // var commitState = { + // "name": "partition", + // "state": "error", + // "message": response + // }; + // wizardFactory.setCommitState(commitState); + // }); } }; }); @@ -1259,14 +1262,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne "message": "" }; wizardFactory.setCommitState(commitState); - }).error(function(response) { - var commitState = { - "name": "package_config", - "state": "error", - "message": response - }; - wizardFactory.setCommitState(commitState); }); + // .error(function(response) { + // var commitState = { + // "name": "package_config", + // "state": "error", + // "message": response + // }; + // wizardFactory.setCommitState(commitState); + // }); }; }); @@ -1611,14 +1615,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne "message": "" }; wizardFactory.setCommitState(commitState); - }).error(function(response) { - var commitState = { - "name": "network_mapping", - "state": "error", - "message": response - }; - wizardFactory.setCommitState(commitState); }); + // .error(function(response) { + // var commitState = { + // "name": "network_mapping", + // "state": "error", + // "message": response + // }; + // wizardFactory.setCommitState(commitState); + // }); }; }); diff --git a/v2/src/app/wizard/wizard.tpl.html b/v2/src/app/wizard/wizard.tpl.html index 67d70b6..d835905 100644 --- a/v2/src/app/wizard/wizard.tpl.html +++ b/v2/src/app/wizard/wizard.tpl.html @@ -53,24 +53,3 @@ -
- -