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    'app.navbar',
14    'app.main',
15    'app.signup',
16    'app.login',
17    'app.id'
18]).
19config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
20        $locationProvider.hashPrefix('!');
21
22        if ((localStorage.getItem('darkID_token'))) {
23            console.log(window.location.hash);
24            if ((window.location.hash === '#!/login') || (window.location.hash === '#!/signup')) {
25                window.location = '#!/main';
26            }
27
28            $routeProvider.otherwise({
29                redirectTo: '/main'
30            });
31        } else {
32            if ((window.location !== '#!/login') || (window.location !== '#!/signup')) {
33                console.log('app, user no logged');
34
35                localStorage.removeItem('darkID_token');
36                localStorage.removeItem('darkID_userdata');
37                window.location = '#!/login';
38                $routeProvider.otherwise({
39                    redirectTo: '/login'
40                });
41            }
42        }
43    }])
44    .config(function(toastrConfig) {
45        angular.extend(toastrConfig, {
46            autoDismiss: false,
47            containerId: 'toast-container',
48            maxOpened: 0,
49            newestOnTop: true,
50            positionClass: 'toast-bottom-right',
51            preventDuplicates: false,
52            preventOpenDuplicates: false,
53            target: 'body'
54        });
55    })
56    .factory('httpInterceptor', function httpInterceptor() {
57        return {
58            request: function(config) {
59                return config;
60            },
61
62            requestError: function(config) {
63                return config;
64            },
65
66            response: function(res) {
67                return res;
68            },
69
70            responseError: function(res) {
71                return res;
72            }
73        };
74    })
75    .factory('api', function($http) {
76        return {
77            init: function() {
78                /*$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('block_webapp_token');
79                $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('block_webapp_token');*/
80            }
81        };
82    })
83    .run(function(api) {
84        api.init();
85    });