diff --git a/app/common/auth/authentication-events.run.js b/app/common/auth/authentication-events.run.js index 33ebdef06e..1ebdc00df5 100644 --- a/app/common/auth/authentication-events.run.js +++ b/app/common/auth/authentication-events.run.js @@ -1,7 +1,7 @@ module.exports = AuthenticationEvents; -AuthenticationEvents.$inject = ['$rootScope', '$location', 'Authentication', 'Session', '_']; -function AuthenticationEvents($rootScope, $location, Authentication, Session, _) { +AuthenticationEvents.$inject = ['$rootScope', '$location', 'Authentication', 'Session', '_', '$route']; +function AuthenticationEvents($rootScope, $location, Authentication, Session, _, $route) { $rootScope.currentUser = null; $rootScope.loggedin = false; @@ -23,6 +23,7 @@ function AuthenticationEvents($rootScope, $location, Authentication, Session, _) if (redirect) { $location.url(redirect); } + $route.reload(); } function doLogout(redirect) { @@ -31,6 +32,7 @@ function AuthenticationEvents($rootScope, $location, Authentication, Session, _) if (redirect) { $location.url(redirect); } + $route.reload(); } // todo: move to service @@ -54,11 +56,11 @@ function AuthenticationEvents($rootScope, $location, Authentication, Session, _) }; $rootScope.$on('event:authentication:login:succeeded', function () { - doLogin(Session.getSessionDataEntry('loginPath') || '/'); + doLogin(Session.getSessionDataEntry('loginPath')); }); $rootScope.$on('event:authentication:logout:succeeded', function () { - doLogout('/'); + doLogout(); }); // Don't think this is needed. We should already be logged out before this event @@ -83,6 +85,8 @@ function AuthenticationEvents($rootScope, $location, Authentication, Session, _) // We're logged out, redirect to login if ($location.url() !== '/login') { Session.setSessionDataEntry('loginPath', $location.url()); + // We're logged in hit forbidden page + $location.url('/forbidden'); } Authentication.openLogin(); } diff --git a/test/unit/common/auth/authentication-events.run.spec.js b/test/unit/common/auth/authentication-events.run.spec.js index d4e7c5abb6..a57c062941 100644 --- a/test/unit/common/auth/authentication-events.run.spec.js +++ b/test/unit/common/auth/authentication-events.run.spec.js @@ -6,7 +6,10 @@ describe('global event handlers', function () { mockedAuthenticationData, mockedAuthenticationService, $rootScope, - $location; + $location, + mockRoute = { + reload: jasmine.createSpy() + }; beforeEach(function () { @@ -46,7 +49,10 @@ describe('global event handlers', function () { .service('Authentication', function () { return mockedAuthenticationService; }) - .run(require(rootPath + 'app/common/auth/authentication-events.run.js')); + .run(require(rootPath + 'app/common/auth/authentication-events.run.js')) + .service('$route', function () { + return mockRoute; + }); require(rootPath + 'test/unit/simple-test-app-config.js')(testApp); }); @@ -92,8 +98,8 @@ describe('global event handlers', function () { expect($rootScope.loggedin).toBe(true); }); - it('should change the path to "/"', function () { - expect($location.path()).toEqual('/'); + it('should reload the route', function () { + expect(mockRoute.reload).toHaveBeenCalled(); }); }); @@ -129,8 +135,8 @@ describe('global event handlers', function () { expect($rootScope.loggedin).toBe(false); }); - it('should change the path to "/"', function () { - expect($location.path()).toEqual('/'); + it('should reload the route', function () { + expect(mockRoute.reload).toHaveBeenCalled(); }); }); });