text: ﻿(function () {
      'use strict';
  
      angular
          .module('greenApp', ['ngRoute', 'ngCookies'])
          .config(config)
          .constant('urls', {
          BASE: 'http://localhost:8080/',
          USER_SERVICE_API : 'http://localhost:8080/app/'
      })
          .run(run);
  
        //  sportsApp.constant('urls', {
          //BASE: 'http://localhost:8080/SportsManager',
          //USER_SERVICE_API : 'http://localhost:8080/SportsManager/api/user/'
    //  });
  
      config.$inject = ['$routeProvider', '$locationProvider'];
      function config($routeProvider, $locationProvider) {
          $routeProvider
              .when('/', {
                  controller: 'HomeController',
                  templateUrl: 'home/home.view.html',
                  controllerAs: 'vm'
              })
  
              .when('/login', {
                  controller: 'LoginController',
                  templateUrl: 'login/login.view.html',
                  controllerAs: 'vm'
              })
  
              .when('/register', {
                  controller: 'RegisterController',
                  templateUrl: 'register/register.view.html',
                  controllerAs: 'vm'
              })
  
              .otherwise({ redirectTo: '/login' });
      }
  
      run.$inject = ['$rootScope', '$location', '$cookies', '$http'];
      function run($rootScope, $location, $cookies, $http) {
          // keep user logged in after page refresh
          $rootScope.globals = $cookies.getObject('globals') || {};
          if ($rootScope.globals.currentUser) {
              $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata;
          }
  
          $rootScope.$on('$locationChangeStart', function (event, next, current) {
              // redirect to login page if not logged in and trying to access a restricted page
              var restrictedPage = $.inArray($location.path(), ['/login', '/register']) === -1;
              var loggedIn = $rootScope.globals.currentUser;
              if (restrictedPage && !loggedIn) {
                  $location.path('/login');
              }
          });
      }
  
  })();
  