Newer
Older
ubFramework / Portal / docroot / js / app.js
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 860 bytes Cleaning Up Making It A Sub Module
(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
      }
    });
  })
})();