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-05-12 12:30:01 +02:00
|
|
|
var url = location.pathname;
|
2016-05-20 11:43:47 +02:00
|
|
|
var exclusions = [
|
2016-06-16 08:10:35 +02:00
|
|
|
'/',
|
|
|
|
'/forgot_password',
|
|
|
|
'/sign_up',
|
|
|
|
'/reset_password',
|
|
|
|
'/search'
|
2016-05-20 11:43:47 +02:00
|
|
|
];
|
2016-05-12 12:30:01 +02:00
|
|
|
for(var i = 0; i < exclusions.length; i++) {
|
|
|
|
if(exclusions[i]===url) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-14 07:34:54 +02:00
|
|
|
}
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = '/';
|
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
|
|
|
})();
|