(function () { 'use strict'; angular .module('codeMowing.client') .run(runFunction); /* @ngInject */ function runFunction($rootScope, $state, $log, $anchorScroll, $window, $interval, Auth, $cookies, WEB_API) { // default redirect if access is denied function redirectError() { $state.go('main.home'); } $rootScope.$on('$stateChangeError', redirectError); if ($window.location.hash === '#_=_') { $window.location.hash = ''; } $rootScope.$on("$destroy", function () { if (angular.isDefined($rootScope.interval)) { $interval.cancel($rootScope.interval); } }); $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { if (angular.isDefined($rootScope.interval)) { $interval.cancel($rootScope.interval); } var employeeInfo = $cookies.getObject("employeeInfo"); if (employeeInfo != null) { $rootScope.iniEmplyoeeName = employeeInfo.name; $rootScope.iniEmplyoeeEmail = employeeInfo.email; $rootScope.iniEmplyoeeRole_name = employeeInfo.role_name; } Auth.isLoggedIn(_.noop) .then(function (logInfo) { // $log.debug('isLoggedIn: ' + logInfo); if (logInfo) { $rootScope.isLoginedState = true; if (employeeInfo == null) { $rootScope.isLoginedState = false; $rootScope.isAdminState = false; $rootScope.isVerifyManager = false; $rootScope.isSiteManager = false; } else { Auth.hasRole('serverManager') .then(function (data) { $rootScope.isAdminState = data; $rootScope.checkAdmin = false; // $state.go("main.noticeBoard"); }).catch(function (err) { $log.debug(err); }); Auth.hasRole('verifyManager') .then(function (data) { $rootScope.isVerifyManager = data; $rootScope.checkVerifyManager = false; // $state.go("main.noticeBoard"); }).catch(function (err) { $log.debug(err); }); Auth.hasRole('siteManager') .then(function (data) { $rootScope.isSiteManager = data; $rootScope.checkSiteManager = false; // $state.go("main.noticeBoard"); }).catch(function (err) { $log.debug(err); }); } if (toState.url === '/') { $state.go("main.home"); } } else { /*if(toState.url != '/join_Member'){ $state.go("main.login_Member"); }*/ if (toState.url !== '/') { if (toState.url !== '/join_Member') { $state.go("main.login"); } } $rootScope.isLoginedState = false; $rootScope.isAdminState = false; $rootScope.isVerifyManager = false; $rootScope.isSiteManager = false; } }); $anchorScroll('header'); }); $rootScope.$watch(function () { return $rootScope.isLoginedState; }, function (value) { }); } })();