Add a new cookie service and have it properly use permanent cookies when needed.
This commit is contained in:
parent
8725b7a87c
commit
cc8e0e5ea5
1 changed files with 37 additions and 13 deletions
|
@ -90,7 +90,28 @@ function getMarkedDown(string) {
|
||||||
|
|
||||||
// Start the application code itself.
|
// Start the application code itself.
|
||||||
quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives', 'ngCookies'], function($provide) {
|
quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives', 'ngCookies'], function($provide) {
|
||||||
$provide.factory('UserService', ['Restangular', '$cookies', function(Restangular, $cookies) {
|
$provide.factory('CookieService', ['$cookies', '$cookieStore', function($cookies, $cookieStore) {
|
||||||
|
var cookieService = {};
|
||||||
|
cookieService.putPermanent = function(name, value) {
|
||||||
|
document.cookie = escape(name) + "=" + escape(value) + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
|
||||||
|
};
|
||||||
|
|
||||||
|
cookieService.putSession = function(name, value) {
|
||||||
|
$cookies[name] = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
cookieService.clear = function(name) {
|
||||||
|
$cookies[name] = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
cookieService.get = function(name) {
|
||||||
|
return $cookies[name];
|
||||||
|
};
|
||||||
|
|
||||||
|
return cookieService;
|
||||||
|
}]);
|
||||||
|
|
||||||
|
$provide.factory('UserService', ['Restangular', 'CookieService', function(Restangular, CookieService) {
|
||||||
var userResponse = {
|
var userResponse = {
|
||||||
verified: false,
|
verified: false,
|
||||||
anonymous: true,
|
anonymous: true,
|
||||||
|
@ -103,7 +124,7 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an
|
||||||
var userService = {}
|
var userService = {}
|
||||||
|
|
||||||
userService.hasEverLoggedIn = function() {
|
userService.hasEverLoggedIn = function() {
|
||||||
return $cookies.loggedIn == 'true';
|
return CookieService.get('quay.loggedin') == 'true';
|
||||||
};
|
};
|
||||||
|
|
||||||
userService.load = function(opt_callback) {
|
userService.load = function(opt_callback) {
|
||||||
|
@ -122,7 +143,7 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an
|
||||||
'$created': new Date()
|
'$created': new Date()
|
||||||
})
|
})
|
||||||
|
|
||||||
$cookies.loggedIn = 'true';
|
CookieService.putPermanent('quay.loggedin', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_callback) {
|
if (opt_callback) {
|
||||||
|
@ -180,8 +201,8 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an
|
||||||
return keyService;
|
return keyService;
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
$provide.factory('PlanService', ['Restangular', 'KeyService', 'UserService', '$cookieStore',
|
$provide.factory('PlanService', ['Restangular', 'KeyService', 'UserService', 'CookieService',
|
||||||
function(Restangular, KeyService, UserService, $cookieStore) {
|
function(Restangular, KeyService, UserService, CookieService) {
|
||||||
var plans = null;
|
var plans = null;
|
||||||
var planDict = {};
|
var planDict = {};
|
||||||
var planService = {};
|
var planService = {};
|
||||||
|
@ -201,7 +222,7 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.notePlan = function(planId) {
|
planService.notePlan = function(planId) {
|
||||||
$cookieStore.put('quay.notedplan', planId);
|
CookieService.putSession('quay.notedplan', planId);
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.handleNotedPlan = function() {
|
planService.handleNotedPlan = function() {
|
||||||
|
@ -224,8 +245,8 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.getAndResetNotedPlan = function() {
|
planService.getAndResetNotedPlan = function() {
|
||||||
var planId = $cookieStore.get('quay.notedplan');
|
var planId = CookieService.get('quay.notedplan');
|
||||||
$cookieStore.put('quay.notedplan', '');
|
CookieService.clear('quay.notedplan');
|
||||||
return planId;
|
return planId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1842,7 +1863,7 @@ quayApp.directive('namespaceSelector', function () {
|
||||||
'namespace': '=namespace',
|
'namespace': '=namespace',
|
||||||
'requireCreate': '=requireCreate'
|
'requireCreate': '=requireCreate'
|
||||||
},
|
},
|
||||||
controller: function($scope, $element, $routeParams, $cookies) {
|
controller: function($scope, $element, $routeParams, CookieService) {
|
||||||
$scope.namespaces = {};
|
$scope.namespaces = {};
|
||||||
|
|
||||||
$scope.initialize = function(user) {
|
$scope.initialize = function(user) {
|
||||||
|
@ -1854,7 +1875,7 @@ quayApp.directive('namespaceSelector', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var initialNamespace = $routeParams['namespace'] || $cookies.current_namespace|| $scope.user.username;
|
var initialNamespace = $routeParams['namespace'] || CookieService.get('quay.namespace') || $scope.user.username;
|
||||||
$scope.namespaces = namespaces;
|
$scope.namespaces = namespaces;
|
||||||
$scope.setNamespace($scope.namespaces[initialNamespace]);
|
$scope.setNamespace($scope.namespaces[initialNamespace]);
|
||||||
};
|
};
|
||||||
|
@ -1871,7 +1892,10 @@ quayApp.directive('namespaceSelector', function () {
|
||||||
var newNamespace = namespaceObj.name || namespaceObj.username;
|
var newNamespace = namespaceObj.name || namespaceObj.username;
|
||||||
$scope.namespaceObj = namespaceObj;
|
$scope.namespaceObj = namespaceObj;
|
||||||
$scope.namespace = newNamespace;
|
$scope.namespace = newNamespace;
|
||||||
$cookies.current_namespace = newNamespace;
|
|
||||||
|
if (newNamespace) {
|
||||||
|
CookieService.putPermanent('quay.namespace', newNamespace);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.$watch('user', function(user) {
|
$scope.$watch('user', function(user) {
|
||||||
|
@ -1959,8 +1983,8 @@ quayApp.directive('ngBlur', function() {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', 'PlanService', '$http', '$cookieStore', '$timeout',
|
quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', 'PlanService', '$http', '$timeout',
|
||||||
function($location, $rootScope, Restangular, UserService, PlanService, $http, $cookieStore, $timeout) {
|
function($location, $rootScope, Restangular, UserService, PlanService, $http, $timeout) {
|
||||||
// Handle session expiration.
|
// Handle session expiration.
|
||||||
Restangular.setErrorInterceptor(function(response) {
|
Restangular.setErrorInterceptor(function(response) {
|
||||||
if (response.status == 401) {
|
if (response.status == 401) {
|
||||||
|
|
Reference in a new issue