From 6e7aa1907393ce6042d64928e1072ceef6fd75ba Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 May 2015 09:00:43 +1000 Subject: [PATCH] Fixes U4-5213 in a better way using a query string so it's clear where it redirects to --- src/Umbraco.Web.UI.Client/src/init.js | 13 ++++++----- .../src/views/common/login.controller.js | 22 +++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/init.js b/src/Umbraco.Web.UI.Client/src/init.js index eb1bdfe2e8..d95c711e0e 100644 --- a/src/Umbraco.Web.UI.Client/src/init.js +++ b/src/Umbraco.Web.UI.Client/src/init.js @@ -2,7 +2,6 @@ app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', 'appState', 'editorState', 'fileManager', 'assetsService', 'eventsService', '$cookies', '$templateCache', function (userService, $log, $rootScope, $location, navigationService, appState, editorState, fileManager, assetsService, eventsService, $cookies, $templateCache) { - //This sets the default jquery ajax headers to include our csrf token, we // need to user the beforeSend method because our token changes per user/login so // it cannot be static @@ -16,8 +15,10 @@ app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', eventsService.on("app.authenticated", function(evt, data) { assetsService._loadInitAssets().then(function() { appState.setGlobalState("isReady", true); - //send the ready event + + //send the ready event with the included returnToPath,returnToSearch data eventsService.emit("app.ready", data); + returnToPath = null, returnToSearch = null; }); }); @@ -44,9 +45,11 @@ app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', wiring up it's controller, etc... and then redirect to the rejected URL. */ $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { event.preventDefault(); - $rootScope.returnToPath = $location.$$path; - $rootScope.returnToSearch = $location.$$search; - $location.path(rejection.path).search(rejection.search); + + //Set the current path before redirecting so we know where to redirect back to + var returnPath = encodeURIComponent($location.url()); + + $location.path(rejection.path).search("returnPath", returnPath); }); diff --git a/src/Umbraco.Web.UI.Client/src/views/common/login.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/login.controller.js index 59d8f6bf57..4f78632be5 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/login.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/login.controller.js @@ -3,8 +3,22 @@ angular.module('umbraco').controller("Umbraco.LoginController", function (events userService._showLoginDialog(); - eventsService.on("app.ready", function(){ - $scope.avatar = "assets/img/application/logo.png"; - $location.path($rootScope.returnToPath || "/").search($rootScope.returnToSearch || ""); + var evtOn = eventsService.on("app.ready", function(evt, data){ + $scope.avatar = "assets/img/application/logo.png"; + + var path = "/"; + + //check if there's a returnPath query string, if so redirect to it + var locationObj = $location.search(); + if (locationObj.returnPath) { + path = decodeURIComponent(locationObj.returnPath); + } + + $location.url(path); }); -}); \ No newline at end of file + + $scope.$on('$destroy', function () { + eventsService.unsubscribe(evtOn); + }); + +});