From c511010ec41e57d99d1756780ee968269fa2b8fb Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 24 Feb 2016 14:39:47 +0100 Subject: Manager session cookie OK ! --- client/js/controllers/login.js | 1 - 1 file changed, 1 deletion(-) (limited to 'client/js/controllers/login.js') diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 829fc1d..a37591c 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -20,7 +20,6 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s $('#loadingLoginButton').hide(); $('#failedToLoginAlert').hide(); - $scope.loginAction=function(){ // Begin login state for template -- cgit v1.2.3 From 211ebb0e432b5fee2031dd6e7338e659146867bb Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 24 Feb 2016 15:02:14 +0100 Subject: Simplify Identity --- client/js/controllers/login.js | 7 ++++++- client/js/controllers/status.js | 2 +- client/js/services/Identity.js | 46 +++++++++++++++++++++++++++-------------- 3 files changed, 37 insertions(+), 18 deletions(-) (limited to 'client/js/controllers/login.js') diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index a37591c..66d1793 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -13,13 +13,18 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s if(!Identity.isAlreadyLogin()){ $('#loginModal').modal({backdrop: 'static', keyboard: false}); } + + // Manager logout event $scope.$on('logoutEvent', function(){ $('#loginModal').modal({backdrop: 'static', keyboard: false}); }); - + + // Hide loading button and message alert $('#loadingLoginButton').hide(); $('#failedToLoginAlert').hide(); + + // Defined function for login $scope.loginAction=function(){ // Begin login state for template diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index e01df34..5ec6fa8 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -10,7 +10,7 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($ { // Give profile to model - $scope.profile=Identity.profile; + $scope.profile=Identity.getProfile(); // Function to logout $scope.logout=function(){ diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 0dfba47..2042efd 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -7,10 +7,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ var profile={}; profile.username=null; profile.projectname=null; - var token={}; - token.part_0=null; - token.part_1=null; + var token=null; + /** * Save profile in cookies */ @@ -27,7 +26,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ var isAlreadyLogin=function(){ var profileInCookie=$cookies.getObject('profile'); var tokenPart_0InCookie=$cookies.getObject('token.part_0'); - var tokenPart_1InCookie=$cookies.getObject('token.part_0'); + var tokenPart_1InCookie=$cookies.getObject('token.part_1'); if(typeof profileInCookie !== 'undefined' @@ -35,14 +34,29 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ && typeof tokenPart_1InCookie !== 'undefined' ){ angular.extend(profile, profileInCookie); - token.part_0=tokenPart_0InCookie; - token.part_1=tokenPart_1InCookie; + token=tokenPart_0InCookie+tokenPart_1InCookie; + return true; } return false; } + + /* + * Get the profile + */ + var getProfile=function(){ + return profile; + } + + /* + * Get the token + */ + var getToken=function(){ + return token; + } + /* * Destroy profile cookies */ @@ -67,13 +81,18 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ requestParserResult.failReason=null; if (typeof response.data.token !== 'undefined') { + // Set status code requestParserResult.status=0; + // Find the middle of the token to split it var middle=parseInt(response.data.token.length/2); - token.part_0=response.data.token.substring(0, middle); - token.part_1=response.data.token.substring(middle, response.data.token.length); - - saveCookieForSession(); + + // Save profile + $cookies.putObject('profile', profile); + // Save first part of token + $cookies.putObject('token.part_0', response.data.token.substring(0, middle)); + // Save second part of token + $cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length)); } else if(failedToSendRequest){ requestParserResult.failReason="Failed to send request"; @@ -84,11 +103,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ return requestParserResult; }; - - - var getToken=function(){ - return token.part_0+token.part_1; - } /** * Function to connect to OpenStack @@ -121,7 +135,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ // Return services objects return { login: login, - profile: profile, + getProfile: getProfile, isAlreadyLogin: isAlreadyLogin, logout:logout, getToken:getToken -- cgit v1.2.3 From 5d8b904a328c87c533231ebf6ba68965256a035f Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 24 Feb 2016 15:22:10 +0100 Subject: Change logout event --- client/js/controllers/login.js | 1 + client/js/controllers/status.js | 4 +--- client/partials/nav.html | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'client/js/controllers/login.js') diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 66d1793..1a89563 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -16,6 +16,7 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s // Manager logout event $scope.$on('logoutEvent', function(){ + Identity.logout(); $('#loginModal').modal({backdrop: 'static', keyboard: false}); }); diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 5ec6fa8..940d794 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -13,10 +13,8 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($ $scope.profile=Identity.getProfile(); // Function to logout - $scope.logout=function(){ - Identity.logout(); + $scope.raiseLogoutEvent=function(){ $rootScope.$broadcast('logoutEvent'); - }; }]); diff --git a/client/partials/nav.html b/client/partials/nav.html index 3c72844..b3ef76a 100644 --- a/client/partials/nav.html +++ b/client/partials/nav.html @@ -32,7 +32,7 @@
  • Informations
  • Settings
  • -
  • Logout
  • +
  • Logout
  • -- cgit v1.2.3