GUAC-932: Remove use of localStorageUtility where possible. Use cookies for auth data.

This commit is contained in:
Michael Jumper
2014-11-30 03:31:46 -08:00
parent 4d1e604759
commit fee75204bd
12 changed files with 55 additions and 50 deletions

View File

@@ -23,12 +23,13 @@
/**
* A service for authenticating a user against the REST API.
*/
angular.module('auth').factory('authenticationService', ['$http', '$injector',
function authenticationService($http, $injector) {
angular.module('auth').factory('authenticationService', ['$http', '$cookieStore',
function authenticationService($http, $cookieStore) {
var localStorageUtility = $injector.get("localStorageUtility");
var service = {};
var AUTH_COOKIE_ID = "GUAC_AUTH";
/**
* Makes a request to authenticate a user using the token REST API endpoint,
* returning a promise that can be used for processing the results of the call.
@@ -49,8 +50,10 @@ angular.module('auth').factory('authenticationService', ['$http', '$injector',
password: password
})
}).success(function success(data, status, headers, config) {
localStorageUtility.set('authToken', data.authToken);
localStorageUtility.set('userID', data.userID);
$cookieStore.put(AUTH_COOKIE_ID, {
authToken : data.authToken,
userID : data.userID
});
});
};
@@ -73,7 +76,8 @@ angular.module('auth').factory('authenticationService', ['$http', '$injector',
* @returns {String} The user ID of the current user.
*/
service.getCurrentUserID = function getCurrentUserID() {
return localStorageUtility.get('userID');
var authData = $cookieStore.get(AUTH_COOKIE_ID);
return authData && authData.userID;
};
/**
@@ -83,7 +87,8 @@ angular.module('auth').factory('authenticationService', ['$http', '$injector',
* @returns {String} The auth token associated with the current user.
*/
service.getCurrentToken = function getCurrentToken() {
return localStorageUtility.get('authToken');
var authData = $cookieStore.get(AUTH_COOKIE_ID);
return authData && authData.authToken;
};
return service;