Merge pull request #5618 from jaredevantabor/upgrade-cookieStore

updating $cookieStore to $cookie
This commit is contained in:
Jared Tabor 2017-03-02 14:07:42 -08:00 committed by GitHub
commit 795b71082d
7 changed files with 47 additions and 47 deletions

View File

@ -232,12 +232,12 @@ var tower = angular.module('Tower', [
// })
}
])
.run(['$stateExtender', '$q', '$compile', '$cookieStore', '$rootScope', '$log', '$stateParams',
.run(['$stateExtender', '$q', '$compile', '$cookies', '$rootScope', '$log', '$stateParams',
'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'Timer',
'ClearScope', 'LoadConfig', 'Store', 'pendoService', 'Prompt', 'Rest',
'Wait', 'ProcessErrors', '$state', 'GetBasePath', 'ConfigService',
'FeaturesService', '$filter', 'SocketService',
function($stateExtender, $q, $compile, $cookieStore, $rootScope, $log, $stateParams,
function($stateExtender, $q, $compile, $cookies, $rootScope, $log, $stateParams,
CheckLicense, $location, Authorization, LoadBasePaths, Timer,
ClearScope, LoadConfig, Store, pendoService, Prompt, Rest, Wait,
ProcessErrors, $state, GetBasePath, ConfigService, FeaturesService,
@ -339,7 +339,7 @@ var tower = angular.module('Tower', [
// capture most recent URL, excluding login/logout
$rootScope.lastPath = $location.path();
$rootScope.enteredPath = $location.path();
$cookieStore.put('lastPath', $location.path());
$cookies.put('lastPath', $location.path());
}
if (Authorization.isUserLoggedIn() === false) {
@ -405,7 +405,7 @@ var tower = angular.module('Tower', [
// User not authenticated, redirect to login page
$location.path('/login');
} else {
var lastUser = $cookieStore.get('current_user'),
var lastUser = $cookies.getObject('current_user'),
timestammp = Store('sessionTime');
if (lastUser && lastUser.id && timestammp && timestammp[lastUser.id] && timestammp[lastUser.id].loggedIn) {
var stime = timestammp[lastUser.id].time,

View File

@ -15,20 +15,20 @@
*/
export default
['$http', '$rootScope', '$location', '$cookieStore', 'GetBasePath', 'Store', '$q',
['$http', '$rootScope', '$location', '$cookies', 'GetBasePath', 'Store', '$q',
'$injector',
function ($http, $rootScope, $location, $cookieStore, GetBasePath, Store, $q,
function ($http, $rootScope, $location, $cookies, GetBasePath, Store, $q,
$injector) {
return {
setToken: function (token, expires) {
// set the session cookie
$cookieStore.remove('token');
$cookieStore.remove('token_expires');
$cookieStore.remove('userLoggedIn');
$cookieStore.put('token', token);
$cookieStore.put('token_expires', expires);
$cookieStore.put('userLoggedIn', true);
$cookieStore.put('sessionExpired', false);
$cookies.remove('token');
$cookies.remove('token_expires');
$cookies.remove('userLoggedIn');
$cookies.put('token', token);
$cookies.put('token_expires', expires);
$cookies.put('userLoggedIn', true);
$cookies.put('sessionExpired', false);
$rootScope.token = token;
$rootScope.userLoggedIn = true;
$rootScope.token_expires = expires;
@ -38,14 +38,14 @@ export default
isUserLoggedIn: function () {
if ($rootScope.userLoggedIn === undefined) {
// Browser refresh may have occurred
$rootScope.userLoggedIn = $cookieStore.get('userLoggedIn');
$rootScope.sessionExpired = $cookieStore.get('sessionExpired');
$rootScope.userLoggedIn = $cookies.get('userLoggedIn');
$rootScope.sessionExpired = $cookies.get('sessionExpired');
}
return $rootScope.userLoggedIn;
},
getToken: function () {
return ($rootScope.token) ? $rootScope.token : $cookieStore.get('token');
return ($rootScope.token) ? $rootScope.token : $cookies.get('token');
},
retrieveToken: function (username, password) {
@ -83,17 +83,17 @@ export default
scope.$destroy();
}
if($cookieStore.get('lastPath')==='/portal'){
$cookieStore.put( 'lastPath', '/portal');
if($cookies.get('lastPath')==='/portal'){
$cookies.put( 'lastPath', '/portal');
$rootScope.lastPath = '/portal';
}
else if ($cookieStore.get('lastPath') !== '/home' || $cookieStore.get('lastPath') !== '/' || $cookieStore.get('lastPath') !== '/login' || $cookieStore.get('lastPath') !== '/logout'){
else if ($cookies.get('lastPath') !== '/home' || $cookies.get('lastPath') !== '/' || $cookies.get('lastPath') !== '/login' || $cookies.get('lastPath') !== '/logout'){
// do nothing
$rootScope.lastPath = $cookieStore.get('lastPath');
$rootScope.lastPath = $cookies.get('lastPath');
}
else {
// your last path was home
$cookieStore.remove('lastPath');
$cookies.remove('lastPath');
$rootScope.lastPath = '/home';
}
x = Store('sessionTime');
@ -102,17 +102,17 @@ export default
}
Store('sessionTime', x);
if ($cookieStore.get('current_user')) {
$rootScope.lastUser = $cookieStore.get('current_user').id;
if ($cookies.getObject('current_user')) {
$rootScope.lastUser = $cookies.getObject('current_user').id;
}
ConfigService.delete();
SocketService.disconnect();
$cookieStore.remove('token_expires');
$cookieStore.remove('current_user');
$cookieStore.remove('token');
$cookieStore.put('userLoggedIn', false);
$cookieStore.put('sessionExpired', false);
$cookieStore.put('current_user', {});
$cookies.remove('token_expires');
$cookies.remove('current_user');
$cookies.remove('token');
$cookies.put('userLoggedIn', false);
$cookies.put('sessionExpired', false);
$cookies.putObject('current_user', {});
$rootScope.current_user = {};
$rootScope.license_tested = undefined;
$rootScope.userLoggedIn = false;
@ -163,11 +163,11 @@ export default
setUserInfo: function (response) {
// store the response values in $rootScope so we can get to them later
$rootScope.current_user = response.results[0];
$cookieStore.put('current_user', response.results[0]); //keep in session cookie in the event of browser refresh
$cookies.putObject('current_user', response.results[0]); //keep in session cookie in the event of browser refresh
},
restoreUserInfo: function () {
$rootScope.current_user = $cookieStore.get('current_user');
$rootScope.current_user = $cookies.getObject('current_user');
},
getUserInfo: function (key) {
@ -177,7 +177,7 @@ export default
return $rootScope.current_user[key];
}
this.restoreUserInfo();
cu = $cookieStore.get('current_user');
cu = $cookies.getObject('current_user');
return cu[key];
}
};

View File

@ -12,8 +12,8 @@
export default
['$rootScope', 'Alert', 'Rest', 'GetBasePath', 'ProcessErrors', '$cookieStore',
function ($rootScope, Alert, Rest, GetBasePath, ProcessErrors, $cookieStore) {
['$rootScope', 'Alert', 'Rest', 'GetBasePath', 'ProcessErrors', '$cookies',
function ($rootScope, Alert, Rest, GetBasePath, ProcessErrors, $cookies) {
return function (params) {
// set PermissionAddAllowed to true or false based on user access. admins and org admins are granted
// accesss.
@ -22,7 +22,7 @@ export default
me;
// uer may have refreshed the browser, in which case retrieve current user info from session cookie
me = ($rootScope.current_user) ? $rootScope.current_user : $cookieStore.get('current_user');
me = ($rootScope.current_user) ? $rootScope.current_user : $cookies.getObject('current_user');
if (me.is_superuser) {
scope.PermissionAddAllowed = true;

View File

@ -22,9 +22,9 @@
* @description
*/
export default
['$rootScope', '$cookieStore', 'CreateDialog', 'Authorization',
['$rootScope', '$cookies', 'CreateDialog', 'Authorization',
'Store', '$interval', '$state', '$q', 'i18n',
function ($rootScope, $cookieStore, CreateDialog, Authorization,
function ($rootScope, $cookies, CreateDialog, Authorization,
Store, $interval, $state, $q, i18n) {
return {
@ -81,7 +81,7 @@ export default
}
this.sessionTime = 0;
this.clearTimers();
$cookieStore.put('sessionExpired', true);
$cookies.put('sessionExpired', true);
},
moveForward: function () {
@ -101,7 +101,7 @@ export default
y[$rootScope.current_user.id] = x;
Store('sessionTime' , y);
$rootScope.sessionExpired = false;
$cookieStore.put('sessionExpired', false);
$cookies.put('sessionExpired', false);
this.startTimers();
},

View File

@ -54,11 +54,11 @@
* This is usage information.
*/
export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope',
export default ['$log', '$cookies', '$compile', '$window', '$rootScope',
'$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait', 'Timer',
'Empty', 'ClearScope', '$scope', 'pendoService', 'ConfigService',
'CheckLicense', 'FeaturesService', 'SocketService',
function ($log, $cookieStore, $compile, $window, $rootScope, $location,
function ($log, $cookies, $compile, $window, $rootScope, $location,
Authorization, ToggleClass, Alert, Wait, Timer, Empty, ClearScope,
scope, pendoService, ConfigService, CheckLicense, FeaturesService,
SocketService) {
@ -70,13 +70,13 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope',
}, 1000);
};
scope.sessionExpired = (Empty($rootScope.sessionExpired)) ? $cookieStore.get('sessionExpired') : $rootScope.sessionExpired;
scope.sessionExpired = (Empty($rootScope.sessionExpired)) ? $cookies.get('sessionExpired') : $rootScope.sessionExpired;
scope.login_username = '';
scope.login_password = '';
lastPath = function () {
return (Empty($rootScope.lastPath)) ? $cookieStore.get('lastPath') : $rootScope.lastPath;
return (Empty($rootScope.lastPath)) ? $cookies.get('lastPath') : $rootScope.lastPath;
};
lastUser = function(){

View File

@ -55,8 +55,8 @@
*/
export default
['$http', '$rootScope', '$cookieStore', '$q', 'Authorization',
function ($http, $rootScope, $cookieStore, $q, Authorization) {
['$http', '$rootScope', '$cookies', '$q', 'Authorization',
function ($http, $rootScope, $cookies, $q, Authorization) {
return {
headers: {},

View File

@ -179,8 +179,8 @@ angular.module('Utilities', ['RestServices', 'Utilities', 'sanitizeFilter'])
* @methodOf shared.function:Utilities
* @description For handling errors that are returned from the API
*/
.factory('ProcessErrors', ['$rootScope', '$cookieStore', '$log', '$location', 'Alert', 'Wait',
function($rootScope, $cookieStore, $log, $location, Alert, Wait) {
.factory('ProcessErrors', ['$rootScope', '$cookies', '$log', '$location', 'Alert', 'Wait',
function($rootScope, $cookies, $log, $location, Alert, Wait) {
return function(scope, data, status, form, defaultMsg) {
var field, fieldErrors, msg, keys;
Wait('stop');