Merge branch 'oauth3' of git.daplie.com:Daplie/walnut_launchpad into oauth3

This commit is contained in:
aj 2017-08-30 19:24:13 +00:00
commit a0b5076dc5
2 changed files with 15 additions and 12 deletions

View File

@ -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 });
}
}
});
}]);

View File

@ -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;