diff --git a/js/app.js b/js/app.js index c445ea1..e6e332d 100644 --- a/js/app.js +++ b/js/app.js @@ -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 }); + } }); }]); diff --git a/js/controllers/signInController.js b/js/controllers/signInController.js index 82bbe47..df01901 100644 --- a/js/controllers/signInController.js +++ b/js/controllers/signInController.js @@ -10,5 +10,6 @@ app.controller('SignInController', ['$scope', 'Auth', '$location', 'localStorage return localStorageService.set('userAuth', JSON.stringify(userInfo)); }(); }; - + + }]); diff --git a/js/services/auth.js b/js/services/auth.js index 4dfdf6d..3d8280a 100644 --- a/js/services/auth.js +++ b/js/services/auth.js @@ -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'));