//parent module
// inject children modules for access
angular.module('dibs', ['ngAnimate', 'ui.bootstrap', 'ui.router', 'eventsInfo', 'eventsInfoFactory', 'userInfo', 'userFactory', 'loginInfo', 'userloginFactory'])
  .config(function($stateProvider, $urlRouterProvider, $httpProvider) {
    $urlRouterProvider.otherwise('signup');
    $httpProvider.interceptors.push('AttachToken');
    //runs before reaching server and 
    //pushes the result of what we have defined with factory function

    $stateProvider
      .state('signupPage', {
        url: '/signup',
        views: {
          'indexPage': {
            templateUrl: 'views/signup.html',
            controller: 'userSignUp'
          }
        },
        data: {
          authenticate: false
        }
      })
      .state('dashboardPage', {
        url: '/dashboard',
        views: {
          'indexPage': {
            templateUrl: 'views/dashboard.html',
            controller: 'eventsController'
          }
        },
        data: {
          authenticate: true
        }
      })
      .state('dashboardPage.events', {
        url: '/events',
        templateUrl: 'views/eventListEmbedded.html',
        controller: 'eventsController',
        data: {
          authenticate: true
        }
      })
      .state('dashboardPage.eventsChart', {
        url: '/eventsChart',
        templateUrl: 'views/eventChart.html',
        controller: 'eventsController',
        data: {
          authenticate: true
        }
      })
      .state('loginupPage', {
        url: '/login',
        views: {
          'indexPage': {
            templateUrl: 'views/login.html',
            controller: 'userLogin'
          }
        },
        data: {
          authenticate: false
        }
      });
  })

.factory('AttachToken', function($window) {
  return {
    request: function(http) {
      var token = $window.localStorage.getItem('dibsToken');
      if (token) {
        http.headers["x-access-token"] = token;
      }
      http.headers["Allow-Control-Allow-Origin"] = "*";
      return http;
    }
  };
})

.run(function($state, $rootScope, SignUpFactory) {
  $rootScope.$on('$stateChangeStart', function(event, toState) {
    if (toState.data.authenticate === true && !SignUpFactory.validToken) {
      $state.go('signupPage');
      event.preventDefault();
    }
  });
});
@@ -277,24 +277,127 @@
 Provider) %7B%0A
+    //by default, tries to access dashboard%0A    //if there is no current user, will redirect to signup%0A
     $urlRout
@@ -418,22 +418,25 @@
 erwise('
-signup
+dashboard
 ');%0A    

change /dashboard to be root route