GUAC-1161: Reject attempts to visit '/' unless '/' is actually the home page. Redirect to true home page otherwise.

This commit is contained in:
Michael Jumper
2015-04-23 12:00:37 -07:00
parent 35c5d846ce
commit 7c542e8de8

View File

@@ -74,8 +74,8 @@ angular.module('index').config(['$routeProvider', '$locationProvider',
var $q = $injector.get('$q'); var $q = $injector.get('$q');
var userPageService = $injector.get('userPageService'); var userPageService = $injector.get('userPageService');
// Promise for redirection attempt // Promise for routing attempt
var redirect = $q.defer(); var route = $q.defer();
// Re-authenticate including any parameters in URL // Re-authenticate including any parameters in URL
$injector.invoke(updateCurrentToken) $injector.invoke(updateCurrentToken)
@@ -84,23 +84,29 @@ angular.module('index').config(['$routeProvider', '$locationProvider',
// Redirect to home page // Redirect to home page
userPageService.getHomePage() userPageService.getHomePage()
.then(function homePageRetrieved(homePage) { .then(function homePageRetrieved(homePage) {
$location.url(homePage.url);
// If home page is the requested location, allow through
if ($location.path() === homePage.url)
route.resolve();
// Otherwise, reject and reroute
else {
$location.url(homePage.url);
route.reject();
}
}) })
// If retrieval of home page fails, assume '/' // If retrieval of home page fails, assume requested page is OK
['catch'](function homePageFailed() { ['catch'](function homePageFailed() {
$location.url('/'); route.resolve();
})
// Resolve promise in either case
['finally'](function retrievalAttemptComplete() {
redirect.resolve();
}); });
}); });
// Return promise that will resolve regardless of success/failure // Return promise that will resolve only if the requested page is the
return redirect.promise; // home page
return route.promise;
}]; }];