Login redirect replaces page history

Story: 2001549
Task: 6490

Change-Id: I43afa711ab3c88a48af7d20eaf266f72777b1a4f
Signed-off-by: Ankita Bansal <ankitabansal2798@gmail.com>
This commit is contained in:
Ankita Bansal 2019-03-12 19:18:22 +05:30 committed by Adam Coldrick
parent 13984cb8de
commit d9d784e6c4
3 changed files with 30 additions and 37 deletions

View File

@ -22,8 +22,8 @@
*/
angular.module('sb.auth').controller('AuthTokenController',
function ($state, $log, OpenId, Session, $searchParams, $window, UrlUtil,
LastLocation) {
function ($state, $log, OpenId, Session, $searchParams, UrlUtil,
LastLocation) {
'use strict';
// First, check for the edge case where the API returns an error code

View File

@ -64,7 +64,8 @@ angular.module('storyboard',
}
});
})
.run(function ($log, $rootScope, $document) {
.run(function ($log, $rootScope, $document, $transitions,
LastLocation) {
'use strict';
var resolvingClassName = 'resolving';
@ -73,28 +74,28 @@ angular.module('storyboard',
// Apply a global class to the application when we're in the middle of
// a state resolution, as well as a global scope variable that UI views
// can switch on.
$rootScope.$on('$stateChangeStart', function () {
$transitions.onStart({}, function(transition){
body.addClass(resolvingClassName);
$rootScope.isResolving = true;
LastLocation.onStateChange(transition);
});
$rootScope.$on('$stateChangeSuccess', function () {
$transitions.onSuccess({}, function(){
body.removeClass(resolvingClassName);
$rootScope.isResolving = false;
});
$rootScope.$on('$stateChangeError', function () {
$transitions.onError({}, function(){
body.removeClass(resolvingClassName);
$rootScope.isResolving = false;
});
})
.run(function ($log, $rootScope, $state) {
.run(function ($log, $rootScope, $state, $transitions) {
'use strict';
// Listen to changes on the root scope. If it's an error in the state
// changes (i.e. a 404) take the user back to the index.
$rootScope.$on('$stateChangeError',
function () {
$state.go('sb.index');
});
$transitions.onError({}, function(){
return false;
});
})
.run(function ($http, DSCacheFactory) {
'use strict';

View File

@ -21,32 +21,6 @@ angular.module('sb.util').factory('LastLocation',
function ($rootScope, localStorageService, $state) {
'use strict';
/**
* onStateChange handler. Stores the next destination state, and its
* parameters, so we can keep revisit the history after bouncing out
* for authentication.
*
* @param event The state change event.
* @param toState The destination state.
* @param toParams The parameters for that destination state.
*/
function onStateChange(event, toState, toParams) {
if (toState.name.indexOf('sb.auth') === -1) {
var data = {
'name': toState.name,
'params': toParams
};
localStorageService.set('lastLocation',
angular.toJson(data));
}
}
// Add the listener to the application, remove it when the scope is
// destroyed.
$rootScope.$on('$destroy',
$rootScope.$on('$stateChangeStart', onStateChange)
);
// The published API.
return {
@ -64,6 +38,24 @@ angular.module('sb.util').factory('LastLocation',
last = angular.fromJson(last);
$state.go(last.name, last.params);
}
},
/**
* onStateChange handler. Stores the next destination state, and its
* parameters, so we can keep revisit the history after bouncing out
* for authentication.
*
* @param transition The transition to record the state from.
*/
onStateChange: function(transition) {
if (transition.$to().name.indexOf('sb.auth') === -1) {
var data = {
'name': transition.$to().name,
'params': transition.params()
};
localStorageService.set('lastLocation',
angular.toJson(data));
}
}
};
});