diff --git a/js/app.js b/js/app.js index 6e04297..a3dd002 100644 --- a/js/app.js +++ b/js/app.js @@ -8,13 +8,13 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider $urlRouterProvider.otherwise('/splash-page'); $stateProvider .state('splash-page', { - data: { requiresLogin: false }, + data: { requiresLogin: false, session: null }, url: '/splash-page', templateUrl: '/templates/splash-page.html', controller: 'loginCtrl as vm' }) .state('app',{ - data: { requiresLogin: true }, + data: { requiresLogin: true, session: null }, url: '/', controller: 'loginCtrl as vm', views: { @@ -112,21 +112,24 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider }); }]); -app.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) { +app.run(['$rootScope', '$state', 'Auth', '$location', function($rootScope, $state, Auth, $location) { $rootScope.urlArray = []; - $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { var requiresLogin = toState.data.requiresLogin; + toState.data.session = $location.search(); $rootScope.redirectedURL = toState.url; + var query = $location.search(); $rootScope.urlArray.push($rootScope.redirectedURL); - if ($rootScope.urlArray.length > 1) { - $rootScope.redirectedURL = $rootScope.urlArray[0]; - $rootScope.urlArray = []; - } - if (requiresLogin && !Auth.isLoggedIn()) { event.preventDefault(); - $state.go('splash-page', { 'toState': toState.name }); + if (!angular.equals(toState.data.session, {})) { + toState.data.session.token = OAUTH3.jwt.decode(query.access_token); + toState.data.session.refresh = OAUTH3.jwt.decode(query.refresh_token); + Auth.add(query); + $state.go('app.' + $rootScope.redirectedURL); + } else { + $state.go('splash-page', { 'toState': toState.name }); + } } }); }]); diff --git a/js/controllers/login-controller.js b/js/controllers/login-controller.js index 9e06ebf..2e13dde 100644 --- a/js/controllers/login-controller.js +++ b/js/controllers/login-controller.js @@ -1,6 +1,6 @@ app.controller('loginCtrl', [ - '$scope', '$timeout', 'Auth', '$location', 'localStorageService', '$rootScope', 'azp@oauth3.org' -, function ($scope, $timeout, Auth, $location, localStorageService, $rootScope, Oauth3) { + '$scope', '$timeout', 'Auth', '$location', 'localStorageService', '$rootScope', 'azp@oauth3.org', '$stateParams' +, function ($scope, $timeout, Auth, $location, localStorageService, $rootScope, Oauth3, $stateParams) { var vm = this;