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);
|
|
|
|
|
|
|
|
CurrentUserController.$inject = ['CurrentUserService', 'currentUser', '$scope', '$timeout', '$window'];
|
2016-04-14 19:50:10 +02:00
|
|
|
|
2016-05-12 12:30:01 +02:00
|
|
|
function CurrentUserController(CurrentUserService, currentUser, $scope, $timeout, $window) {
|
2016-05-10 12:43:52 +02:00
|
|
|
|
|
|
|
var vm = this;
|
2016-04-14 19:50:10 +02:00
|
|
|
|
|
|
|
CurrentUserService()
|
|
|
|
.then(getCurrentUserComplete)
|
|
|
|
.catch(getCurrentUserFailed);
|
|
|
|
|
2016-05-10 12:43:52 +02:00
|
|
|
function getCurrentUserComplete(response) {
|
|
|
|
console.log('Successful logged in.');
|
|
|
|
$timeout(function(){
|
|
|
|
$scope.$broadcast('currentUser', response.data);
|
2016-05-11 09:57:52 +02:00
|
|
|
currentUser.set(response.data);
|
2016-05-10 12:43:52 +02:00
|
|
|
}, 50);
|
2016-04-14 19:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentUserFailed(e){
|
2016-05-12 12:30:01 +02:00
|
|
|
var url = location.pathname;
|
|
|
|
var exclusions = ['/ng', '/ng/forgot_password', '/ng/sign_up', '/ng/reset_password'];
|
|
|
|
for(var i = 0; i < exclusions.length; i++) {
|
|
|
|
if(exclusions[i]===url) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-14 07:34:54 +02:00
|
|
|
}
|
2016-05-12 12:30:01 +02:00
|
|
|
$window.location.href = '/ng';
|
2016-04-14 19:50:10 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 12:30:01 +02:00
|
|
|
|
2016-04-14 19:50:10 +02:00
|
|
|
})();
|