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
|
|
|
})();
|