redirect almost working

This commit is contained in:
Jon Lambson 2017-08-10 16:33:54 -06:00
parent 3abdf1a606
commit 9788e73afb
3 changed files with 29 additions and 19 deletions

View File

@ -1,4 +1,5 @@
var app = angular.module('launchpad', ['ui.router', 'LocalStorageModule']);
var redirectedURL;
app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function($stateProvider, $urlRouterProvider, localStorageServiceProvider){
localStorageServiceProvider.setPrefix('launchpad').setStorageType('sessionStorage');
@ -9,13 +10,15 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
.state('splash-page', {
data: { 'requiresLogin': false },
params: {
'toState': 'launchpad-home', // default state to proceed to after login
'toParams': {}
// 'toState': 'launchpad-home',
'toParams': {
}
},
url: '/splash-page',
templateUrl: '/templates/splash-page.html',
})
.state('app',{
data: { 'requiresLogin': true },
url: '/launchpad-',
views: {
'header': {
@ -33,11 +36,6 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
templateUrl: '/templates/partials/notifications.html'
}
},
data: { 'requiresLogin': true },
params: {
'toState': '',
'toParams': {}
}
})
.state('app.home', {
url: 'home',
@ -129,7 +127,6 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
app.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) {
// Change title based on the `data` object in routes
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
console.log('toState', toState);
console.log('toParams', toParams);
@ -138,17 +135,20 @@ app.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) {
var requiresLogin = toState.data.requiresLogin;
if (requiresLogin && !Auth.isLoggedIn()) {
event.preventDefault();
$state.go('splash-page', {'toState': toState.name, 'toParams': toParams});
redirectedURL = toState.url;
console.log("%c" + redirectedURL, "color: yellow; font-size: 72px;");
if (Auth.isLoggedIn()) {
console.log('yes');
} else {
// if ($state.params.toState === undefined && $state.params.toParams === undefined) {
// console.log('set a route');
// }
console.log('TOSTATE: ',$state.params.toState);
console.log('TOPARAMS: ',$state.params.toParams);
// $state.go($state.params.toState, $state.params.toParams);
console.log('not logged in');
}
if (requiresLogin && !Auth.isLoggedIn()) {
event.preventDefault();
$state.go('splash-page');
// $state.go('splash-page', { 'toState': toState.name, 'toParams': toParams });
}
});
}]);

View File

@ -11,4 +11,5 @@ app.controller('SignInController', ['$scope', 'Auth', '$location', 'localStorage
}();
};
}]);

View File

@ -1,8 +1,17 @@
app.factory('Auth', ['localStorageService', function(localStorageService){
app.factory('Auth', ['localStorageService', '$location', function(localStorageService, $location) {
var user;
return{
setUser : function(currentUser){
user = currentUser;
console.log("%c" + redirectedURL, "color: red; font-size: 72px;");
if (redirectedURL === '/splash-page') {
$location.path('/launchpad-home');
} else {
$location.path('/launchpad-' + redirectedURL);
}
},
isLoggedIn : function(){
user = JSON.parse(localStorageService.get('userAuth'));