harbor/static/resources/js/session/session.current-user.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-04-14 19:50:10 +02:00
(function() {
'use strict';
angular
.module('harbor.session')
.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) {
var vm = this;
2016-06-25 21:12:17 +02:00
CurrentUserService()
.then(getCurrentUserComplete)
.catch(getCurrentUserFailed);
function getCurrentUserComplete(response) {
if(angular.isDefined(response)) {
currentUser.set(response.data);
if(location.pathname === '/') {
$window.location.href = '/dashboard';
}
}
2016-04-14 19:50:10 +02:00
}
function getCurrentUserFailed(e){
var url = location.pathname;
var exclusions = [
'/',
'/forgot_password',
'/sign_up',
'/reset_password',
'/search',
'/repository'
];
for(var i = 0; i < exclusions.length; i++) {
if(exclusions[i]===url) {
return;
}
2016-05-14 07:34:54 +02:00
}
$window.location.href = '/';
}
2016-04-14 19:50:10 +02:00
}
2016-04-14 19:50:10 +02:00
})();