2016-07-07 18:03:32 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2016-04-14 19:50:10 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.session')
|
2016-05-12 12:30:01 +02:00
|
|
|
.controller('CurrentUserController', CurrentUserController);
|
|
|
|
|
2016-06-25 21:12:17 +02:00
|
|
|
CurrentUserController.$inject = ['$scope', 'CurrentUserService', 'currentUser', '$window', '$document'];
|
2016-04-14 19:50:10 +02:00
|
|
|
|
2016-06-25 21:12:17 +02:00
|
|
|
function CurrentUserController($scope, CurrentUserService, currentUser, $window, $document) {
|
2016-05-10 12:43:52 +02:00
|
|
|
|
|
|
|
var vm = this;
|
2016-06-25 21:12:17 +02:00
|
|
|
|
2016-05-21 11:20:39 +02:00
|
|
|
CurrentUserService()
|
|
|
|
.then(getCurrentUserComplete)
|
|
|
|
.catch(getCurrentUserFailed);
|
|
|
|
|
2016-05-10 12:43:52 +02:00
|
|
|
function getCurrentUserComplete(response) {
|
2016-05-21 11:20:39 +02:00
|
|
|
if(angular.isDefined(response)) {
|
|
|
|
currentUser.set(response.data);
|
2016-06-21 12:42:53 +02:00
|
|
|
if(location.pathname === '/') {
|
|
|
|
$window.location.href = '/dashboard';
|
|
|
|
}
|
2016-05-21 11:20:39 +02:00
|
|
|
}
|
2016-04-14 19:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentUserFailed(e){
|
2016-07-05 03:06:36 +02:00
|
|
|
console.log('No session of current user.');
|
2016-05-20 11:43:47 +02:00
|
|
|
}
|
2016-04-14 19:50:10 +02:00
|
|
|
}
|
2016-05-12 12:30:01 +02:00
|
|
|
|
2016-04-14 19:50:10 +02:00
|
|
|
})();
|