Newer
Older
ubFramework / Portal / docroot / assets / js / app.js
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 1 KB Cleaning Up Making It A Sub Module
/**
 * INSPINIA - Responsive Admin Theme
 * 
 */
(function() {
  
  //angular.module('Authentication', []);
  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'

  ]).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();
      
      alert('TEST: ' + userInfo.authenticated);

      if (userInfo.authenticated === false) {
        e.preventDefault(); // stop current execution
        $state.go('login_two_columns'); // go to login
      }
    });
  })
})();

// Other libraries are loaded dynamically in the config.js file using the
// library ocLazyLoad