Store the url that the user comes in on before auth in preAuthUrl

This commit is contained in:
Michael Abashian
2017-06-08 19:01:44 -04:00
parent fc312398cd
commit 7768106d3f
3 changed files with 17 additions and 11 deletions

View File

@@ -364,8 +364,7 @@ var tower = angular.module('Tower', [
if (!Authorization.getToken() || !Authorization.isUserLoggedIn()) { if (!Authorization.getToken() || !Authorization.isUserLoggedIn()) {
// User not authenticated, redirect to login page // User not authenticated, redirect to login page
$rootScope.lastPath = $location.path(); $cookies.put('preAuthUrl', $location.path());
$cookies.put('lastPath', $location.path());
$location.path('/login'); $location.path('/login');
} else { } else {
var lastUser = $cookies.getObject('current_user'), var lastUser = $cookies.getObject('current_user'),

View File

@@ -103,7 +103,7 @@ export default
Store('sessionTime', x); Store('sessionTime', x);
if ($cookies.getObject('current_user')) { if ($cookies.getObject('current_user')) {
$cookies.put( 'lastUser', $cookies.getObject('current_user').id); $rootScope.lastUser = $cookies.getObject('current_user').id;
} }
ConfigService.delete(); ConfigService.delete();
SocketService.disconnect(); SocketService.disconnect();

View File

@@ -62,7 +62,7 @@ export default ['$log', '$cookies', '$compile', '$rootScope',
Authorization, Alert, Wait, Timer, Empty, Authorization, Alert, Wait, Timer, Empty,
scope, pendoService, ConfigService, CheckLicense, FeaturesService, scope, pendoService, ConfigService, CheckLicense, FeaturesService,
SocketService) { SocketService) {
var lastPath, lastUser, sessionExpired, loginAgain; var lastPath, lastUser, sessionExpired, loginAgain, preAuthUrl;
loginAgain = function() { loginAgain = function() {
setTimeout(function() { setTimeout(function() {
@@ -80,8 +80,7 @@ export default ['$log', '$cookies', '$compile', '$rootScope',
}; };
lastUser = function(){ lastUser = function(){
let lastUser = $cookies.get('lastUser'); if(!Empty($rootScope.lastUser) && $rootScope.lastUser === $rootScope.current_user.id){
if(!Empty(lastUser) && parseInt(lastUser) === $rootScope.current_user.id){
return true; return true;
} }
else { else {
@@ -89,6 +88,8 @@ export default ['$log', '$cookies', '$compile', '$rootScope',
} }
}; };
preAuthUrl = $cookies.get('preAuthUrl');
$log.debug('User session expired: ' + sessionExpired); $log.debug('User session expired: ' + sessionExpired);
$log.debug('Last URL: ' + lastPath()); $log.debug('Last URL: ' + lastPath());
@@ -113,11 +114,17 @@ export default ['$log', '$cookies', '$compile', '$rootScope',
pendoService.issuePendoIdentity(); pendoService.issuePendoIdentity();
FeaturesService.get(); FeaturesService.get();
Wait("stop"); Wait("stop");
if (lastPath() && lastUser()) { if(!Empty(preAuthUrl)){
// Go back to most recent navigation path $location.path(preAuthUrl);
$location.path(lastPath()); $cookies.remove('preAuthUrl');
} else { }
$location.url('/home'); else {
if (lastPath() && lastUser()) {
// Go back to most recent navigation path
$location.path(lastPath());
} else {
$location.url('/home');
}
} }
}) })
.catch(function () { .catch(function () {