Merge branch 'oauth3' of git.daplie.com:Daplie/walnut_launchpad into oauth3
This commit is contained in:
commit
a0b5076dc5
23
js/app.js
23
js/app.js
|
@ -8,13 +8,13 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
|
||||||
$urlRouterProvider.otherwise('/splash-page');
|
$urlRouterProvider.otherwise('/splash-page');
|
||||||
$stateProvider
|
$stateProvider
|
||||||
.state('splash-page', {
|
.state('splash-page', {
|
||||||
data: { requiresLogin: false },
|
data: { requiresLogin: false, session: null },
|
||||||
url: '/splash-page',
|
url: '/splash-page',
|
||||||
templateUrl: '/templates/splash-page.html',
|
templateUrl: '/templates/splash-page.html',
|
||||||
controller: 'loginCtrl as vm'
|
controller: 'loginCtrl as vm'
|
||||||
})
|
})
|
||||||
.state('app',{
|
.state('app',{
|
||||||
data: { requiresLogin: true },
|
data: { requiresLogin: true, session: null },
|
||||||
url: '/',
|
url: '/',
|
||||||
controller: 'loginCtrl as vm',
|
controller: 'loginCtrl as vm',
|
||||||
views: {
|
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.urlArray = [];
|
||||||
|
|
||||||
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
|
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
|
||||||
var requiresLogin = toState.data.requiresLogin;
|
var requiresLogin = toState.data.requiresLogin;
|
||||||
|
toState.data.session = $location.search();
|
||||||
$rootScope.redirectedURL = toState.url;
|
$rootScope.redirectedURL = toState.url;
|
||||||
|
var query = $location.search();
|
||||||
$rootScope.urlArray.push($rootScope.redirectedURL);
|
$rootScope.urlArray.push($rootScope.redirectedURL);
|
||||||
if ($rootScope.urlArray.length > 1) {
|
|
||||||
$rootScope.redirectedURL = $rootScope.urlArray[0];
|
|
||||||
$rootScope.urlArray = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiresLogin && !Auth.isLoggedIn()) {
|
if (requiresLogin && !Auth.isLoggedIn()) {
|
||||||
event.preventDefault();
|
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 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
app.controller('loginCtrl', [
|
app.controller('loginCtrl', [
|
||||||
'$scope', '$timeout', 'Auth', '$location', 'localStorageService', '$rootScope', 'azp@oauth3.org'
|
'$scope', '$timeout', 'Auth', '$location', 'localStorageService', '$rootScope', 'azp@oauth3.org', '$stateParams'
|
||||||
, function ($scope, $timeout, Auth, $location, localStorageService, $rootScope, Oauth3) {
|
, function ($scope, $timeout, Auth, $location, localStorageService, $rootScope, Oauth3, $stateParams) {
|
||||||
|
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue