(function() {
angular.module('Auth', []);
angular.module('inspinia', [
'ui.router', // Routing
'oc.lazyLoad', // ocLazyLoad
'ui.bootstrap', // Ui Bootstrap
'pascalprecht.translate', // Angular Translate
'ngIdle', // Idle timer
'ngSanitize', // ngSanitize
'Auth' // Auth Module
]).run(function($rootScope, $location, $state, AuthSvc) {
$rootScope.$on('$stateChangeStart', function(e, toState, toParams, fromState, fromParams) {
var isLogin = toState.name === "login";
if (isLogin) {
return; // no need to redirect
}
// now, redirect only not authenticated
var userInfo = AuthSvc.getUserInfo();
if (userInfo.authenticated === false) {
e.preventDefault(); // stop current execution
$state.go('login'); // go to login
}
});
})
})();