From 9d3d5008393c7ca4cf003f785e972f9de99b0e20 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 8 Dec 2014 14:26:30 -0800 Subject: [PATCH] GUAC-932: Explicitly handle lack of auth data. Document return values for such a case. --- .../app/auth/service/authenticationService.js | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/guacamole/src/main/webapp/app/auth/service/authenticationService.js b/guacamole/src/main/webapp/app/auth/service/authenticationService.js index 4430e7913..aafe92d2d 100644 --- a/guacamole/src/main/webapp/app/auth/service/authenticationService.js +++ b/guacamole/src/main/webapp/app/auth/service/authenticationService.js @@ -71,24 +71,43 @@ angular.module('auth').factory('authenticationService', ['$http', '$cookieStore' }; /** - * Returns the user ID of the current user. + * Returns the user ID of the current user. If the current user is not + * logged in, this ID may not be valid. * - * @returns {String} The user ID of the current user. + * @returns {String} + * The user ID of the current user, or null if no authentication data + * is present. */ service.getCurrentUserID = function getCurrentUserID() { + + // Return user ID, if available var authData = $cookieStore.get(AUTH_COOKIE_ID); - return authData && authData.userID; + if (authData) + return authData.userID; + + // No auth data present + return null; + }; /** * Returns the auth token associated with the current user. If the current * user is not logged in, this token may not be valid. * - * @returns {String} The auth token associated with the current user. + * @returns {String} + * The auth token associated with the current user, or null if no + * authentication data is present. */ service.getCurrentToken = function getCurrentToken() { + + // Return auth token, if available var authData = $cookieStore.get(AUTH_COOKIE_ID); - return authData && authData.authToken; + if (authData) + return authData.authToken; + + // No auth data present + return null; + }; return service;