{"size": 1474, "ext": "js", "max_stars_repo_path": "client/app/app.js", "max_stars_repo_name": "agundy/canary-project", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/app/app.js", "max_issues_repo_name": "agundy/canary-project", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/app/app.js", "max_forks_repo_name": "agundy/canary-project", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.5, "max_line_length": 80, "alphanum_fraction": 0.5698778833}
//Manages general interaction with a session of the Canary application

//Establishes an Angular module to hold session information
var app = angular.module('app', [
        'ngRoute',
        'ngCookies',
        'ngResource'
])
.config(function($routeProvider, $locationProvider, $httpProvider){
    //Configuration for page redirection and loading
    $locationProvider.html5Mode(true);
    $routeProvider
        .when('/', {
            controller: 'LoginCtrl',
            templateUrl: 'app/login/login.html',
            title: 'Login'
        }).when('/dashboard', {
            controller: 'DashboardCtrl',
            templateUrl: 'app/dashboard/dashboard.html',
            title: 'Dashboard'
        });
    ;
    $httpProvider.interceptors.push('authInterceptor');
}).factory('authInterceptor', function($rootScope, $q, $cookieStore, $location){
    //Manages responses based on the current session configuration
    return {
        request(config) {
            config.headers = config.headers || {};
            if ($cookieStore.get('jwt')){
                config.headers.Authorization = $cookieStore.get('jwt');
                $rootScope.jwt = $cookieStore.get('jwt');
            }
            return config;
        },
        responseError(response) {
            if (response.status == 401) {
                $location.path('/');
                $cookieStore.remove('token');
            }
            return $q.reject(response);
        }
    };
});
