diff --git a/guacamole/src/main/webapp/app/home/controllers/homeController.js b/guacamole/src/main/webapp/app/home/controllers/homeController.js index 95ef1e525..89f88e25a 100644 --- a/guacamole/src/main/webapp/app/home/controllers/homeController.js +++ b/guacamole/src/main/webapp/app/home/controllers/homeController.js @@ -32,7 +32,6 @@ angular.module('home').controller('homeController', ['$scope', '$injector', // Get required services var authenticationService = $injector.get("authenticationService"); var connectionGroupService = $injector.get("connectionGroupService"); - var userPageService = $injector.get("userPageService"); /** * The root connection group, or null if the connection group hierarchy has @@ -61,10 +60,4 @@ angular.module('home').controller('homeController', ['$scope', '$injector', $scope.rootConnectionGroup = rootConnectionGroup; }); - // Navigate to home page, if not already there - userPageService.getHomePage() - .then(function homePageRetrieved(homePage) { - $location.url(homePage.url); - }); - }]); diff --git a/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js b/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js index 456997774..837f4e632 100644 --- a/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js +++ b/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js @@ -62,6 +62,57 @@ angular.module('index').config(['$routeProvider', '$locationProvider', }]; + /** + * Redirects the user to their home page. This necessarily requires + * attempting to re-authenticate with the Guacamole server, as the user's + * credentials may have changed, and thus their most-appropriate home page + * may have changed as well. + * + * @param {Service} $injector + * The Angular $injector service. + * + * @returns {Promise} + * A promise which resolves successfully only after an attempt to + * re-authenticate and determine the user's proper home page has been + * made. + */ + var routeToUserHomePage = ['$injector', function routeToUserHomePage($injector) { + + // Required services + var $location = $injector.get('$location'); + var $q = $injector.get('$q'); + var userPageService = $injector.get('userPageService'); + + // Promise for redirection attempt + var redirect = $q.defer(); + + // Re-authenticate including any parameters in URL + $injector.invoke(updateCurrentToken) + .then(function tokenUpdateComplete() { + + // Redirect to home page + userPageService.getHomePage() + .then(function homePageRetrieved(homePage) { + $location.url(homePage.url); + }) + + // If retrieval of home page fails, assume '/' + ['catch'](function homePageFailed() { + $location.url('/'); + }) + + // Resolve promise in either case + ['finally'](function retrievalAttemptComplete() { + redirect.resolve(); + }); + + }); + + // Return promise that will resolve regardless of success/failure + return redirect.promise; + + }]; + // Configure each possible route $routeProvider @@ -71,7 +122,7 @@ angular.module('index').config(['$routeProvider', '$locationProvider', bodyClassName : 'home', templateUrl : 'app/home/templates/home.html', controller : 'homeController', - resolve : { updateCurrentToken: updateCurrentToken } + resolve : { routeToUserHomePage: routeToUserHomePage } }) // Connection management screen @@ -147,9 +198,7 @@ angular.module('index').config(['$routeProvider', '$locationProvider', // Redirect to home screen if page not found .otherwise({ - redirectTo : '/' + resolve : { routeToUserHomePage: routeToUserHomePage } }); }]); - - diff --git a/guacamole/src/main/webapp/app/index/indexModule.js b/guacamole/src/main/webapp/app/index/indexModule.js index 9f513b0d7..a1d927330 100644 --- a/guacamole/src/main/webapp/app/index/indexModule.js +++ b/guacamole/src/main/webapp/app/index/indexModule.js @@ -29,6 +29,7 @@ angular.module('index', [ 'home', 'login', 'manage', + 'navigation', 'ngRoute', 'ngTouch', 'notification',