<commit_before>(function() {
  'use strict';

  angular
    .module('sslv2App', [
      'ui.router',
      'ui.bootstrap',
      'ui.mask',
      'ngCookies',
      'ui.gravatar',
      'angular-confirm',
      'ngIdle',
      'ngSanitize',
      'ngTagsInput',
      'ui.multiselect',
      'fsm',
      'ui.codemirror',
      'angularMoment',
      'pascalprecht.translate',
      'tmh.dynamicLocale',
      'easypiechart',

    ])
    .factory('headerInjector', [function() {
      var headerInjector = {
        request: function(config) {
          config.headers['X-Cbo-Client-Url'] = 'http://demo.ssl.s360.is';
          return config;
        }
      };
      return headerInjector;
    }])
    .config(configFunction)
    .run(runFunction);

  configFunction.$inject = ['$httpProvider','$urlRouterProvider','gravatarServiceProvider','KeepaliveProvider','IdleProvider','$locationProvider','$translateProvider','tmhDynamicLocaleProvider'];

  function configFunction($httpProvider,$urlRouterProvider,gravatarServiceProvider,KeepaliveProvider,IdleProvider,$locationProvider,$translateProvider,tmhDynamicLocaleProvider) {
      tmhDynamicLocaleProvider.localeLocationPattern('bower_components/angular-i18n/angular-locale_{{locale}}.js');
      $translateProvider.useMissingTranslationHandlerLog();
      $translateProvider.useSanitizeValueStrategy('sanitize');
      $translateProvider.useStaticFilesLoader({
          prefix: 'resources/locale-',
          suffix: '.json'
      });
      $translateProvider.preferredLanguage('en_US');
      $translateProvider.useLocalStorage();
      $translateProvider.useMissingTranslationHandlerLog();
    $urlRouterProvider.otherwise("/login");
    $httpProvider.defaults.headers.common = {};
    $httpProvider.defaults.headers.get = {};
    $httpProvider.defaults.headers.post = {};
    $httpProvider.defaults.headers.put = {};
    $httpProvider.defaults.headers.patch = {};
    $httpProvider.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
    $httpProvider.defaults.headers.common.Accept = '*/*';
    //$httpProvider.interceptors.push('headerInjector');
    $httpProvider.defaults.timeout = 15000;
    gravatarServiceProvider.defaults = {
      size     : 50,
      "default": 'mm'
    };
      $httpProvider.interceptors.push(function ($q,ProfileService,$location) {
          return {
              'response': function (response) {
                  if (response.status === 401) {
                      sessionStorage.clear();
                      ProfileService.clear();
                      $location.path('/login');
                  }
                  return response || $q.when(response);
              },
              'responseError': function (rejection) {
                  if (rejection.status === 401) {
                      sessionStorage.clear();
                      ProfileService.clear();
                      $location.path('/login');
                  }
                  return $q.reject(rejection);
              }
          };
      });
    // IdleProvider.idle(5); // in seconds
    // IdleProvider.timeout(10); // in seconds
    // KeepaliveProvider.interval(1); // in seconds
  }

  runFunction.$inject = ['$rootScope', '$state', 'RESOURCES','$cookies','Idle','PROTECTED_PATHS'];

  function runFunction($rootScope, $state, RESOURCES,$cookies,Idle,PROTECTED_PATHS) {
    // Idle.watch();
    $rootScope.$on('$stateChangeError',
      function(event, toState, toParams, fromState, fromParams, error) {

        if (error === "AUTH_REQUIRED") {
          $state.go('login');
        }

      });
    // $rootScope.$on('IdleStart', function() {
    //     console.log("idle start");
    // });
    // $rootScope.$on('IdleEnd', function() {
    //     console.log("idleEnd");
    // });
    //  $rootScope.$on('Keepalive', function() {
    //     console.log("keepalive");
    // });

    //   $rootScope.$on('IdleTimeout', function() {
    //   console.log("timeout");
    //   });
    //   $rootScope.$on('IdleWarn', function(e, countdown) {
    //     console.log("idle warn");
    // });

      $rootScope.$on('$stateNotFound',
        function(event, unfoundState, fromState, fromParams){
          console.log(unfoundState);
        })



    $rootScope.$on('$stateChangeStart',
      function(event, toState, toParams, fromState, fromParams, options) {
      var profile;
          if(sessionStorage.getItem('id') === null){
            profile = {
              is_authenticated:false
            }
          }else{
            profile = $cookies.getObject(sessionStorage.getItem('id'));
          }
              if(toState.name !== 'login' && toState.name !== 'forgot' && toState.name !== 'reset' && toState.name !=='submission'){
                  localStorage.setItem('path',toState.name);
              }

              // for(var key in localStorage){
              //     switch (key){
              //         case "id":
              //             localStorage.removeItem(key)
              //             break;
              //         case "student_id":
              //             localStorage.removeItem(key)
              //             break;
              //     }
              // }
              if(typeof toParams === 'object'){
                  _.forEach(toParams,function (v,k) {
                      localStorage.setItem(k,v);
                  })
              }

        if(toState.name !== "dashboard" && toState.name !== "login" && toState.name !== "forgot"){
            $rootScope.currentURL = toState.name.replace('dashboard.','') + '-page';
        }else{
            $rootScope.currentURL = toState.name.replace('/','') + '-page';
        }
        if (!profile.is_authenticated && pathIsProtected(toState.url)) {
          event.preventDefault();
          $state.go('login', {}, {reload: true});
        }


      });

    function pathIsProtected(path) {
      return PROTECTED_PATHS.indexOf(path) !== -1;
    }

  }



})();
<commit_msg>modify code for handling interceptor in local environtment<commit_after>(function() {
  'use strict';

  angular
    .module('sslv2App', [
      'ui.router',
      'ui.bootstrap',
      'ui.mask',
      'ngCookies',
      'ui.gravatar',
      'angular-confirm',
      'ngIdle',
      'ngSanitize',
      'ngTagsInput',
      'ui.multiselect',
      'fsm',
      'ui.codemirror',
      'angularMoment',
      'pascalprecht.translate',
      'tmh.dynamicLocale',
      'easypiechart',

    ])
    .factory('headerInjector', headerInjector)
    .config(configFunction)
    .run(runFunction);

  headerInjector.$inject = ['RESOURCES'];

  function headerInjector(RESOURCES) {
      var headerInjector = {
          request: function(config) {
              config.headers['X-Cbo-Client-Url'] = RESOURCES.LOCAL;
              return config;
          }
      };
      return headerInjector;
  }

  configFunction.$inject = ['$httpProvider','$urlRouterProvider','gravatarServiceProvider','KeepaliveProvider','IdleProvider','$locationProvider','$translateProvider','tmhDynamicLocaleProvider','RESOURCES'];

  function configFunction($httpProvider,$urlRouterProvider,gravatarServiceProvider,KeepaliveProvider,IdleProvider,$locationProvider,$translateProvider,tmhDynamicLocaleProvider,RESOURCES) {
      tmhDynamicLocaleProvider.localeLocationPattern('bower_components/angular-i18n/angular-locale_{{locale}}.js');
      $translateProvider.useMissingTranslationHandlerLog();
      $translateProvider.useSanitizeValueStrategy('sanitize');
      $translateProvider.useStaticFilesLoader({
          prefix: 'resources/locale-',
          suffix: '.json'
      });
      $translateProvider.preferredLanguage('en_US');
      $translateProvider.useLocalStorage();
      $translateProvider.useMissingTranslationHandlerLog();
    $urlRouterProvider.otherwise("/login");
    $httpProvider.defaults.headers.common = {};
    $httpProvider.defaults.headers.get = {};
    $httpProvider.defaults.headers.post = {};
    $httpProvider.defaults.headers.put = {};
    $httpProvider.defaults.headers.patch = {};
    $httpProvider.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
    $httpProvider.defaults.headers.common.Accept = '*/*';
    if(RESOURCES.LOCAL !== ""){
        $httpProvider.interceptors.push('headerInjector');
    }
    $httpProvider.defaults.timeout = 15000;
    gravatarServiceProvider.defaults = {
      size     : 50,
      "default": 'mm'
    };
      $httpProvider.interceptors.push(function ($q,ProfileService,$location) {
          return {
              'response': function (response) {
                  if (response.status === 401) {
                      sessionStorage.clear();
                      ProfileService.clear();
                      $location.path('/login');
                  }
                  return response || $q.when(response);
              },
              'responseError': function (rejection) {
                  if (rejection.status === 401) {
                      sessionStorage.clear();
                      ProfileService.clear();
                      $location.path('/login');
                  }
                  return $q.reject(rejection);
              }
          };
      });
    // IdleProvider.idle(5); // in seconds
    // IdleProvider.timeout(10); // in seconds
    // KeepaliveProvider.interval(1); // in seconds
  }

  runFunction.$inject = ['$rootScope', '$state', 'RESOURCES','$cookies','Idle','PROTECTED_PATHS'];

  function runFunction($rootScope, $state, RESOURCES,$cookies,Idle,PROTECTED_PATHS) {
    // Idle.watch();
    $rootScope.$on('$stateChangeError',
      function(event, toState, toParams, fromState, fromParams, error) {

        if (error === "AUTH_REQUIRED") {
          $state.go('login');
        }

      });
    // $rootScope.$on('IdleStart', function() {
    //     console.log("idle start");
    // });
    // $rootScope.$on('IdleEnd', function() {
    //     console.log("idleEnd");
    // });
    //  $rootScope.$on('Keepalive', function() {
    //     console.log("keepalive");
    // });

    //   $rootScope.$on('IdleTimeout', function() {
    //   console.log("timeout");
    //   });
    //   $rootScope.$on('IdleWarn', function(e, countdown) {
    //     console.log("idle warn");
    // });

      $rootScope.$on('$stateNotFound',
        function(event, unfoundState, fromState, fromParams){
          console.log(unfoundState);
        })



    $rootScope.$on('$stateChangeStart',
      function(event, toState, toParams, fromState, fromParams, options) {
      var profile;
          if(sessionStorage.getItem('id') === null){
            profile = {
              is_authenticated:false
            }
          }else{
            profile = $cookies.getObject(sessionStorage.getItem('id'));
          }
              if(toState.name !== 'login' && toState.name !== 'forgot' && toState.name !== 'reset' && toState.name !=='submission'){
                  localStorage.setItem('path',toState.name);
              }

              // for(var key in localStorage){
              //     switch (key){
              //         case "id":
              //             localStorage.removeItem(key)
              //             break;
              //         case "student_id":
              //             localStorage.removeItem(key)
              //             break;
              //     }
              // }
              if(typeof toParams === 'object'){
                  _.forEach(toParams,function (v,k) {
                      localStorage.setItem(k,v);
                  })
              }

        if(toState.name !== "dashboard" && toState.name !== "login" && toState.name !== "forgot"){
            $rootScope.currentURL = toState.name.replace('dashboard.','') + '-page';
        }else{
            $rootScope.currentURL = toState.name.replace('/','') + '-page';
        }
        if (!profile.is_authenticated && pathIsProtected(toState.url)) {
          event.preventDefault();
          $state.go('login', {}, {reload: true});
        }


      });

    function pathIsProtected(path) {
      return PROTECTED_PATHS.indexOf(path) !== -1;
    }

  }



})();

{'fraction_non_alphanumeric': 0.15579829172141918, 'fraction_numerical': 0.0036957950065703024, 'mean_word_length': 2.0898249175336208, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2835641', 'n_tokens_mistral': 3487, 'n_tokens_neox': 3365, 'n_words': 444}