arnaucube
arnaucube/darkID-prototypePublic Self-hosted repository
darkID-prototype/clientApp/GUI/app.js
clientApp/GUI/app.jsRaw
 1'use strict';
 2
 3
 4var clientapi = "http://127.0.0.1:4100/";
 5
 6// Declare app level module which depends on views, and components
 7angular.module('app', [
 8    'ngRoute',
 9    'ngMessages',
10    'angularBootstrapMaterial',
11    'ui.bootstrap',
12    'toastr',
13    'chart.js',
14    'app.navbar',
15    'app.main',
16    'app.signup',
17    'app.login',
18    'app.id',
19    'app.stats'
20]).
21config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
22        $locationProvider.hashPrefix('!');
23
24        if ((localStorage.getItem('darkID_token'))) {
25            console.log(window.location.hash);
26            if ((window.location.hash === '#!/login') || (window.location.hash === '#!/signup')) {
27                window.location = '#!/main';
28            }
29
30            $routeProvider.otherwise({
31                redirectTo: '/main'
32            });
33        } else {
34            if ((window.location !== '#!/login') || (window.location !== '#!/signup')) {
35                console.log('app, user no logged');
36
37                localStorage.removeItem('darkID_token');
38                localStorage.removeItem('darkID_userdata');
39                window.location = '#!/login';
40                $routeProvider.otherwise({
41                    redirectTo: '/login'
42                });
43            }
44        }
45    }])
46    .config(function(toastrConfig) {
47        angular.extend(toastrConfig, {
48            autoDismiss: false,
49            containerId: 'toast-container',
50            maxOpened: 0,
51            newestOnTop: true,
52            positionClass: 'toast-bottom-right',
53            preventDuplicates: false,
54            preventOpenDuplicates: false,
55            target: 'body'
56        });
57    })
58    .factory('httpInterceptor', function httpInterceptor() {
59        return {
60            request: function(config) {
61                return config;
62            },
63
64            requestError: function(config) {
65                return config;
66            },
67
68            response: function(res) {
69                return res;
70            },
71
72            responseError: function(res) {
73                return res;
74            }
75        };
76    })
77    .factory('api', function($http) {
78        return {
79            init: function() {
80                /*$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('block_webapp_token');
81                $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('block_webapp_token');*/
82            }
83        };
84    })
85    .run(function(api) {
86        api.init();
87    });